bugfixes in auditor-sync logic

This commit is contained in:
Christian Grothoff 2021-01-12 23:00:57 +01:00
parent 8f887a215e
commit 52513dcc26
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
3 changed files with 101 additions and 36 deletions

View File

@ -84,10 +84,27 @@ static struct Table
}; };
/**
* Closure for #do_insert.
*/
struct InsertContext
{
/**
* Database session to use.
*/
struct TALER_EXCHANGEDB_Session *ds;
/**
* Set to error if insertion created an error.
*/
enum GNUNET_DB_QueryStatus qs;
};
/** /**
* Function called on data to replicate in the auditor's database. * Function called on data to replicate in the auditor's database.
* *
* @param cls closure * @param cls closure, a `struct InsertContext`
* @param td record from an exchange table * @param td record from an exchange table
* @return #GNUNET_OK to continue to iterate, * @return #GNUNET_OK to continue to iterate,
* #GNUNET_SYSERR to fail with an error * #GNUNET_SYSERR to fail with an error
@ -96,7 +113,21 @@ static int
do_insert (void *cls, do_insert (void *cls,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
// FIXME ... struct InsertContext *ctx = cls;
enum GNUNET_DB_QueryStatus qs;
if (0 >= ctx->qs)
return GNUNET_SYSERR;
qs = dst->insert_records_by_table (dst->cls,
ctx->ds,
td);
if (0 >= qs)
{
ctx->qs = qs;
return GNUNET_SYSERR;
}
actual_size++;
return GNUNET_OK;
} }
@ -109,7 +140,12 @@ static int
transact (struct TALER_EXCHANGEDB_Session *ss, transact (struct TALER_EXCHANGEDB_Session *ss,
struct TALER_EXCHANGEDB_Session *ds) struct TALER_EXCHANGEDB_Session *ds)
{ {
if (GNUNET_OK != struct InsertContext ctx = {
.ds = ds,
.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
};
if (0 >
src->start (src->cls, src->start (src->cls,
ss, ss,
"lookup src serials")) "lookup src serials"))
@ -119,7 +155,7 @@ transact (struct TALER_EXCHANGEDB_Session *ss,
ss, ss,
tables[i].rt, tables[i].rt,
&tables[i].end_serial); &tables[i].end_serial);
if (GNUNET_OK != if (0 >
src->commit (src->cls, src->commit (src->cls,
ss)) ss))
return GNUNET_SYSERR; return GNUNET_SYSERR;
@ -133,7 +169,7 @@ transact (struct TALER_EXCHANGEDB_Session *ss,
ds, ds,
tables[i].rt, tables[i].rt,
&tables[i].start_serial); &tables[i].start_serial);
if (GNUNET_OK != if (0 >
dst->commit (dst->cls, dst->commit (dst->cls,
ds)) ds))
return GNUNET_SYSERR; return GNUNET_SYSERR;
@ -160,7 +196,9 @@ transact (struct TALER_EXCHANGEDB_Session *ss,
tables[i].rt, tables[i].rt,
tables[i].start_serial, tables[i].start_serial,
&do_insert, &do_insert,
ds); &ctx);
if (ctx.qs < 0)
qs = ctx.qs;
if (GNUNET_DB_STATUS_HARD_ERROR == qs) if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{ {
global_ret = 3; global_ret = 3;
@ -174,15 +212,22 @@ transact (struct TALER_EXCHANGEDB_Session *ss,
global_ret = 4; global_ret = 4;
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (0 == ctx.qs)
return GNUNET_SYSERR; /* insertion failed, maybe record existed? try again */
src->rollback (src->cls,
ss);
qs = dst->commit (dst->cls,
ds);
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
continue;
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{
global_ret = 5;
return GNUNET_SYSERR;
}
} }
} }
/* we do not care about conflicting UPDATEs to src table, so safe to just rollback */ /* we do not care about conflicting UPDATEs to src table, so safe to just rollback */
src->rollback (src->cls,
ss);
if (GNUNET_OK !=
dst->commit (dst->cls,
ds))
return GNUNET_SYSERR;
printf ("\n"); printf ("\n");
return GNUNET_OK; return GNUNET_OK;
} }

View File

@ -38,12 +38,13 @@ irbt_cb_table_denominations (struct PostgresClosure *pg,
const struct TALER_EXCHANGEDB_TableData *td) const struct TALER_EXCHANGEDB_TableData *td)
{ {
struct GNUNET_HashCode denom_hash; struct GNUNET_HashCode denom_hash;
static struct TALER_MasterPublicKeyP master_pub;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_uint64 (&td->serial),
GNUNET_PQ_query_param_auto_from_type (&denom_hash), GNUNET_PQ_query_param_auto_from_type (&denom_hash),
GNUNET_PQ_query_param_rsa_public_key ( GNUNET_PQ_query_param_rsa_public_key (
td->details.denominations.denom_pub.rsa_public_key), td->details.denominations.denom_pub.rsa_public_key),
// GNUNET_PQ_query_param_auto_from_type (&master_pub), // FIXME: !? GNUNET_PQ_query_param_auto_from_type (&master_pub), // FIXME: !?
GNUNET_PQ_query_param_auto_from_type ( GNUNET_PQ_query_param_auto_from_type (
&td->details.denominations.master_sig), &td->details.denominations.master_sig),
TALER_PQ_query_param_absolute_time ( TALER_PQ_query_param_absolute_time (

View File

@ -2056,8 +2056,9 @@ postgres_get_session (void *cls)
",master_sig" ",master_sig"
",denominations_serial" ",denominations_serial"
" FROM denomination_revocations" " FROM denomination_revocations"
" WHERE denom_revocations_serial_id > $1"
" ORDER BY denom_revocations_serial_id ASC;", " ORDER BY denom_revocations_serial_id ASC;",
0), 1),
GNUNET_PQ_make_prepare ("select_above_serial_by_table_reserves", GNUNET_PQ_make_prepare ("select_above_serial_by_table_reserves",
"SELECT" "SELECT"
" reserve_uuid AS serial" " reserve_uuid AS serial"
@ -2068,8 +2069,9 @@ postgres_get_session (void *cls)
",expiration_date" ",expiration_date"
",gc_date" ",gc_date"
" FROM reserves" " FROM reserves"
" WHERE reserve_uuid > $1"
" ORDER BY reserve_uuid ASC;", " ORDER BY reserve_uuid ASC;",
0), 1),
GNUNET_PQ_make_prepare ("select_above_serial_by_table_reserves_in", GNUNET_PQ_make_prepare ("select_above_serial_by_table_reserves_in",
"SELECT" "SELECT"
" reserve_in_serial_id AS serial" " reserve_in_serial_id AS serial"
@ -2079,9 +2081,11 @@ postgres_get_session (void *cls)
",sender_account_details" ",sender_account_details"
",exchange_account_section" ",exchange_account_section"
",execution_date" ",execution_date"
",reserve_uuid"
" FROM reserves_in" " FROM reserves_in"
" WHERE reserve_in_serial_id > $1"
" ORDER BY reserve_in_serial_id ASC;", " ORDER BY reserve_in_serial_id ASC;",
0), 1),
GNUNET_PQ_make_prepare ("select_above_serial_by_table_reserves_close", GNUNET_PQ_make_prepare ("select_above_serial_by_table_reserves_close",
"SELECT" "SELECT"
" close_uuid AS serial" " close_uuid AS serial"
@ -2094,8 +2098,9 @@ postgres_get_session (void *cls)
",closing_fee_frac" ",closing_fee_frac"
",reserve_uuid" ",reserve_uuid"
" FROM reserves_close" " FROM reserves_close"
" WHERE close_uuid > $1"
" ORDER BY close_uuid ASC;", " ORDER BY close_uuid ASC;",
0), 1),
GNUNET_PQ_make_prepare ("select_above_serial_by_table_reserves_out", GNUNET_PQ_make_prepare ("select_above_serial_by_table_reserves_out",
"SELECT" "SELECT"
" reserve_out_serial_id AS serial" " reserve_out_serial_id AS serial"
@ -2108,8 +2113,9 @@ postgres_get_session (void *cls)
",reserve_uuid" ",reserve_uuid"
",denominations_serial" ",denominations_serial"
" FROM reserves_out" " FROM reserves_out"
" WHERE reserve_out_serial_id > $1"
" ORDER BY reserve_out_serial_id ASC;", " ORDER BY reserve_out_serial_id ASC;",
0), 1),
GNUNET_PQ_make_prepare ("select_above_serial_by_table_auditors", GNUNET_PQ_make_prepare ("select_above_serial_by_table_auditors",
"SELECT" "SELECT"
" auditor_uuid AS serial" " auditor_uuid AS serial"
@ -2119,16 +2125,18 @@ postgres_get_session (void *cls)
",is_active" ",is_active"
",last_change" ",last_change"
" FROM auditors" " FROM auditors"
" WHERE auditor_uuid > $1"
" ORDER BY auditor_uuid ASC;", " ORDER BY auditor_uuid ASC;",
0), 1),
GNUNET_PQ_make_prepare ("select_above_serial_by_table_auditor_denom_sigs", GNUNET_PQ_make_prepare ("select_above_serial_by_table_auditor_denom_sigs",
"SELECT" "SELECT"
" auditor_denom_serial AS serial" " auditor_denom_serial AS serial"
",auditor_uuid" ",auditor_uuid"
",denominations_serial" ",denominations_serial"
" FROM auditor_denom_sigs" " FROM auditor_denom_sigs"
" WHERE auditor_denom_serial > $1"
" ORDER BY auditor_denom_serial ASC;", " ORDER BY auditor_denom_serial ASC;",
0), 1),
GNUNET_PQ_make_prepare ("select_above_serial_by_table_exchange_sign_keys", GNUNET_PQ_make_prepare ("select_above_serial_by_table_exchange_sign_keys",
"SELECT" "SELECT"
" esk_serial AS serial" " esk_serial AS serial"
@ -2138,8 +2146,9 @@ postgres_get_session (void *cls)
",expire_sign" ",expire_sign"
",expire_legal" ",expire_legal"
" FROM exchange_sign_keys" " FROM exchange_sign_keys"
" WHERE esk_serial > $1"
" ORDER BY esk_serial ASC;", " ORDER BY esk_serial ASC;",
0), 1),
GNUNET_PQ_make_prepare ( GNUNET_PQ_make_prepare (
"select_above_serial_by_table_signkey_revocations", "select_above_serial_by_table_signkey_revocations",
"SELECT" "SELECT"
@ -2147,8 +2156,9 @@ postgres_get_session (void *cls)
",esk_serial" ",esk_serial"
",master_sig" ",master_sig"
" FROM signkey_revocations" " FROM signkey_revocations"
" WHERE signkey_revocations_serial_id > $1"
" ORDER BY signkey_revocations_serial_id ASC;", " ORDER BY signkey_revocations_serial_id ASC;",
0), 1),
GNUNET_PQ_make_prepare ("select_above_serial_by_table_known_coins", GNUNET_PQ_make_prepare ("select_above_serial_by_table_known_coins",
"SELECT" "SELECT"
" known_coin_id AS serial" " known_coin_id AS serial"
@ -2156,8 +2166,9 @@ postgres_get_session (void *cls)
",denom_sig" ",denom_sig"
",denominations_serial" ",denominations_serial"
" FROM known_coins" " FROM known_coins"
" WHERE known_coin_id > $1"
" ORDER BY known_coin_id ASC;", " ORDER BY known_coin_id ASC;",
0), 1),
GNUNET_PQ_make_prepare ( GNUNET_PQ_make_prepare (
"select_above_serial_by_table_refresh_commitments", "select_above_serial_by_table_refresh_commitments",
"SELECT" "SELECT"
@ -2169,8 +2180,9 @@ postgres_get_session (void *cls)
",amount_with_fee_frac" ",amount_with_fee_frac"
",noreveal_index" ",noreveal_index"
" FROM refresh_commitments" " FROM refresh_commitments"
" WHERE melt_serial_id > $1"
" ORDER BY melt_serial_id ASC;", " ORDER BY melt_serial_id ASC;",
0), 1),
GNUNET_PQ_make_prepare ( GNUNET_PQ_make_prepare (
"select_above_serial_by_table_refresh_revealed_coins", "select_above_serial_by_table_refresh_revealed_coins",
"SELECT" "SELECT"
@ -2185,8 +2197,9 @@ postgres_get_session (void *cls)
",denominations_serial" ",denominations_serial"
" FROM refresh_revealed_coins" " FROM refresh_revealed_coins"
" JOIN refresh_commitments USING (melt_serial_id)" " JOIN refresh_commitments USING (melt_serial_id)"
" WHERE rrc_serial > $1"
" ORDER BY rrc_serial ASC;", " ORDER BY rrc_serial ASC;",
0), 1),
GNUNET_PQ_make_prepare ( GNUNET_PQ_make_prepare (
"select_above_serial_by_table_refresh_transfer_keys", "select_above_serial_by_table_refresh_transfer_keys",
"SELECT" "SELECT"
@ -2196,8 +2209,9 @@ postgres_get_session (void *cls)
",transfer_privs" ",transfer_privs"
" FROM refresh_transfer_keys" " FROM refresh_transfer_keys"
" JOIN refresh_commitments USING (melt_serial_id)" " JOIN refresh_commitments USING (melt_serial_id)"
" WHERE rtc_serial > $1"
" ORDER BY rtc_serial ASC;", " ORDER BY rtc_serial ASC;",
0), 1),
GNUNET_PQ_make_prepare ("select_above_serial_by_table_deposits", GNUNET_PQ_make_prepare ("select_above_serial_by_table_deposits",
"SELECT" "SELECT"
" deposit_serial_id AS serial" " deposit_serial_id AS serial"
@ -2216,8 +2230,9 @@ postgres_get_session (void *cls)
",done" ",done"
",known_coin_id" ",known_coin_id"
" FROM deposits" " FROM deposits"
" WHERE deposit_serial_id > $1"
" ORDER BY deposit_serial_id ASC;", " ORDER BY deposit_serial_id ASC;",
0), 1),
GNUNET_PQ_make_prepare ("select_above_serial_by_table_refunds", GNUNET_PQ_make_prepare ("select_above_serial_by_table_refunds",
"SELECT" "SELECT"
" refund_serial_id AS serial" " refund_serial_id AS serial"
@ -2230,8 +2245,9 @@ postgres_get_session (void *cls)
",known_coin_id" ",known_coin_id"
" FROM refunds" " FROM refunds"
" JOIN deposits USING (deposit_serial_id)" " JOIN deposits USING (deposit_serial_id)"
" WHERE refund_serial_id > $1"
" ORDER BY refund_serial_id ASC;", " ORDER BY refund_serial_id ASC;",
0), 1),
GNUNET_PQ_make_prepare ("select_above_serial_by_table_wire_out", GNUNET_PQ_make_prepare ("select_above_serial_by_table_wire_out",
"SELECT" "SELECT"
" wireout_uuid AS serial" " wireout_uuid AS serial"
@ -2242,8 +2258,9 @@ postgres_get_session (void *cls)
",amount_val" ",amount_val"
",amount_frac" ",amount_frac"
" FROM wire_out" " FROM wire_out"
" WHERE wireout_uuid > $1"
" ORDER BY wireout_uuid ASC;", " ORDER BY wireout_uuid ASC;",
0), 1),
GNUNET_PQ_make_prepare ( GNUNET_PQ_make_prepare (
"select_above_serial_by_table_aggregation_tracking", "select_above_serial_by_table_aggregation_tracking",
"SELECT" "SELECT"
@ -2251,8 +2268,9 @@ postgres_get_session (void *cls)
",deposit_serial_id" ",deposit_serial_id"
",wtid_raw" ",wtid_raw"
" FROM aggregation_tracking" " FROM aggregation_tracking"
" WHERE aggregation_serial_id > $1"
" ORDER BY aggregation_serial_id ASC;", " ORDER BY aggregation_serial_id ASC;",
0), 1),
GNUNET_PQ_make_prepare ("select_above_serial_by_table_wire_fee", GNUNET_PQ_make_prepare ("select_above_serial_by_table_wire_fee",
"SELECT" "SELECT"
" wire_fee_serial AS serial" " wire_fee_serial AS serial"
@ -2265,8 +2283,9 @@ postgres_get_session (void *cls)
",closing_fee_frac" ",closing_fee_frac"
",master_sig" ",master_sig"
" FROM wire_fee" " FROM wire_fee"
" WHERE wire_fee_serial > $1"
" ORDER BY wire_fee_serial ASC;", " ORDER BY wire_fee_serial ASC;",
0), 1),
GNUNET_PQ_make_prepare ("select_above_serial_by_table_recoup", GNUNET_PQ_make_prepare ("select_above_serial_by_table_recoup",
"SELECT" "SELECT"
" recoup_uuid AS serial" " recoup_uuid AS serial"
@ -2278,8 +2297,9 @@ postgres_get_session (void *cls)
",known_coin_id" ",known_coin_id"
",reserve_out_serial_id" ",reserve_out_serial_id"
" FROM recoup" " FROM recoup"
" WHERE recoup_uuid > $1"
" ORDER BY recoup_uuid ASC;", " ORDER BY recoup_uuid ASC;",
0), 1),
GNUNET_PQ_make_prepare ("select_above_serial_by_table_recoup_refresh", GNUNET_PQ_make_prepare ("select_above_serial_by_table_recoup_refresh",
"SELECT" "SELECT"
" recoup_refresh_uuid AS serial" " recoup_refresh_uuid AS serial"
@ -2291,8 +2311,9 @@ postgres_get_session (void *cls)
",known_coin_id" ",known_coin_id"
",rrc_serial" ",rrc_serial"
" FROM recoup_refresh" " FROM recoup_refresh"
" WHERE recoup_refresh_uuid > $1"
" ORDER BY recoup_refresh_uuid ASC;", " ORDER BY recoup_refresh_uuid ASC;",
0), 1),
/* For postgres_insert_records_by_table */ /* For postgres_insert_records_by_table */
GNUNET_PQ_make_prepare ("insert_into_table_denominations", GNUNET_PQ_make_prepare ("insert_into_table_denominations",
"INSERT INTO denominations" "INSERT INTO denominations"
@ -2618,14 +2639,12 @@ postgres_start (void *cls,
GNUNET_PQ_EXECUTE_STATEMENT_END GNUNET_PQ_EXECUTE_STATEMENT_END
}; };
(void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting transaction named: %s\n", "Starting transaction named: %s\n",
name); name);
postgres_preflight (cls, postgres_preflight (cls,
session); session);
(void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting transaction on %p\n", "Starting transaction on %p\n",
session->conn); session->conn);