exchange

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

commit 527a9a6157fb13601365ad3d22676d95f6240140
parent 263340e88275f201025052c99a00b9ba99fe951d
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat,  8 Aug 2026 21:44:59 +0200

properly set purse target balance and do not break if multiple rows match on certain checks

Diffstat:
Msrc/auditor/taler-helper-auditor-purses.c | 1+
Msrc/auditordb/get_kycauth_in_inconsistency.c | 8++++++++
Msrc/auditordb/get_reserve_in_inconsistency.c | 8++++++++
Msrc/auditordb/insert_purse_info.c | 16++++++++++------
Msrc/auditordb/meson.build | 8++++++++
Msrc/include/auditor-database/get_kycauth_in_inconsistency.h | 5+++--
Msrc/include/auditor-database/get_reserve_in_inconsistency.h | 5+++--
Msrc/include/auditor-database/insert_purse_info.h | 13+++++++------
8 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/src/auditor/taler-helper-auditor-purses.c b/src/auditor/taler-helper-auditor-purses.c @@ -1337,6 +1337,7 @@ verify_purse_balance (void *cls, qs = TALER_AUDITORDB_insert_purse_info (TALER_ARL_adb, &ps->purse_pub, &ps->balance, + &ps->total_value, ps->expiration_date); ps->had_pi = true; } diff --git a/src/auditordb/get_kycauth_in_inconsistency.c b/src/auditordb/get_kycauth_in_inconsistency.c @@ -69,6 +69,14 @@ TALER_AUDITORDB_get_kycauth_in_inconsistency ( ",suppressed" " FROM auditor_kycauth_in_inconsistency" " WHERE (bank_row_id = $1)" + /* bank_row_id is not unique: the column carries bank serials + from analyze_credit() and exchange-side reserves_in serials + from complain_in_not_found(), and the INSERT has no dedup. + Without LIMIT 1 a duplicate makes + GNUNET_PQ_eval_prepared_singleton_select() return a hard + error for ever, wedging the wire-credit auditor. */ + " ORDER BY row_id DESC" + " LIMIT 1" ); return GNUNET_PQ_eval_prepared_singleton_select ( pg->conn, diff --git a/src/auditordb/get_reserve_in_inconsistency.c b/src/auditordb/get_reserve_in_inconsistency.c @@ -69,6 +69,14 @@ TALER_AUDITORDB_get_reserve_in_inconsistency ( ",suppressed" " FROM auditor_reserve_in_inconsistency" " WHERE (bank_row_id = $1)" + /* bank_row_id is not unique: the column carries bank serials + from analyze_credit() and exchange-side reserves_in serials + from complain_in_not_found(), and the INSERT has no dedup. + Without LIMIT 1 a duplicate makes + GNUNET_PQ_eval_prepared_singleton_select() return a hard + error for ever, wedging the wire-credit auditor. */ + " ORDER BY row_id DESC" + " LIMIT 1" ); return GNUNET_PQ_eval_prepared_singleton_select ( pg->conn, diff --git a/src/auditordb/insert_purse_info.c b/src/auditordb/insert_purse_info.c @@ -24,16 +24,19 @@ enum GNUNET_DB_QueryStatus -TALER_AUDITORDB_insert_purse_info (struct TALER_AUDITORDB_PostgresContext *pg, - const struct TALER_PurseContractPublicKeyP * - purse_pub, - const struct TALER_Amount *balance, - struct GNUNET_TIME_Timestamp expiration_date) +TALER_AUDITORDB_insert_purse_info ( + struct TALER_AUDITORDB_PostgresContext *pg, + const struct TALER_PurseContractPublicKeyP *purse_pub, + const struct TALER_Amount *balance, + const struct TALER_Amount *target, + struct GNUNET_TIME_Timestamp expiration_date) { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (purse_pub), TALER_PQ_query_param_amount (pg->conn, balance), + TALER_PQ_query_param_amount (pg->conn, + target), GNUNET_PQ_query_param_timestamp (&expiration_date), GNUNET_PQ_query_param_end }; @@ -43,8 +46,9 @@ TALER_AUDITORDB_insert_purse_info (struct TALER_AUDITORDB_PostgresContext *pg, "INSERT INTO auditor_purses " "(purse_pub" ",target" + ",balance" ",expiration_date" - ") VALUES ($1,$2,$3);"); + ") VALUES ($1,$2,$3,$4);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_purse_info", params); diff --git a/src/auditordb/meson.build b/src/auditordb/meson.build @@ -58,6 +58,13 @@ auditor_0003_sql = [ 'commit.sql', ] +auditor_0004_sql = [ + '0004-preamble.sql', + '0004-auditor_reserve_in_inconsistency.sql', + '0004-auditor_kycauth_in_inconsistency.sql', + 'commit.sql', +] + generated_sql = [ ['versioning.sql', ['versioning.sql']], ['drop.sql', ['drop.sql']], @@ -66,6 +73,7 @@ generated_sql = [ ['auditor-0001.sql', ['auditor-0001.sql']], ['auditor-0002.sql', auditor_0002_sql], ['auditor-0003.sql', auditor_0003_sql], + ['auditor-0004.sql', auditor_0004_sql], ] foreach g : generated_sql diff --git a/src/include/auditor-database/get_kycauth_in_inconsistency.h b/src/include/auditor-database/get_kycauth_in_inconsistency.h @@ -25,8 +25,9 @@ /** - * Return any KYCAUTH incoming inconsistency associated with the given - * @a bank_row_id. + * Return the most recent KYCAUTH incoming inconsistency associated with + * the given @a bank_row_id. Note that @a bank_row_id is not unique, so + * there may be several; the newest one wins. * * @param pg the database context * @param bank_row_id row to select by diff --git a/src/include/auditor-database/get_reserve_in_inconsistency.h b/src/include/auditor-database/get_reserve_in_inconsistency.h @@ -25,8 +25,9 @@ /** - * Return any reserve incoming inconsistency associated with the - * given @a bank_row_id. + * Return the most recent reserve incoming inconsistency associated + * with the given @a bank_row_id. Note that @a bank_row_id is not + * unique, so there may be several; the newest one wins. * * @param pg the database context * @param bank_row_id row to select by diff --git a/src/include/auditor-database/insert_purse_info.h b/src/include/auditor-database/insert_purse_info.h @@ -33,15 +33,16 @@ * @param pg the database context * @param purse_pub public key of the purse * @param balance balance of the purse + * @param target expected final target balance of the purse * @param expiration_date expiration date of the purse * @return transaction status code */ enum GNUNET_DB_QueryStatus -TALER_AUDITORDB_insert_purse_info (struct TALER_AUDITORDB_PostgresContext *pg, - const struct TALER_PurseContractPublicKeyP * - purse_pub, - const struct TALER_Amount *balance, - struct GNUNET_TIME_Timestamp expiration_date) -; +TALER_AUDITORDB_insert_purse_info ( + struct TALER_AUDITORDB_PostgresContext *pg, + const struct TALER_PurseContractPublicKeyP *purse_pub, + const struct TALER_Amount *balance, + const struct TALER_Amount *target, + struct GNUNET_TIME_Timestamp expiration_date); #endif