exchange

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

commit 6cf9f8f43a055adca63d01e0e26065474669b962
parent 249a3628167962d80768aabbe38b94d9708ac4dc
Author: Christian Grothoff <grothoff@gnunet.org>
Date:   Thu, 23 Oct 2025 12:32:31 +0200

fix #10321

Diffstat:
Msrc/auditor/taler-helper-auditor-purses.c | 129++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
Msrc/auditordb/pg_get_purse_info.c | 3++-
2 files changed, 104 insertions(+), 28 deletions(-)

diff --git a/src/auditor/taler-helper-auditor-purses.c b/src/auditor/taler-helper-auditor-purses.c @@ -359,6 +359,10 @@ load_auditor_purse_summary (struct PurseSummary *ps) &rowid, &ps->balance, &ps->expiration_date); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Loaded purse `%s' info (%d)\n", + TALER_B2S (&ps->purse_pub), + (int) qs); if (0 > qs) { GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); @@ -423,7 +427,12 @@ setup_purse (struct PurseContext *pc, ps = GNUNET_CONTAINER_multihashmap_get (pc->purses, &key); if (NULL != ps) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Found purse `%s' summary in cache\n", + TALER_B2S (&ps->purse_pub)); return ps; + } ps = GNUNET_new (struct PurseSummary); ps->purse_pub = *purse_pub; GNUNET_assert (GNUNET_OK == @@ -440,8 +449,15 @@ setup_purse (struct PurseContext *pc, &ps->merge_timestamp, &ps->purse_deleted, &ps->purse_refunded); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Loaded purse `%s' meta-data (%d)\n", + TALER_B2S (purse_pub), + (int) qs); if (0 >= qs) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Failed to load meta-data of purse `%s'\n", + TALER_B2S (&ps->purse_pub)); GNUNET_free (ps); pc->qs = qs; return NULL; @@ -454,6 +470,9 @@ setup_purse (struct PurseContext *pc, pc->qs = qs; return NULL; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Starting purse `%s' analysis\n", + TALER_B2S (purse_pub)); GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (pc->purses, &key, @@ -494,8 +513,10 @@ handle_purse_requested ( struct PurseContext *pc = cls; struct PurseSummary *ps; struct GNUNET_HashCode key; - enum GNUNET_DB_QueryStatus qs; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Handling purse request `%s'\n", + TALER_B2S (purse_pub)); TALER_ARL_USE_PP (purse_request_serial_id) = rowid; if (GNUNET_OK != TALER_wallet_purse_create_verify (purse_expiration, @@ -512,6 +533,7 @@ handle_purse_requested ( .loss = *target_amount, .operation_specific_pub = purse_pub->eddsa_pub }; + enum GNUNET_DB_QueryStatus qs; qs = TALER_ARL_adb->insert_bad_sig_losses ( TALER_ARL_adb->cls, @@ -538,6 +560,17 @@ handle_purse_requested ( ps->expiration_date = purse_expiration; ps->total_value = *target_amount; ps->h_contract_terms = *h_contract_terms; + { + enum GNUNET_DB_QueryStatus qs; + + qs = load_auditor_purse_summary (ps); + if (0 > qs) + { + GNUNET_free (ps); + pc->qs = qs; + return GNUNET_SYSERR; + } + } GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (pc->purses, &key, @@ -575,21 +608,22 @@ handle_purse_deposits ( { struct PurseContext *pc = cls; struct TALER_Amount amount_minus_fee; - struct PurseSummary *ps; const char *base_url = (NULL == deposit->exchange_base_url) ? TALER_ARL_exchange_url : deposit->exchange_base_url; struct TALER_DenominationHashP h_denom_pub; - enum GNUNET_DB_QueryStatus qs; /* should be monotonically increasing */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Handling purse deposit `%s'\n", + TALER_B2S (&deposit->purse_pub)); GNUNET_assert (rowid >= TALER_ARL_USE_PP (purse_deposits_serial_id)); TALER_ARL_USE_PP (purse_deposits_serial_id) = rowid + 1; { const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue; - + enum GNUNET_DB_QueryStatus qs; qs = TALER_ARL_get_denomination_info (denom_pub, &issue, @@ -606,6 +640,10 @@ handle_purse_deposits ( } if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to find denomination key for purse deposit `%s' in record %llu\n", + TALER_B2S (&deposit->purse_pub), + (unsigned long long) rowid); qs = report_row_inconsistency ("purse-deposit", rowid, "denomination key not found"); @@ -637,7 +675,12 @@ handle_purse_deposits ( .loss = deposit->amount, .operation_specific_pub = deposit->coin_pub.eddsa_pub }; + enum GNUNET_DB_QueryStatus qs; + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to verify purse deposit signature on `%s' in record %llu\n", + TALER_B2S (&deposit->purse_pub), + (unsigned long long) rowid); qs = TALER_ARL_adb->insert_bad_sig_losses ( TALER_ARL_adb->cls, &bsl); @@ -653,33 +696,39 @@ handle_purse_deposits ( return GNUNET_OK; } - ps = setup_purse (pc, - &deposit->purse_pub); - if (NULL == ps) { - if (0 > pc->qs) - { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == pc->qs); - return GNUNET_SYSERR; - } - GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == pc->qs); - qs = report_row_inconsistency ("purse_deposit", - rowid, - "purse not found"); - if (0 > qs) + struct PurseSummary *ps; + + ps = setup_purse (pc, + &deposit->purse_pub); + if (NULL == ps) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); - pc->qs = qs; - return GNUNET_SYSERR; + enum GNUNET_DB_QueryStatus qs; + + if (0 > pc->qs) + { + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == pc->qs); + return GNUNET_SYSERR; + } + GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == pc->qs); + qs = report_row_inconsistency ("purse_deposit", + rowid, + "purse not found"); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + pc->qs = qs; + return GNUNET_SYSERR; + } + return GNUNET_OK; } - return GNUNET_OK; + TALER_ARL_amount_add (&ps->balance, + &ps->balance, + &amount_minus_fee); + TALER_ARL_amount_add (&TALER_ARL_USE_AB (purse_global_balance), + &TALER_ARL_USE_AB (purse_global_balance), + &amount_minus_fee); } - TALER_ARL_amount_add (&ps->balance, - &ps->balance, - &amount_minus_fee); - TALER_ARL_amount_add (&TALER_ARL_USE_AB (purse_global_balance), - &TALER_ARL_USE_AB (purse_global_balance), - &amount_minus_fee); return GNUNET_OK; } @@ -720,6 +769,9 @@ handle_purse_merged ( enum GNUNET_DB_QueryStatus qs; /* should be monotonically increasing */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Handling purse merged `%s'\n", + TALER_B2S (purse_pub)); GNUNET_assert (rowid >= TALER_ARL_USE_PP (purse_merges_serial_id)); TALER_ARL_USE_PP (purse_merges_serial_id) = rowid + 1; @@ -833,6 +885,9 @@ handle_account_merged ( enum GNUNET_DB_QueryStatus qs; /* should be monotonically increasing */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Handling account merge on purse `%s'\n", + TALER_B2S (purse_pub)); GNUNET_assert (rowid >= TALER_ARL_USE_PP (purse_account_merge_serial_id)); TALER_ARL_USE_PP (purse_account_merge_serial_id) = rowid + 1; if (GNUNET_OK != @@ -1028,6 +1083,9 @@ handle_purse_decision ( } } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Deleting purse with decision `%s'\n", + TALER_B2S (&ps->purse_pub)); qs = TALER_ARL_adb->delete_purse_info (TALER_ARL_adb->cls, purse_pub); if (qs < 0) @@ -1074,6 +1132,9 @@ handle_purse_deletion ( GNUNET_break (0); return GNUNET_SYSERR; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Handling purse `%s' deletion\n", + TALER_B2S (purse_pub)); if (GNUNET_OK != TALER_wallet_purse_delete_verify (purse_pub, purse_sig)) @@ -1147,6 +1208,9 @@ handle_purse_expired ( pc->qs = qs; return GNUNET_SYSERR; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Handling purse expiration `%s'\n", + TALER_B2S (purse_pub)); TALER_ARL_amount_add (&TALER_ARL_USE_AB (purse_total_delayed_decisions), &TALER_ARL_USE_AB (purse_total_delayed_decisions), balance); @@ -1229,14 +1293,25 @@ verify_purse_balance (void *cls, } if (ps->had_pi) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Updating purse `%s'\n", + TALER_B2S (&ps->purse_pub)); qs = TALER_ARL_adb->update_purse_info (TALER_ARL_adb->cls, &ps->purse_pub, &ps->balance); + } else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Inserting purse `%s'\n", + TALER_B2S (&ps->purse_pub)); qs = TALER_ARL_adb->insert_purse_info (TALER_ARL_adb->cls, &ps->purse_pub, &ps->balance, ps->expiration_date); + ps->had_pi = true; + } if (qs < 0) { GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); diff --git a/src/auditordb/pg_get_purse_info.c b/src/auditordb/pg_get_purse_info.c @@ -51,7 +51,8 @@ TAH_PG_get_purse_info ( PREPARE (pg, "auditor_get_purse_info", "SELECT" - " expiration_date" + " auditor_purses_rowid" + ",expiration_date" ",balance" " FROM auditor_purses" " WHERE purse_pub=$1");