exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 447447e584b50bbfabb9b6a43d4c083aa653828e
parent 9bbd64483760555ad02af2aca7c435c21fac39f5
Author: Özgür Kesim <oec@codeblau.de>
Date:   Sun, 25 Oct 2026 16:56:31 +0100

[exchangedb] replicate refresh.transfer_pubs and refresh.revealed

Diffstat:
Msrc/exchangedb/insert_records_by_table.c | 12+++++++++++-
Msrc/exchangedb/iterate_records_by_table.c | 25+++++++++++++++++++++++++
Msrc/exchangedb/test_refresh.c | 189+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/include/exchange-database/iterate_records_by_table.h | 3+++
4 files changed, 228 insertions(+), 1 deletion(-)

diff --git a/src/exchangedb/insert_records_by_table.c b/src/exchangedb/insert_records_by_table.c @@ -882,6 +882,13 @@ irbt_cb_table_refresh (struct TALER_EXCHANGEDB_PostgresContext *pg, td->details.refresh.num_coins, td->details.refresh.denom_sigs, pg->conn), + (NULL == td->details.refresh.transfer_pubs) + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_array_auto_from_type ( + td->details.refresh.num_coins, + td->details.refresh.transfer_pubs, + pg->conn), + GNUNET_PQ_query_param_bool (td->details.refresh.revealed), GNUNET_PQ_query_param_uint32 ( &td->details.refresh.rc_version), GNUNET_PQ_query_param_end @@ -906,9 +913,12 @@ irbt_cb_table_refresh (struct TALER_EXCHANGEDB_PostgresContext *pg, ",cs_r_choices" ",denom_serials" ",denom_sigs" + ",transfer_pubs" + ",revealed" ",rc_version" ") VALUES " - "($1, $2, $3, $4, $5, $6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);"); + "($1, $2, $3, $4, $5, $6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17," + "$18);"); qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_records_by_table_into_table_refresh", params); diff --git a/src/exchangedb/iterate_records_by_table.c b/src/exchangedb/iterate_records_by_table.c @@ -914,7 +914,9 @@ lrbt_cb_table_refresh (void *cls, { bool no_cs_r_values; bool no_cs_r_choices; + bool no_transfer_pubs; size_t num_denom_sigs; + size_t num_transfer_pubs; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ( "serial", @@ -973,12 +975,24 @@ lrbt_cb_table_refresh (void *cls, "denom_sigs", &num_denom_sigs, &td.details.refresh.denom_sigs), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_array_fixed_size ( + pg->conn, + "transfer_pubs", + sizeof (*td.details.refresh.transfer_pubs), + &num_transfer_pubs, + (void **) &td.details.refresh.transfer_pubs), + &no_transfer_pubs), + GNUNET_PQ_result_spec_bool ( + "revealed", + &td.details.refresh.revealed), GNUNET_PQ_result_spec_uint32 ( "rc_version", &td.details.refresh.rc_version), GNUNET_PQ_result_spec_end }; + td.details.refresh.transfer_pubs = NULL; if (GNUNET_OK != GNUNET_PQ_extract_result (result, rs, @@ -989,6 +1003,15 @@ lrbt_cb_table_refresh (void *cls, GNUNET_PQ_cleanup_result (rs); return; } + if ( (num_denom_sigs != td.details.refresh.num_coins) || + ( (! no_transfer_pubs) && + (num_transfer_pubs != td.details.refresh.num_coins) ) ) + { + GNUNET_break (0); + ctx->error = true; + GNUNET_PQ_cleanup_result (rs); + return; + } ctx->cb (ctx->cb_cls, &td); GNUNET_PQ_cleanup_result (rs); @@ -3220,6 +3243,8 @@ TALER_EXCHANGEDB_iterate_records_by_table ( ",cs_r_choices" ",denom_serials" ",denom_sigs" + ",transfer_pubs" + ",revealed" ",rc_version" " FROM refresh" " WHERE refresh_id > $1" diff --git a/src/exchangedb/test_refresh.c b/src/exchangedb/test_refresh.c @@ -33,6 +33,8 @@ #include "exchange-database/get_known_coin.h" #include "exchange-database/get_refresh.h" #include "exchange-database/iterate_refreshes_above_serial_id.h" +#include "exchange-database/insert_records_by_table.h" +#include "exchange-database/iterate_records_by_table.h" #include "exchange-database/update_to_refresh_revealed.h" @@ -802,6 +804,191 @@ check_rc_version (struct TALER_EXCHANGEDB_PostgresContext *pg) /** + * Closure for #replication_cb(). + */ +struct ReplicationContext +{ + /** + * The melt we look for. + */ + const struct TALER_EXCHANGEDB_Refresh_vDOLDPLUS *rf; + + /** + * How many records matched @e rf. + */ + unsigned int seen; + + /** + * Set if a matching record differed from @e rf. + */ + bool mismatch; + + /** + * Serial of the matching record. + */ + uint64_t serial; + + /** + * Execution date of the matching record. + */ + struct GNUNET_TIME_Timestamp execution_date; +}; + + +/** + * Callback for #TALER_EXCHANGEDB_iterate_records_by_table(). + * + * @param cls a `struct ReplicationContext *` + * @param td the record + * @return #GNUNET_OK to continue iterating + */ +static int +replication_cb (void *cls, + const struct TALER_EXCHANGEDB_TableData *td) +{ + struct ReplicationContext *rc = cls; + const struct TALER_EXCHANGEDB_Refresh_vDOLDPLUS *rf = rc->rf; + + if (TALER_EXCHANGEDB_RT_REFRESH != td->table) + { + rc->mismatch = true; + return GNUNET_OK; + } + if (0 != GNUNET_memcmp (&td->details.refresh.rc, + &rf->rc)) + return GNUNET_OK; + rc->seen++; + rc->serial = td->serial; + rc->execution_date = td->details.refresh.execution_date; + if ( (rf->num_coins != td->details.refresh.num_coins) || + (NULL == td->details.refresh.transfer_pubs) || + (0 != GNUNET_memcmp (&td->details.refresh.transfer_pubs[0], + &rf->transfer_pubs[0])) || + (! td->details.refresh.revealed) || + (rf->rc_version != td->details.refresh.rc_version) ) + rc->mismatch = true; + return GNUNET_OK; +} + + +/** + * The auditor replication copies a melt with its transfer public keys, + * reveal status and commitment version. + * + * @param pg the database context + * @return 0 on success + */ +static int +check_replication (struct TALER_EXCHANGEDB_PostgresContext *pg) +{ + struct TALER_CoinPublicInfo coin; + struct TALER_EXCHANGEDB_Refresh_vDOLDPLUS rf; + struct RefreshStatus st; + struct ReplicationContext rc = { + .rf = &rf + }; + struct TALER_EXCHANGEDB_TableData td = { + .table = TALER_EXCHANGEDB_RT_REFRESH + }; + char *hex; + + TDB_coin (pg, + &denom, + 60, + &coin, + NULL); + make_refresh (60, + "1", + &coin, + false, + &rf); + TDB_coin_free (&coin); + rf.is_v27_refresh = false; + rf.rc_version = TALER_REFRESH_COMMITMENT_VERSION_CURRENT; + rf.transfer_pubs = GNUNET_new_array (rf.num_coins, + struct TALER_TransferPublicKeyP); + TDB_fill (rf.transfer_pubs, + sizeof (*rf.transfer_pubs) * rf.num_coins, + 60); + FAILIF_C (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + run_refresh (pg, + &rf, + false, + &st), + free_refresh (&rf)); + hex = TDB_hex (&rf.rc, + sizeof (rf.rc)); + FAILIF_C (GNUNET_OK != + TDB_exec (pg, + "UPDATE refresh SET revealed=TRUE" + " WHERE rc=decode('%s','hex');", + hex), + GNUNET_free (hex); free_refresh (&rf)); + FAILIF_C (0 >= + TALER_EXCHANGEDB_iterate_records_by_table ( + pg, + TALER_EXCHANGEDB_RT_REFRESH, + 0, + &replication_cb, + &rc), + GNUNET_free (hex); free_refresh (&rf)); + FAILIF_C ( (1 != rc.seen) || rc.mismatch, + GNUNET_free (hex); free_refresh (&rf)); + + /* drop the melt (and the coin history entry its insert trigger made) + and replicate it back in */ + FAILIF_C (GNUNET_OK != + TDB_exec (pg, + "DELETE FROM refresh" + " WHERE rc=decode('%s','hex');", + hex), + GNUNET_free (hex); free_refresh (&rf)); + FAILIF_C (GNUNET_OK != + TDB_exec (pg, + "DELETE FROM coin_history" + " WHERE table_name='refresh'" + " AND serial_id=%llu;", + (unsigned long long) rc.serial), + GNUNET_free (hex); free_refresh (&rf)); + GNUNET_free (hex); + td.serial = rc.serial; + td.details.refresh.rc = rf.rc; + td.details.refresh.execution_date = rc.execution_date; + td.details.refresh.amount_with_fee = rf.amount_with_fee; + td.details.refresh.old_coin_pub = rf.coin.coin_pub; + td.details.refresh.old_coin_sig = rf.coin_sig; + td.details.refresh.refresh_seed = rf.refresh_seed; + td.details.refresh.noreveal_index = rf.noreveal_index; + td.details.refresh.planchets_h = rf.planchets_h; + td.details.refresh.selected_h = rf.selected_h; + td.details.refresh.no_blinding_seed = true; + td.details.refresh.num_coins = rf.num_coins; + td.details.refresh.denom_serials = rf.denom_serials; + td.details.refresh.denom_sigs = rf.denom_sigs; + td.details.refresh.transfer_pubs = rf.transfer_pubs; + td.details.refresh.revealed = true; + td.details.refresh.rc_version = rf.rc_version; + FAILIF_C (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + TALER_EXCHANGEDB_insert_records_by_table (pg, + &td), + free_refresh (&rf)); + rc.seen = 0; + FAILIF_C (0 >= + TALER_EXCHANGEDB_iterate_records_by_table ( + pg, + TALER_EXCHANGEDB_RT_REFRESH, + 0, + &replication_cb, + &rc), + free_refresh (&rf)); + free_refresh (&rf); + FAILIF ( (1 != rc.seen) || rc.mismatch); + FAILIF (td.serial != rc.serial); + return 0; +} + + +/** * The checks to run, in order. */ static const struct TDB_Test tests[] = { @@ -821,6 +1008,8 @@ static const struct TDB_Test tests[] = { &check_iterate }, { "refresh-rc-version", &check_rc_version }, + { "refresh-replication", + &check_replication }, { NULL, NULL } }; diff --git a/src/include/exchange-database/iterate_records_by_table.h b/src/include/exchange-database/iterate_records_by_table.h @@ -332,6 +332,9 @@ struct TALER_EXCHANGEDB_TableData size_t num_coins; uint64_t *denom_serials; struct TALER_BlindedDenominationSignature *denom_sigs; + /* NULL for v27 melts, otherwise @e num_coins many */ + struct TALER_TransferPublicKeyP *transfer_pubs; + bool revealed; uint32_t rc_version; } refresh;