more work on #5010

This commit is contained in:
Christian Grothoff 2017-05-25 19:38:34 +02:00
parent 6029ed7db1
commit a5873d0222
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
2 changed files with 60 additions and 119 deletions

View File

@ -35,6 +35,11 @@
*/ */
#define PQ_DIAG_SQLSTATE_DEADLOCK "40P01" #define PQ_DIAG_SQLSTATE_DEADLOCK "40P01"
/**
* Error code returned by Postgres for uniqueness violation.
*/
#define PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION "23505"
/** /**
* Error code returned by Postgres on serialization failure. * Error code returned by Postgres on serialization failure.
*/ */
@ -3662,6 +3667,7 @@ postgres_create_refresh_session (void *cls,
* @param num_newcoins number of coins to generate, size of the @a denom_pubs array * @param num_newcoins number of coins to generate, size of the @a denom_pubs array
* @param denom_pubs array denominations of the coins to create * @param denom_pubs array denominations of the coins to create
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
* #GNUNET_NO on transient error
* #GNUNET_SYSERR on internal error * #GNUNET_SYSERR on internal error
*/ */
static int static int
@ -3671,12 +3677,9 @@ postgres_insert_refresh_order (void *cls,
uint16_t num_newcoins, uint16_t num_newcoins,
const struct TALER_DenominationPublicKey *denom_pubs) const struct TALER_DenominationPublicKey *denom_pubs)
{ {
unsigned int i; for (unsigned int i=0;i<(unsigned int) num_newcoins;i++)
for (i=0;i<(unsigned int) num_newcoins;i++)
{ {
uint16_t newcoin_off = (uint16_t) i; uint16_t newcoin_off = (uint16_t) i;
PGresult *result;
{ {
struct GNUNET_HashCode denom_pub_hash; struct GNUNET_HashCode denom_pub_hash;
@ -3686,25 +3689,16 @@ postgres_insert_refresh_order (void *cls,
GNUNET_PQ_query_param_auto_from_type (&denom_pub_hash), GNUNET_PQ_query_param_auto_from_type (&denom_pub_hash),
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
int ret;
GNUNET_CRYPTO_rsa_public_key_hash (denom_pubs[i].rsa_public_key, GNUNET_CRYPTO_rsa_public_key_hash (denom_pubs[i].rsa_public_key,
&denom_pub_hash); &denom_pub_hash);
result = GNUNET_PQ_exec_prepared (session->conn, ret = execute_prepared_non_select (session,
"insert_refresh_order", "insert_refresh_order",
params); params);
if (GNUNET_OK != ret)
return ret;
} }
if (PGRES_COMMAND_OK != PQresultStatus (result))
{
BREAK_DB_ERR (result, session->conn);
PQclear (result);
return GNUNET_SYSERR;
}
if (0 != strcmp ("1", PQcmdTuples (result)))
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
PQclear (result);
} }
return GNUNET_OK; return GNUNET_OK;
} }
@ -3814,6 +3808,7 @@ postgres_get_refresh_order (void *cls,
* @param num_newcoins coin index size of the @a commit_coins array * @param num_newcoins coin index size of the @a commit_coins array
* @param commit_coins array of coin commitments to store * @param commit_coins array of coin commitments to store
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
* #GNUNET_NO on transient error
* #GNUNET_SYSERR on error * #GNUNET_SYSERR on error
*/ */
static int static int
@ -3823,38 +3818,22 @@ postgres_insert_refresh_commit_coins (void *cls,
uint16_t num_newcoins, uint16_t num_newcoins,
const struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins) const struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins)
{ {
PGresult *result; for (uint16_t coin_off=0;coin_off<num_newcoins;coin_off++)
unsigned int i;
uint16_t coin_off;
for (i=0;i<(unsigned int) num_newcoins;i++)
{
coin_off = (uint16_t) i;
{ {
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (session_hash), GNUNET_PQ_query_param_auto_from_type (session_hash),
GNUNET_PQ_query_param_uint16 (&coin_off), GNUNET_PQ_query_param_uint16 (&coin_off),
GNUNET_PQ_query_param_fixed_size (commit_coins[i].coin_ev, GNUNET_PQ_query_param_fixed_size (commit_coins[coin_off].coin_ev,
commit_coins[i].coin_ev_size), commit_coins[coin_off].coin_ev_size),
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
result = GNUNET_PQ_exec_prepared (session->conn, int ret;
ret = execute_prepared_non_select (session,
"insert_refresh_commit_coin", "insert_refresh_commit_coin",
params); params);
} if (GNUNET_OK != ret)
if (PGRES_COMMAND_OK != PQresultStatus (result)) return ret;
{
BREAK_DB_ERR (result, session->conn);
PQclear (result);
return GNUNET_SYSERR;
}
if (0 != strcmp ("1", PQcmdTuples (result)))
{
GNUNET_break (0);
PQclear (result);
return GNUNET_SYSERR;
}
PQclear (result);
} }
return GNUNET_OK; return GNUNET_OK;
} }
@ -5154,7 +5133,8 @@ postgres_get_expired_reserves (void *cls,
* @param wtid wire transfer details * @param wtid wire transfer details
* @param amount_with_fee amount we charged to the reserve * @param amount_with_fee amount we charged to the reserve
* @param closing_fee how high is the closing fee * @param closing_fee how high is the closing fee
* @return #GNUNET_OK on success, #GNUNET_NO if the record exists, * @return #GNUNET_OK on success,
* #GNUNET_NO if the record exists or on transient errors
* #GNUNET_SYSERR on failure * #GNUNET_SYSERR on failure
*/ */
static int static int
@ -5177,35 +5157,24 @@ postgres_insert_reserve_closed (void *cls,
TALER_PQ_query_param_amount (closing_fee), TALER_PQ_query_param_amount (closing_fee),
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
PGresult *result;
int ret; int ret;
result = GNUNET_PQ_exec_prepared (session->conn, ret = execute_prepared_non_select (session,
"reserves_close_insert", "reserves_close_insert",
params); params);
if (PGRES_COMMAND_OK != PQresultStatus (result)) if (GNUNET_OK != ret)
{ return ret;
BREAK_DB_ERR (result, session->conn);
PQclear (result);
return GNUNET_SYSERR;
}
if (0 != strcmp ("1", PQcmdTuples (result)))
{
GNUNET_break (0);
PQclear (result);
return GNUNET_SYSERR;
}
PQclear (result);
/* update reserve balance */ /* update reserve balance */
reserve.pub = *reserve_pub; reserve.pub = *reserve_pub;
if (GNUNET_OK != postgres_reserve_get (cls, if (GNUNET_OK !=
(ret = postgres_reserve_get (cls,
session, session,
&reserve)) &reserve)))
{ {
/* Should have been checked before we got here... */ /* Existence should have been checked before we got here... */
GNUNET_break (0); GNUNET_break (GNUNET_NO == ret);
return GNUNET_SYSERR; return ret;
} }
ret = TALER_amount_subtract (&reserve.balance, ret = TALER_amount_subtract (&reserve.balance,
&reserve.balance, &reserve.balance,
@ -5250,24 +5219,15 @@ postgres_wire_prepare_data_insert (void *cls,
const char *buf, const char *buf,
size_t buf_size) size_t buf_size)
{ {
PGresult *result;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_string (type), GNUNET_PQ_query_param_string (type),
GNUNET_PQ_query_param_fixed_size (buf, buf_size), GNUNET_PQ_query_param_fixed_size (buf, buf_size),
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
result = GNUNET_PQ_exec_prepared (session->conn, return execute_prepared_non_select (session,
"wire_prepare_data_insert", "wire_prepare_data_insert",
params); params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
{
BREAK_DB_ERR (result, session->conn);
PQclear (result);
return GNUNET_SYSERR;
}
PQclear (result);
return GNUNET_OK;
} }
@ -5288,20 +5248,10 @@ postgres_wire_prepare_data_mark_finished (void *cls,
GNUNET_PQ_query_param_uint64 (&rowid), GNUNET_PQ_query_param_uint64 (&rowid),
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
PGresult *result;
result = GNUNET_PQ_exec_prepared (session->conn, return execute_prepared_non_select (session,
"wire_prepare_data_mark_done", "wire_prepare_data_mark_done",
params); params);
if (PGRES_COMMAND_OK !=
PQresultStatus (result))
{
BREAK_DB_ERR (result, session->conn);
PQclear (result);
return GNUNET_SYSERR;
}
PQclear (result);
return GNUNET_OK;
} }
@ -5453,7 +5403,6 @@ postgres_store_wire_transfer_out (void *cls,
const json_t *wire_account, const json_t *wire_account,
const struct TALER_Amount *amount) const struct TALER_Amount *amount)
{ {
PGresult *result;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_absolute_time (&date), GNUNET_PQ_query_param_absolute_time (&date),
GNUNET_PQ_query_param_auto_from_type (wtid), GNUNET_PQ_query_param_auto_from_type (wtid),
@ -5462,17 +5411,9 @@ postgres_store_wire_transfer_out (void *cls,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
result = GNUNET_PQ_exec_prepared (session->conn, return execute_prepared_non_select (session,
"insert_wire_out", "insert_wire_out",
params); params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
{
BREAK_DB_ERR (result, session->conn);
PQclear (result);
return GNUNET_SYSERR;
}
PQclear (result);
return GNUNET_OK;
} }
@ -6397,7 +6338,6 @@ postgres_insert_payback_request (void *cls,
struct GNUNET_TIME_Absolute timestamp) struct GNUNET_TIME_Absolute timestamp)
{ {
struct PostgresClosure *pg = cls; struct PostgresClosure *pg = cls;
PGresult *result;
struct GNUNET_TIME_Absolute expiry; struct GNUNET_TIME_Absolute expiry;
struct TALER_EXCHANGEDB_Reserve reserve; struct TALER_EXCHANGEDB_Reserve reserve;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
@ -6435,16 +6375,14 @@ postgres_insert_payback_request (void *cls,
} }
/* now store actual payback information */ /* now store actual payback information */
result = GNUNET_PQ_exec_prepared (session->conn, if (GNUNET_OK !=
(ret = execute_prepared_non_select (session,
"payback_insert", "payback_insert",
params); params)))
if (PGRES_COMMAND_OK != PQresultStatus (result))
{ {
BREAK_DB_ERR (result, session->conn); GNUNET_break (GNUNET_NO == ret);
PQclear (result); return ret;
return GNUNET_SYSERR;
} }
PQclear (result);
/* Update reserve balance */ /* Update reserve balance */
reserve.pub = *reserve_pub; reserve.pub = *reserve_pub;
@ -6581,8 +6519,9 @@ postgres_insert_denomination_revocation (void *cls,
efield = PQresultErrorField (result, efield = PQresultErrorField (result,
PG_DIAG_SQLSTATE); PG_DIAG_SQLSTATE);
/* FIXME: what about serialization errors? */
if ( (PGRES_FATAL_ERROR == PQresultStatus(result)) && if ( (PGRES_FATAL_ERROR == PQresultStatus(result)) &&
(NULL != strstr ("23505", /* unique violation */ (NULL != strstr (PQ_DIAG_SQLSTATE_UNIQUE_VIOLATION,
efield)) ) efield)) )
{ {
/* This means we had the same reserve/justification/details /* This means we had the same reserve/justification/details

View File

@ -1488,6 +1488,7 @@ struct TALER_EXCHANGEDB_Plugin
* @param num_newcoins number of coins to generate, size of the @a denom_pubs array * @param num_newcoins number of coins to generate, size of the @a denom_pubs array
* @param denom_pubs array denominations of the coins to create * @param denom_pubs array denominations of the coins to create
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
* #GNUNET_NO on transient error
* #GNUNET_SYSERR on internal error * #GNUNET_SYSERR on internal error
*/ */
int int
@ -1528,6 +1529,7 @@ struct TALER_EXCHANGEDB_Plugin
* @param num_newcoins coin index size of the @a commit_coins array * @param num_newcoins coin index size of the @a commit_coins array
* @param commit_coin array of coin commitments to store * @param commit_coin array of coin commitments to store
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
* #GNUNET_NO on transient error
* #GNUNET_SYSERR on error * #GNUNET_SYSERR on error
*/ */
int int