exchange

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

commit a9ac0a8759909620d6995dba32942038ee9cd3c1
parent 83253275c08fac583fa32c209d9cdc905ffde41a
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 21 Aug 2024 22:29:22 +0200

clean up auditor and bugfixes

Diffstat:
Msrc/auditor/taler-helper-auditor-aggregation.c | 50++++++++++++++++++++++++--------------------------
Msrc/auditor/taler-helper-auditor-coins.c | 155++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/auditor/taler-helper-auditor-deposits.c | 207++++++++++++++++++++++++++++++++-----------------------------------------------
Msrc/auditor/taler-helper-auditor-purses.c | 128+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/auditor/taler-helper-auditor-reserves.c | 163+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/auditor/taler-helper-auditor-wire-credit.c | 92+++++++++++++++++++++++++++++--------------------------------------------------
Msrc/auditor/taler-helper-auditor-wire-debit.c | 182+++++++++++++++++++++++++++++++------------------------------------------------
Msrc/exchangedb/pg_select_purse_deposits_above_serial_id.c | 3++-
8 files changed, 445 insertions(+), 535 deletions(-)

diff --git a/src/auditor/taler-helper-auditor-aggregation.c b/src/auditor/taler-helper-auditor-aggregation.c @@ -1292,23 +1292,21 @@ analyze_aggregations (void *cls) { struct AggregationContext ac; struct WireFeeInfo *wfi; - enum GNUNET_DB_QueryStatus qsx; enum GNUNET_DB_QueryStatus qs; - enum GNUNET_DB_QueryStatus qsp; (void) cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Analyzing aggregations\n"); - qsp = TALER_ARL_adb->get_auditor_progress ( + qs = TALER_ARL_adb->get_auditor_progress ( TALER_ARL_adb->cls, TALER_ARL_GET_PP (aggregation_last_wire_out_serial_id), NULL); - if (0 > qsp) + if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsp); - return qsp; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsp) + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "First analysis using this auditor, starting audit from scratch\n"); @@ -1324,7 +1322,7 @@ analyze_aggregations (void *cls) memset (&ac, 0, sizeof (ac)); - qsx = TALER_ARL_adb->get_balance ( + qs = TALER_ARL_adb->get_balance ( TALER_ARL_adb->cls, TALER_ARL_GET_AB (aggregation_total_wire_fee_revenue), TALER_ARL_GET_AB (aggregation_total_arithmetic_delta_plus), @@ -1334,11 +1332,12 @@ analyze_aggregations (void *cls) TALER_ARL_GET_AB (aggregation_total_wire_out_delta_minus), TALER_ARL_GET_AB (aggregation_total_coin_delta_plus), NULL); - if (0 > qsx) + if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx); - return qsx; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } + ac.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; qs = TALER_ARL_edb->select_wire_out_above_serial_id ( TALER_ARL_edb->cls, @@ -1402,23 +1401,22 @@ analyze_aggregations (void *cls) return qs; } - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp) - { - qs = TALER_ARL_adb->insert_auditor_progress ( - TALER_ARL_adb->cls, - TALER_ARL_SET_PP (aggregation_last_wire_out_serial_id), - NULL); - } - else + qs = TALER_ARL_adb->insert_auditor_progress ( + TALER_ARL_adb->cls, + TALER_ARL_SET_PP (aggregation_last_wire_out_serial_id), + NULL); + if (0 > qs) { - GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp); - qs = TALER_ARL_adb->update_auditor_progress ( - TALER_ARL_adb->cls, - TALER_ARL_SET_PP (aggregation_last_wire_out_serial_id), - NULL); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to update auditor DB, not recording progress\n"); + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } - - if (0 >= qs) + qs = TALER_ARL_adb->update_auditor_progress ( + TALER_ARL_adb->cls, + TALER_ARL_SET_PP (aggregation_last_wire_out_serial_id), + NULL); + if (0 > qs) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to update auditor DB, not recording progress\n"); diff --git a/src/auditor/taler-helper-auditor-coins.c b/src/auditor/taler-helper-auditor-coins.c @@ -2447,8 +2447,6 @@ analyze_coins (void *cls) { struct CoinContext cc; enum GNUNET_DB_QueryStatus qs; - enum GNUNET_DB_QueryStatus qsx; - enum GNUNET_DB_QueryStatus qsp; (void) cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -2463,7 +2461,7 @@ analyze_coins (void *cls) } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Analyzing coins\n"); - qsp = TALER_ARL_adb->get_auditor_progress ( + qs = TALER_ARL_adb->get_auditor_progress ( TALER_ARL_adb->cls, TALER_ARL_GET_PP (coins_withdraw_serial_id), TALER_ARL_GET_PP (coins_deposit_serial_id), @@ -2474,12 +2472,12 @@ analyze_coins (void *cls) TALER_ARL_GET_PP (coins_purse_deposits_serial_id), TALER_ARL_GET_PP (coins_purse_refunds_serial_id), NULL); - if (0 > qsp) + if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsp); - return qsp; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsp) + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "First analysis using this auditor, starting from scratch\n"); @@ -2509,7 +2507,7 @@ analyze_coins (void *cls) cc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; cc.denom_summaries = GNUNET_CONTAINER_multihashmap_create (256, GNUNET_NO); - qsx = TALER_ARL_adb->get_balance ( + qs = TALER_ARL_adb->get_balance ( TALER_ARL_adb->cls, TALER_ARL_GET_AB (coin_balance_risk), TALER_ARL_GET_AB (total_escrowed), @@ -2525,10 +2523,10 @@ analyze_coins (void *cls) TALER_ARL_GET_AB (coins_emergencies_loss), TALER_ARL_GET_AB (total_refresh_hanging), NULL); - if (0 > qsx) + if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx); - return qsx; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } /* process withdrawals */ if (0 > @@ -2648,46 +2646,47 @@ analyze_coins (void *cls) return cc.qs; } - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsx) + qs = TALER_ARL_adb->insert_balance ( + TALER_ARL_adb->cls, + TALER_ARL_SET_AB (coin_balance_risk), + TALER_ARL_SET_AB (total_escrowed), + TALER_ARL_SET_AB (coin_irregular_loss), + TALER_ARL_SET_AB (coin_melt_fee_revenue), + TALER_ARL_SET_AB (coin_deposit_fee_revenue), + TALER_ARL_SET_AB (coin_refund_fee_revenue), + TALER_ARL_SET_AB (total_recoup_loss), + TALER_ARL_SET_AB (coins_total_arithmetic_delta_plus), + TALER_ARL_SET_AB (coins_total_arithmetic_delta_minus), + TALER_ARL_SET_AB (coins_reported_emergency_risk_by_count), + TALER_ARL_SET_AB (coins_reported_emergency_risk_by_amount), + TALER_ARL_SET_AB (coins_emergencies_loss), + TALER_ARL_SET_AB (total_refresh_hanging), + NULL); + if (0 > qs) { - qs = TALER_ARL_adb->insert_balance ( - TALER_ARL_adb->cls, - TALER_ARL_SET_AB (coin_balance_risk), - TALER_ARL_SET_AB (total_escrowed), - TALER_ARL_SET_AB (coin_irregular_loss), - TALER_ARL_SET_AB (coin_melt_fee_revenue), - TALER_ARL_SET_AB (coin_deposit_fee_revenue), - TALER_ARL_SET_AB (coin_refund_fee_revenue), - TALER_ARL_SET_AB (total_recoup_loss), - TALER_ARL_SET_AB (coins_total_arithmetic_delta_plus), - TALER_ARL_SET_AB (coins_total_arithmetic_delta_minus), - TALER_ARL_SET_AB (coins_reported_emergency_risk_by_count), - TALER_ARL_SET_AB (coins_reported_emergency_risk_by_amount), - TALER_ARL_SET_AB (coins_emergencies_loss), - TALER_ARL_SET_AB (total_refresh_hanging), - NULL); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to update auditor DB, not recording progress\n"); + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } - else - { - GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsx); - qs = TALER_ARL_adb->update_balance ( - TALER_ARL_adb->cls, - TALER_ARL_SET_AB (coin_balance_risk), - TALER_ARL_SET_AB (total_escrowed), - TALER_ARL_SET_AB (coin_irregular_loss), - TALER_ARL_SET_AB (coin_melt_fee_revenue), - TALER_ARL_SET_AB (coin_deposit_fee_revenue), - TALER_ARL_SET_AB (coin_refund_fee_revenue), - TALER_ARL_SET_AB (total_recoup_loss), - TALER_ARL_SET_AB (coins_total_arithmetic_delta_plus), - TALER_ARL_SET_AB (coins_total_arithmetic_delta_minus), - TALER_ARL_SET_AB (coins_reported_emergency_risk_by_count), - TALER_ARL_SET_AB (coins_reported_emergency_risk_by_amount), - TALER_ARL_SET_AB (coins_emergencies_loss), - TALER_ARL_SET_AB (total_refresh_hanging), - NULL); - } - if (0 >= qs) + + qs = TALER_ARL_adb->update_balance ( + TALER_ARL_adb->cls, + TALER_ARL_SET_AB (coin_balance_risk), + TALER_ARL_SET_AB (total_escrowed), + TALER_ARL_SET_AB (coin_irregular_loss), + TALER_ARL_SET_AB (coin_melt_fee_revenue), + TALER_ARL_SET_AB (coin_deposit_fee_revenue), + TALER_ARL_SET_AB (coin_refund_fee_revenue), + TALER_ARL_SET_AB (total_recoup_loss), + TALER_ARL_SET_AB (coins_total_arithmetic_delta_plus), + TALER_ARL_SET_AB (coins_total_arithmetic_delta_minus), + TALER_ARL_SET_AB (coins_reported_emergency_risk_by_count), + TALER_ARL_SET_AB (coins_reported_emergency_risk_by_amount), + TALER_ARL_SET_AB (coins_emergencies_loss), + TALER_ARL_SET_AB (total_refresh_hanging), + NULL); + if (0 > qs) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to update auditor DB, not recording progress\n"); @@ -2695,42 +2694,44 @@ analyze_coins (void *cls) return qs; } - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsp) + qs = TALER_ARL_adb->insert_auditor_progress ( + TALER_ARL_adb->cls, + TALER_ARL_SET_PP (coins_withdraw_serial_id), + TALER_ARL_SET_PP (coins_deposit_serial_id), + TALER_ARL_SET_PP (coins_melt_serial_id), + TALER_ARL_SET_PP (coins_refund_serial_id), + TALER_ARL_SET_PP (coins_recoup_serial_id), + TALER_ARL_SET_PP (coins_recoup_refresh_serial_id), + TALER_ARL_SET_PP (coins_purse_deposits_serial_id), + TALER_ARL_SET_PP (coins_purse_refunds_serial_id), + NULL); + if (0 > qs) { - qs = TALER_ARL_adb->insert_auditor_progress ( - TALER_ARL_adb->cls, - TALER_ARL_SET_PP (coins_withdraw_serial_id), - TALER_ARL_SET_PP (coins_deposit_serial_id), - TALER_ARL_SET_PP (coins_melt_serial_id), - TALER_ARL_SET_PP (coins_refund_serial_id), - TALER_ARL_SET_PP (coins_recoup_serial_id), - TALER_ARL_SET_PP (coins_recoup_refresh_serial_id), - TALER_ARL_SET_PP (coins_purse_deposits_serial_id), - TALER_ARL_SET_PP (coins_purse_refunds_serial_id), - NULL); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to update auditor DB, not recording progress\n"); + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } - else - { - GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp); - qs = TALER_ARL_adb->update_auditor_progress ( - TALER_ARL_adb->cls, - TALER_ARL_SET_PP (coins_withdraw_serial_id), - TALER_ARL_SET_PP (coins_deposit_serial_id), - TALER_ARL_SET_PP (coins_melt_serial_id), - TALER_ARL_SET_PP (coins_refund_serial_id), - TALER_ARL_SET_PP (coins_recoup_serial_id), - TALER_ARL_SET_PP (coins_recoup_refresh_serial_id), - TALER_ARL_SET_PP (coins_purse_deposits_serial_id), - TALER_ARL_SET_PP (coins_purse_refunds_serial_id), - NULL); - } - if (0 >= qs) + + qs = TALER_ARL_adb->update_auditor_progress ( + TALER_ARL_adb->cls, + TALER_ARL_SET_PP (coins_withdraw_serial_id), + TALER_ARL_SET_PP (coins_deposit_serial_id), + TALER_ARL_SET_PP (coins_melt_serial_id), + TALER_ARL_SET_PP (coins_refund_serial_id), + TALER_ARL_SET_PP (coins_recoup_serial_id), + TALER_ARL_SET_PP (coins_recoup_refresh_serial_id), + TALER_ARL_SET_PP (coins_purse_deposits_serial_id), + TALER_ARL_SET_PP (coins_purse_refunds_serial_id), + NULL); + if (0 > qs) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to update auditor DB, not recording progress\n"); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Concluded coin audit step at %llu/%llu/%llu/%llu/%llu/%llu/%llu\n", (unsigned long long) TALER_ARL_USE_PP (coins_deposit_serial_id), diff --git a/src/auditor/taler-helper-auditor-deposits.c b/src/auditor/taler-helper-auditor-deposits.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2016-2023 Taler Systems SA + Copyright (C) 2016-2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero Public License as published by the Free Software @@ -59,24 +59,18 @@ */ static int global_ret; +static TALER_ARL_DEF_PP (deposit_confirmation_serial_id); + /** * Run in test mode. Exit when idle instead of * going to sleep and waiting for more work. - * - * FIXME: not yet implemented! */ static int test_mode; /** - * Total number of deposit confirmations that we did not get. - */ -// FIXME: persist! -static json_int_t number_missed_deposit_confirmations; - -/** * Total amount involved in deposit confirmations that we did not get. */ -static struct TALER_Amount total_missed_deposit_confirmations; +static TALER_ARL_DEF_AB (total_missed_deposit_confirmations); /** * Should we run checks that only work for exchange-internal audits? @@ -91,40 +85,11 @@ static struct GNUNET_DB_EventHandler *eh; static const struct GNUNET_CONFIGURATION_Handle *cfg; /** - * Closure for #test_dc. + * Success or failure of (exchange) database operations within + * #test_dc. */ -struct DepositConfirmationContext -{ - - /** - * How many deposit confirmations did we NOT find in the #TALER_ARL_edb? - */ - unsigned long long missed_count; - - /** - * What is the total amount missing? - */ - struct TALER_Amount missed_amount; - - /** - * Lowest SerialID of the first coin we missed? (This is where we - * should resume next time). - */ - // uint64_t first_missed_coin_serial; - - /** - * Lowest SerialID of the first coin we missed? (This is where we - * should resume next time). - */ - // uint64_t last_seen_coin_serial; - - /** - * Success or failure of (exchange) database operations within - * #test_dc. - */ - enum GNUNET_DB_QueryStatus qs; +static enum GNUNET_DB_QueryStatus eqs; -}; /** * Given a deposit confirmation from #TALER_ARL_adb, check that it is also @@ -140,15 +105,13 @@ test_dc (void *cls, uint64_t serial_id, const struct TALER_AUDITORDB_DepositConfirmation *dc) { - struct DepositConfirmationContext *dcc = cls; bool missing = false; - (void) cls; - enum GNUNET_DB_QueryStatus qs; - // dcc->last_seen_coin_serial = serial_id; + + (void) cls; + TALER_ARL_USE_PP (deposit_confirmation_serial_id) = serial_id; for (unsigned int i = 0; i < dc->num_coins; i++) { - struct GNUNET_TIME_Timestamp exchange_timestamp; struct TALER_Amount deposit_fee; @@ -164,7 +127,7 @@ test_dc (void *cls, if (qs < 0) { GNUNET_break (0); /* DB error, complain */ - dcc->qs = qs; + eqs = qs; return GNUNET_SYSERR; } } @@ -173,14 +136,9 @@ test_dc (void *cls, if (qs < 0) { GNUNET_break (0); /* DB error, complain */ - dcc->qs = qs; + eqs = qs; return GNUNET_SYSERR; } - if (dcc->qs == 1) - { - (void) cls; - - } if (! missing) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -188,10 +146,9 @@ test_dc (void *cls, GNUNET_h2s (&dc->h_contract_terms.hash)); return GNUNET_OK; /* all coins found, all good */ } - // dcc->first_missed_coin_serial = GNUNET_MIN (dcc->first_missed_coin_serial, serial_id); - dcc->missed_count++; - TALER_ARL_amount_add (&dcc->missed_amount, - &dcc->missed_amount, + // FIXME: where do we *decrease* this amount if we get a DC later? + TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_missed_deposit_confirmations), + &TALER_ARL_USE_AB (total_missed_deposit_confirmations), &dc->total_without_fee); return GNUNET_OK; } @@ -207,23 +164,19 @@ test_dc (void *cls, static enum GNUNET_DB_QueryStatus analyze_deposit_confirmations (void *cls) { - // TALER_ARL_DEF_PP (deposit_confirmation_serial_id); - struct DepositConfirmationContext dcc; - // enum GNUNET_DB_QueryStatus qs; - enum GNUNET_DB_QueryStatus qsx; - // enum GNUNET_DB_QueryStatus qsp; + enum GNUNET_DB_QueryStatus qs; + (void) cls; -/* - qsp = TALER_ARL_adb->get_auditor_progress ( + qs = TALER_ARL_adb->get_auditor_progress ( TALER_ARL_adb->cls, TALER_ARL_GET_PP (deposit_confirmation_serial_id), NULL); - if (0 > qsp) + if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsp); - return qsp; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsp) + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "First analysis using deposit auditor, starting audit from scratch\n"); @@ -235,70 +188,79 @@ analyze_deposit_confirmations (void *cls) (unsigned long long) TALER_ARL_USE_PP ( deposit_confirmation_serial_id)); } -*/ - /* setup 'cc' */ - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero (TALER_ARL_currency, - &dcc.missed_amount)); - dcc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; - dcc.missed_count = 0LLU; - // dcc.first_missed_coin_serial = UINT64_MAX; - - qsx = TALER_ARL_adb->get_deposit_confirmations ( + qs = TALER_ARL_adb->get_balance ( + TALER_ARL_adb->cls, + TALER_ARL_GET_AB (total_missed_deposit_confirmations), + NULL); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; + } + qs = TALER_ARL_adb->get_deposit_confirmations ( TALER_ARL_adb->cls, INT64_MAX, 0, true, /* return suppressed */ &test_dc, - &dcc); - - - if (0 > qsx) + NULL); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; + } + if (0 > eqs) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx); - return qsx; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == eqs); + return eqs; } GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Analyzed %d deposit confirmations\n", - (int) qsx); - if (0 > dcc.qs) + (int) qs); + qs = TALER_ARL_adb->insert_auditor_progress ( + TALER_ARL_adb->cls, + TALER_ARL_SET_PP (deposit_confirmation_serial_id), + NULL); + if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == dcc.qs); - return dcc.qs; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to update auditor DB, not recording progress\n"); + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; + } + qs = TALER_ARL_adb->update_auditor_progress ( + TALER_ARL_adb->cls, + TALER_ARL_SET_PP (deposit_confirmation_serial_id), + NULL); + if (0 > qs) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to update auditor DB, not recording progress\n"); + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; + } + qs = TALER_ARL_adb->insert_balance ( + TALER_ARL_adb->cls, + TALER_ARL_SET_AB (total_missed_deposit_confirmations), + NULL); + if (0 > qs) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to update auditor DB, not recording progress\n"); + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; + } + qs = TALER_ARL_adb->update_balance ( + TALER_ARL_adb->cls, + TALER_ARL_SET_AB (total_missed_deposit_confirmations), + NULL); + if (0 > qs) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to update auditor DB, not recording progress\n"); + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } -/* TODO: zu überprüfen - if (UINT64_MAX == dcc.first_missed_coin_serial) - ppdc.last_deposit_confirmation_serial_id = dcc.last_seen_coin_serial; - else - ppdc.last_deposit_confirmation_serial_id = dcc.first_missed_coin_serial - 1; - */ -/* sync 'cc' back to disk */ -/* - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp) - qs = TALER_ARL_adb->update_auditor_progress ( - TALER_ARL_adb->cls, - TALER_ARL_SET_PP (deposit_confirmation_serial_id), - NULL); - else - qs = TALER_ARL_adb->insert_auditor_progress ( - TALER_ARL_adb->cls, - TALER_ARL_SET_PP (deposit_confirmation_serial_id), - NULL); -*/ -// TODO :correct me and above -/* if (0 >= qs) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Failed to update auditor DB, not recording progress\n"); - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); - return qs; - }*/ - - number_missed_deposit_confirmations = (json_int_t) dcc.missed_count; - total_missed_deposit_confirmations = dcc.missed_amount; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Concluded deposit confirmation audit"); - return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; } @@ -367,7 +329,6 @@ run (void *cls, (void) args; (void) cfgfile; cfg = c; - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/auditor/taler-helper-auditor-purses.c b/src/auditor/taler-helper-auditor-purses.c @@ -1115,14 +1115,12 @@ static enum GNUNET_DB_QueryStatus analyze_purses (void *cls) { struct PurseContext pc; - enum GNUNET_DB_QueryStatus qsx; enum GNUNET_DB_QueryStatus qs; - enum GNUNET_DB_QueryStatus qsp; (void) cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Analyzing purses\n"); - qsp = TALER_ARL_adb->get_auditor_progress ( + qs = TALER_ARL_adb->get_auditor_progress ( TALER_ARL_adb->cls, TALER_ARL_GET_PP (purse_account_merge_serial_id), TALER_ARL_GET_PP (purse_decision_serial_id), @@ -1131,12 +1129,12 @@ analyze_purses (void *cls) TALER_ARL_GET_PP (purse_request_serial_id), TALER_ARL_GET_PP (purse_open_counter), NULL); - if (0 > qsp) + if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsp); - return qsp; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsp) + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "First analysis using this auditor, starting audit from scratch\n"); @@ -1157,7 +1155,7 @@ analyze_purses (void *cls) purse_account_merge_serial_id)); } pc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; - qsx = TALER_ARL_adb->get_balance ( + qs = TALER_ARL_adb->get_balance ( TALER_ARL_adb->cls, TALER_ARL_GET_AB (purse_global_balance), TALER_ARL_GET_AB (purse_total_balance_insufficient_loss), @@ -1167,10 +1165,10 @@ analyze_purses (void *cls) TALER_ARL_GET_AB (purse_total_arithmetic_delta_minus), TALER_ARL_GET_AB (purse_total_bad_sig_loss), NULL); - if (qsx < 0) + if (qs < 0) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx); - return qsx; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } pc.purses = GNUNET_CONTAINER_multihashmap_create (512, GNUNET_NO); @@ -1195,6 +1193,7 @@ analyze_purses (void *cls) GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + qs = TALER_ARL_edb->select_purse_deposits_above_serial_id ( TALER_ARL_edb->cls, TALER_ARL_USE_PP (purse_deposits_serial_id), @@ -1205,6 +1204,7 @@ analyze_purses (void *cls) GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + /* Charge purse fee! */ qs = TALER_ARL_edb->select_account_merges_above_serial_id ( TALER_ARL_edb->cls, @@ -1216,6 +1216,7 @@ analyze_purses (void *cls) GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + qs = TALER_ARL_edb->select_all_purse_decisions_above_serial_id ( TALER_ARL_edb->cls, TALER_ARL_USE_PP (purse_decision_serial_id), @@ -1226,6 +1227,7 @@ analyze_purses (void *cls) GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + qs = TALER_ARL_adb->select_purse_expired ( TALER_ARL_adb->cls, &handle_purse_expired, @@ -1244,66 +1246,70 @@ analyze_purses (void *cls) GNUNET_CONTAINER_multihashmap_destroy (pc.purses); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != pc.qs) return qs; - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsx) - { - qs = TALER_ARL_adb->insert_balance ( - TALER_ARL_adb->cls, - TALER_ARL_SET_AB (purse_global_balance), - TALER_ARL_SET_AB (purse_total_balance_insufficient_loss), - TALER_ARL_SET_AB (purse_total_delayed_decisions), - TALER_ARL_SET_AB (purse_total_balance_purse_not_closed), - TALER_ARL_SET_AB (purse_total_arithmetic_delta_plus), - TALER_ARL_SET_AB (purse_total_arithmetic_delta_minus), - TALER_ARL_SET_AB (purse_total_bad_sig_loss), - NULL); - } - else - { - GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsx); - qs = TALER_ARL_adb->update_balance ( - TALER_ARL_adb->cls, - TALER_ARL_SET_AB (purse_global_balance), - TALER_ARL_SET_AB (purse_total_balance_insufficient_loss), - TALER_ARL_SET_AB (purse_total_delayed_decisions), - TALER_ARL_SET_AB (purse_total_balance_purse_not_closed), - TALER_ARL_SET_AB (purse_total_arithmetic_delta_plus), - TALER_ARL_SET_AB (purse_total_arithmetic_delta_minus), - TALER_ARL_SET_AB (purse_total_bad_sig_loss), - NULL); - } - if (0 >= qs) + + qs = TALER_ARL_adb->insert_balance ( + TALER_ARL_adb->cls, + TALER_ARL_SET_AB (purse_global_balance), + TALER_ARL_SET_AB (purse_total_balance_insufficient_loss), + TALER_ARL_SET_AB (purse_total_delayed_decisions), + TALER_ARL_SET_AB (purse_total_balance_purse_not_closed), + TALER_ARL_SET_AB (purse_total_arithmetic_delta_plus), + TALER_ARL_SET_AB (purse_total_arithmetic_delta_minus), + TALER_ARL_SET_AB (purse_total_bad_sig_loss), + NULL); + if (0 > qs) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to update auditor DB, not recording progress\n"); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsp) + + qs = TALER_ARL_adb->update_balance ( + TALER_ARL_adb->cls, + TALER_ARL_SET_AB (purse_global_balance), + TALER_ARL_SET_AB (purse_total_balance_insufficient_loss), + TALER_ARL_SET_AB (purse_total_delayed_decisions), + TALER_ARL_SET_AB (purse_total_balance_purse_not_closed), + TALER_ARL_SET_AB (purse_total_arithmetic_delta_plus), + TALER_ARL_SET_AB (purse_total_arithmetic_delta_minus), + TALER_ARL_SET_AB (purse_total_bad_sig_loss), + NULL); + if (0 > qs) { - qs = TALER_ARL_adb->insert_auditor_progress ( - TALER_ARL_adb->cls, - TALER_ARL_SET_PP (purse_account_merge_serial_id), - TALER_ARL_SET_PP (purse_decision_serial_id), - TALER_ARL_SET_PP (purse_deposits_serial_id), - TALER_ARL_SET_PP (purse_merges_serial_id), - TALER_ARL_SET_PP (purse_request_serial_id), - TALER_ARL_SET_PP (purse_open_counter), - NULL); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to update auditor DB, not recording progress\n"); + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } - else + + qs = TALER_ARL_adb->insert_auditor_progress ( + TALER_ARL_adb->cls, + TALER_ARL_SET_PP (purse_account_merge_serial_id), + TALER_ARL_SET_PP (purse_decision_serial_id), + TALER_ARL_SET_PP (purse_deposits_serial_id), + TALER_ARL_SET_PP (purse_merges_serial_id), + TALER_ARL_SET_PP (purse_request_serial_id), + TALER_ARL_SET_PP (purse_open_counter), + NULL); + if (0 > qs) { - GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp); - qs = TALER_ARL_adb->update_auditor_progress ( - TALER_ARL_adb->cls, - TALER_ARL_SET_PP (purse_account_merge_serial_id), - TALER_ARL_SET_PP (purse_decision_serial_id), - TALER_ARL_SET_PP (purse_deposits_serial_id), - TALER_ARL_SET_PP (purse_merges_serial_id), - TALER_ARL_SET_PP (purse_request_serial_id), - TALER_ARL_SET_PP (purse_open_counter), - NULL); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to update auditor DB, not recording progress\n"); + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } - if (0 >= qs) + + qs = TALER_ARL_adb->update_auditor_progress ( + TALER_ARL_adb->cls, + TALER_ARL_SET_PP (purse_account_merge_serial_id), + TALER_ARL_SET_PP (purse_decision_serial_id), + TALER_ARL_SET_PP (purse_deposits_serial_id), + TALER_ARL_SET_PP (purse_merges_serial_id), + TALER_ARL_SET_PP (purse_request_serial_id), + TALER_ARL_SET_PP (purse_open_counter), + NULL); + if (0 > qs) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to update auditor DB, not recording progress\n"); diff --git a/src/auditor/taler-helper-auditor-reserves.c b/src/auditor/taler-helper-auditor-reserves.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2016-2022 Taler Systems SA + Copyright (C) 2016-2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero Public License as published by the Free Software @@ -1674,14 +1674,12 @@ static enum GNUNET_DB_QueryStatus analyze_reserves (void *cls) { struct ReserveContext rc; - enum GNUNET_DB_QueryStatus qsx; enum GNUNET_DB_QueryStatus qs; - enum GNUNET_DB_QueryStatus qsp; (void) cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Analyzing reserves\n"); - qsp = TALER_ARL_adb->get_auditor_progress ( + qs = TALER_ARL_adb->get_auditor_progress ( TALER_ARL_adb->cls, TALER_ARL_GET_PP (reserves_reserve_in_serial_id), TALER_ARL_GET_PP (reserves_reserve_out_serial_id), @@ -1692,12 +1690,12 @@ analyze_reserves (void *cls) TALER_ARL_GET_PP (reserves_account_merges_serial_id), TALER_ARL_GET_PP (reserves_history_requests_serial_id), NULL); - if (0 > qsp) + if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsp); - return qsp; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsp) + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "First analysis using this auditor, starting audit from scratch\n"); @@ -1724,7 +1722,7 @@ analyze_reserves (void *cls) reserves_history_requests_serial_id)); } rc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; - qsx = TALER_ARL_adb->get_balance ( + qs = TALER_ARL_adb->get_balance ( TALER_ARL_adb->cls, TALER_ARL_GET_AB (reserves_reserve_total_balance), TALER_ARL_GET_AB (reserves_reserve_loss), @@ -1739,15 +1737,16 @@ analyze_reserves (void *cls) TALER_ARL_GET_AB (reserves_total_arithmetic_delta_minus), TALER_ARL_GET_AB (total_balance_summary_delta_minus), NULL); - if (qsx < 0) + if (qs < 0) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx); - return qsx; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } rc.reserves = GNUNET_CONTAINER_multihashmap_create (512, GNUNET_NO); rc.revoked = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO); + qs = TALER_ARL_edb->select_reserves_in_above_serial_id ( TALER_ARL_edb->cls, TALER_ARL_USE_PP (reserves_reserve_in_serial_id), @@ -1758,6 +1757,7 @@ analyze_reserves (void *cls) GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + qs = TALER_ARL_edb->select_withdrawals_above_serial_id ( TALER_ARL_edb->cls, TALER_ARL_USE_PP (reserves_reserve_out_serial_id), @@ -1768,6 +1768,7 @@ analyze_reserves (void *cls) GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + qs = TALER_ARL_edb->select_recoup_above_serial_id ( TALER_ARL_edb->cls, TALER_ARL_USE_PP (reserves_reserve_recoup_serial_id), @@ -1778,6 +1779,7 @@ analyze_reserves (void *cls) GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + qs = TALER_ARL_edb->select_reserve_open_above_serial_id ( TALER_ARL_edb->cls, TALER_ARL_USE_PP (reserves_reserve_open_serial_id), @@ -1788,6 +1790,7 @@ analyze_reserves (void *cls) GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + qs = TALER_ARL_edb->select_reserve_closed_above_serial_id ( TALER_ARL_edb->cls, TALER_ARL_USE_PP (reserves_reserve_close_serial_id), @@ -1798,6 +1801,7 @@ analyze_reserves (void *cls) GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + /* process purse_decisions (to credit reserve) */ if (0 > (qs = TALER_ARL_edb->select_purse_decisions_above_serial_id ( @@ -1810,9 +1814,11 @@ analyze_reserves (void *cls) GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + if (0 > rc.qs) return rc.qs; /* Charge purse fee! */ + qs = TALER_ARL_edb->select_account_merges_above_serial_id ( TALER_ARL_edb->cls, TALER_ARL_USE_PP (reserves_account_merges_serial_id), @@ -1823,6 +1829,7 @@ analyze_reserves (void *cls) GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + GNUNET_CONTAINER_multihashmap_iterate (rc.reserves, &verify_reserve_balance, &rc); @@ -1832,84 +1839,86 @@ analyze_reserves (void *cls) GNUNET_CONTAINER_multihashmap_destroy (rc.revoked); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != rc.qs) return qs; - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsx) - { - qs = TALER_ARL_adb->insert_balance ( - TALER_ARL_adb->cls, - TALER_ARL_SET_AB (reserves_reserve_total_balance), - TALER_ARL_SET_AB (reserves_reserve_loss), - TALER_ARL_SET_AB (reserves_withdraw_fee_revenue), - TALER_ARL_SET_AB (reserves_close_fee_revenue), - TALER_ARL_SET_AB (reserves_purse_fee_revenue), - TALER_ARL_SET_AB (reserves_open_fee_revenue), - TALER_ARL_SET_AB (reserves_history_fee_revenue), - TALER_ARL_SET_AB (reserves_total_bad_sig_loss), - TALER_ARL_SET_AB (total_balance_reserve_not_closed), - TALER_ARL_SET_AB (reserves_total_arithmetic_delta_plus), - TALER_ARL_SET_AB (reserves_total_arithmetic_delta_minus), - TALER_ARL_SET_AB (total_balance_summary_delta_minus), - NULL); - } - else - { - GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsx); - qs = TALER_ARL_adb->update_balance ( - TALER_ARL_adb->cls, - TALER_ARL_SET_AB (reserves_reserve_total_balance), - TALER_ARL_SET_AB (reserves_reserve_loss), - TALER_ARL_SET_AB (reserves_withdraw_fee_revenue), - TALER_ARL_SET_AB (reserves_close_fee_revenue), - TALER_ARL_SET_AB (reserves_purse_fee_revenue), - TALER_ARL_SET_AB (reserves_open_fee_revenue), - TALER_ARL_SET_AB (reserves_history_fee_revenue), - TALER_ARL_SET_AB (reserves_total_bad_sig_loss), - TALER_ARL_SET_AB (total_balance_reserve_not_closed), - TALER_ARL_SET_AB (reserves_total_arithmetic_delta_plus), - TALER_ARL_SET_AB (reserves_total_arithmetic_delta_minus), - TALER_ARL_SET_AB (total_balance_summary_delta_minus), - NULL); - } - if (0 >= qs) + + qs = TALER_ARL_adb->insert_balance ( + TALER_ARL_adb->cls, + TALER_ARL_SET_AB (reserves_reserve_total_balance), + TALER_ARL_SET_AB (reserves_reserve_loss), + TALER_ARL_SET_AB (reserves_withdraw_fee_revenue), + TALER_ARL_SET_AB (reserves_close_fee_revenue), + TALER_ARL_SET_AB (reserves_purse_fee_revenue), + TALER_ARL_SET_AB (reserves_open_fee_revenue), + TALER_ARL_SET_AB (reserves_history_fee_revenue), + TALER_ARL_SET_AB (reserves_total_bad_sig_loss), + TALER_ARL_SET_AB (total_balance_reserve_not_closed), + TALER_ARL_SET_AB (reserves_total_arithmetic_delta_plus), + TALER_ARL_SET_AB (reserves_total_arithmetic_delta_minus), + TALER_ARL_SET_AB (total_balance_summary_delta_minus), + NULL); + if (0 > qs) { GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsp) + + qs = TALER_ARL_adb->update_balance ( + TALER_ARL_adb->cls, + TALER_ARL_SET_AB (reserves_reserve_total_balance), + TALER_ARL_SET_AB (reserves_reserve_loss), + TALER_ARL_SET_AB (reserves_withdraw_fee_revenue), + TALER_ARL_SET_AB (reserves_close_fee_revenue), + TALER_ARL_SET_AB (reserves_purse_fee_revenue), + TALER_ARL_SET_AB (reserves_open_fee_revenue), + TALER_ARL_SET_AB (reserves_history_fee_revenue), + TALER_ARL_SET_AB (reserves_total_bad_sig_loss), + TALER_ARL_SET_AB (total_balance_reserve_not_closed), + TALER_ARL_SET_AB (reserves_total_arithmetic_delta_plus), + TALER_ARL_SET_AB (reserves_total_arithmetic_delta_minus), + TALER_ARL_SET_AB (total_balance_summary_delta_minus), + NULL); + if (0 > qs) { - qs = TALER_ARL_adb->insert_auditor_progress ( - TALER_ARL_adb->cls, - TALER_ARL_SET_PP (reserves_reserve_in_serial_id), - TALER_ARL_SET_PP (reserves_reserve_out_serial_id), - TALER_ARL_SET_PP (reserves_reserve_recoup_serial_id), - TALER_ARL_SET_PP (reserves_reserve_open_serial_id), - TALER_ARL_SET_PP (reserves_reserve_close_serial_id), - TALER_ARL_SET_PP (reserves_purse_decisions_serial_id), - TALER_ARL_SET_PP (reserves_account_merges_serial_id), - TALER_ARL_SET_PP (reserves_history_requests_serial_id), - NULL); + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } - else + + qs = TALER_ARL_adb->insert_auditor_progress ( + TALER_ARL_adb->cls, + TALER_ARL_SET_PP (reserves_reserve_in_serial_id), + TALER_ARL_SET_PP (reserves_reserve_out_serial_id), + TALER_ARL_SET_PP (reserves_reserve_recoup_serial_id), + TALER_ARL_SET_PP (reserves_reserve_open_serial_id), + TALER_ARL_SET_PP (reserves_reserve_close_serial_id), + TALER_ARL_SET_PP (reserves_purse_decisions_serial_id), + TALER_ARL_SET_PP (reserves_account_merges_serial_id), + TALER_ARL_SET_PP (reserves_history_requests_serial_id), + NULL); + if (0 > qs) { - GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp); - qs = TALER_ARL_adb->update_auditor_progress ( - TALER_ARL_adb->cls, - TALER_ARL_SET_PP (reserves_reserve_in_serial_id), - TALER_ARL_SET_PP (reserves_reserve_out_serial_id), - TALER_ARL_SET_PP (reserves_reserve_recoup_serial_id), - TALER_ARL_SET_PP (reserves_reserve_open_serial_id), - TALER_ARL_SET_PP (reserves_reserve_close_serial_id), - TALER_ARL_SET_PP (reserves_purse_decisions_serial_id), - TALER_ARL_SET_PP (reserves_account_merges_serial_id), - TALER_ARL_SET_PP (reserves_history_requests_serial_id), - NULL); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to update auditor DB, not recording progress\n"); + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } - if (0 >= qs) + qs = TALER_ARL_adb->update_auditor_progress ( + TALER_ARL_adb->cls, + TALER_ARL_SET_PP (reserves_reserve_in_serial_id), + TALER_ARL_SET_PP (reserves_reserve_out_serial_id), + TALER_ARL_SET_PP (reserves_reserve_recoup_serial_id), + TALER_ARL_SET_PP (reserves_reserve_open_serial_id), + TALER_ARL_SET_PP (reserves_reserve_close_serial_id), + TALER_ARL_SET_PP (reserves_purse_decisions_serial_id), + TALER_ARL_SET_PP (reserves_account_merges_serial_id), + TALER_ARL_SET_PP (reserves_history_requests_serial_id), + NULL); + if (0 > qs) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to update auditor DB, not recording progress\n"); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Concluded reserve audit step at %llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu\n", (unsigned long long) TALER_ARL_USE_PP ( @@ -1996,10 +2005,8 @@ run (void *cls, (void) cfgfile; cfg = c; - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching reserves auditor\n"); if (GNUNET_OK != diff --git a/src/auditor/taler-helper-auditor-wire-credit.c b/src/auditor/taler-helper-auditor-wire-credit.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2017-2023 Taler Systems SA + Copyright (C) 2017-2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -105,10 +105,6 @@ struct WireAccount */ char *label_wire_off_in; - /** - * Return value when we got this account's progress point. - */ - enum GNUNET_DB_QueryStatus qsx; }; @@ -177,16 +173,6 @@ static TALER_ARL_DEF_AB (total_wire_format_amount); // FIXME static TALER_ARL_DEF_AB (total_wire_in); /** - * True if #total_wire_in was initialized. - */ -static bool had_start_balance; - -/** - * True if #wire_reserve_in_id was initialized. - */ -static bool had_start_progress; - -/** * Amount of zero in our currency. */ static struct TALER_Amount zero; @@ -338,19 +324,15 @@ commit (enum GNUNET_DB_QueryStatus qs) { if (qs >= 0) { - if (had_start_balance) - { - qs = TALER_ARL_adb->update_balance ( - TALER_ARL_adb->cls, - TALER_ARL_SET_AB (total_wire_in), - TALER_ARL_SET_AB (total_bad_amount_in_plus), - TALER_ARL_SET_AB (total_bad_amount_in_minus), - TALER_ARL_SET_AB (total_misattribution_in), - TALER_ARL_SET_AB (total_wire_format_amount), - NULL); - } - else - { + qs = TALER_ARL_adb->update_balance ( + TALER_ARL_adb->cls, + TALER_ARL_SET_AB (total_wire_in), + TALER_ARL_SET_AB (total_bad_amount_in_plus), + TALER_ARL_SET_AB (total_bad_amount_in_minus), + TALER_ARL_SET_AB (total_misattribution_in), + TALER_ARL_SET_AB (total_wire_format_amount), + NULL); + if (0 <= qs) qs = TALER_ARL_adb->insert_balance ( TALER_ARL_adb->cls, TALER_ARL_SET_AB (total_wire_in), @@ -359,34 +341,31 @@ commit (enum GNUNET_DB_QueryStatus qs) TALER_ARL_SET_AB (total_misattribution_in), TALER_ARL_SET_AB (total_wire_format_amount), NULL); + if (0 > qs) + { + if (GNUNET_DB_STATUS_SOFT_ERROR == qs) + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Serialization issue, not recording progress\n"); + else + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Hard error, not recording progress\n"); + TALER_ARL_adb->rollback (TALER_ARL_adb->cls); + TALER_ARL_edb->rollback (TALER_ARL_edb->cls); + return; } } - if (0 > qs) - { - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Serialization issue, not recording progress\n"); - else - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Hard error, not recording progress\n"); - TALER_ARL_adb->rollback (TALER_ARL_adb->cls); - TALER_ARL_edb->rollback (TALER_ARL_edb->cls); - return; - } for (struct WireAccount *wa = wa_head; NULL != wa; wa = wa->next) { - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == wa->qsx && - had_start_progress) - qs = TALER_ARL_adb->update_auditor_progress ( - TALER_ARL_adb->cls, - wa->label_reserve_in_serial_id, - wa->last_reserve_in_serial_id, - wa->label_wire_off_in, - wa->wire_off_in, - NULL); - else + qs = TALER_ARL_adb->update_auditor_progress ( + TALER_ARL_adb->cls, + wa->label_reserve_in_serial_id, + wa->last_reserve_in_serial_id, + wa->label_wire_off_in, + wa->wire_off_in, + NULL); + if (0 <= qs) qs = TALER_ARL_adb->insert_auditor_progress ( TALER_ARL_adb->cls, wa->label_reserve_in_serial_id, @@ -394,7 +373,7 @@ commit (enum GNUNET_DB_QueryStatus qs) wa->label_wire_off_in, wa->wire_off_in, NULL); - if (0 >= qs) + if (0 > qs) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to update auditor DB, not recording progress\n"); @@ -983,10 +962,7 @@ begin_transaction (void) GNUNET_break (0); return qs; case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - had_start_balance = false; - break; case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: - had_start_balance = true; break; } for (struct WireAccount *wa = wa_head; @@ -1001,17 +977,17 @@ begin_transaction (void) "wire-%s-%s", wa->ai->section_name, "wire_off_in"); - wa->qsx = TALER_ARL_adb->get_auditor_progress ( + qs = TALER_ARL_adb->get_auditor_progress ( TALER_ARL_adb->cls, wa->label_reserve_in_serial_id, &wa->last_reserve_in_serial_id, wa->label_wire_off_in, &wa->wire_off_in, NULL); - if (0 > wa->qsx) + if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == wa->qsx); - return GNUNET_DB_STATUS_HARD_ERROR; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } wa->start_reserve_in_serial_id = wa->last_reserve_in_serial_id; } diff --git a/src/auditor/taler-helper-auditor-wire-debit.c b/src/auditor/taler-helper-auditor-wire-debit.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2017-2023 Taler Systems SA + Copyright (C) 2017-2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -109,11 +109,6 @@ struct WireAccount * Label under which we store our wire_off_out. */ char *label_wire_off_out; - - /** - * Return value when we got this account's progress point. - */ - enum GNUNET_DB_QueryStatus qsx; }; @@ -183,12 +178,6 @@ static struct WireAccount *wa_head; static struct WireAccount *wa_tail; /** - * Query status for the incremental processing status in the auditordb. - * Return value from our call to the "get_wire_auditor_progress" function. - */ -static enum GNUNET_DB_QueryStatus qsx_gwap; - -/** * Last reserve_out / wire_out serial IDs seen. */ static TALER_ARL_DEF_PP (wire_reserve_close_id); @@ -236,16 +225,6 @@ static TALER_ARL_DEF_AB (total_wire_out); static TALER_ARL_DEF_AB (total_drained); /** - * True if #start_balance was initialized. - */ -static bool had_start_balance; - -/** - * True if #start_balance was initialized. - */ -static bool had_start_progress; - -/** * Amount of zero in our currency. */ static struct TALER_Amount zero; @@ -503,22 +482,18 @@ commit (enum GNUNET_DB_QueryStatus qs) { if (qs >= 0) { - if (had_start_balance) - { - qs = TALER_ARL_adb->update_balance ( - TALER_ARL_adb->cls, - TALER_ARL_SET_AB (total_drained), - TALER_ARL_SET_AB (total_wire_out), - TALER_ARL_SET_AB (total_bad_amount_out_plus), - TALER_ARL_SET_AB (total_bad_amount_out_minus), - TALER_ARL_SET_AB (total_amount_lag), - TALER_ARL_SET_AB (total_closure_amount_lag), - TALER_ARL_SET_AB (total_wire_format_amount), - TALER_ARL_SET_AB (total_wire_out), - NULL); - } - else - { + qs = TALER_ARL_adb->update_balance ( + TALER_ARL_adb->cls, + TALER_ARL_SET_AB (total_drained), + TALER_ARL_SET_AB (total_wire_out), + TALER_ARL_SET_AB (total_bad_amount_out_plus), + TALER_ARL_SET_AB (total_bad_amount_out_minus), + TALER_ARL_SET_AB (total_amount_lag), + TALER_ARL_SET_AB (total_closure_amount_lag), + TALER_ARL_SET_AB (total_wire_format_amount), + TALER_ARL_SET_AB (total_wire_out), + NULL); + if (qs >= 0) qs = TALER_ARL_adb->insert_balance ( TALER_ARL_adb->cls, TALER_ARL_SET_AB (total_drained), @@ -530,7 +505,6 @@ commit (enum GNUNET_DB_QueryStatus qs) TALER_ARL_SET_AB (total_wire_format_amount), TALER_ARL_SET_AB (total_wire_out), NULL); - } } if (0 > qs) { @@ -548,16 +522,14 @@ commit (enum GNUNET_DB_QueryStatus qs) NULL != wa; wa = wa->next) { - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == wa->qsx && - had_start_progress) - qs = TALER_ARL_adb->update_auditor_progress ( - TALER_ARL_adb->cls, - wa->label_wire_out_serial_id, - wa->last_wire_out_serial_id, - wa->label_wire_off_out, - wa->wire_off_out, - NULL); - else + qs = TALER_ARL_adb->update_auditor_progress ( + TALER_ARL_adb->cls, + wa->label_wire_out_serial_id, + wa->last_wire_out_serial_id, + wa->label_wire_off_out, + wa->wire_off_out, + NULL); + if (0 <= qs) qs = TALER_ARL_adb->insert_auditor_progress ( TALER_ARL_adb->cls, wa->label_wire_out_serial_id, @@ -565,37 +537,39 @@ commit (enum GNUNET_DB_QueryStatus qs) wa->label_wire_off_out, wa->wire_off_out, NULL); - if (0 >= qs) + if (0 > qs) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to update auditor DB, not recording progress\n"); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + TALER_ARL_adb->rollback (TALER_ARL_adb->cls); + TALER_ARL_edb->rollback (TALER_ARL_edb->cls); return; } } GNUNET_CONTAINER_multihashmap_iterate (reserve_closures, &check_pending_rc, NULL); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsx_gwap && had_start_progress == - true) - qs = TALER_ARL_adb->update_auditor_progress ( - TALER_ARL_adb->cls, - TALER_ARL_SET_PP (wire_reserve_close_id), - TALER_ARL_SET_PP (wire_batch_deposit_id), - TALER_ARL_SET_PP (wire_aggregation_id), - NULL); - else + qs = TALER_ARL_adb->update_auditor_progress ( + TALER_ARL_adb->cls, + TALER_ARL_SET_PP (wire_reserve_close_id), + TALER_ARL_SET_PP (wire_batch_deposit_id), + TALER_ARL_SET_PP (wire_aggregation_id), + NULL); + if (0 <= qs) qs = TALER_ARL_adb->insert_auditor_progress ( TALER_ARL_adb->cls, TALER_ARL_SET_PP (wire_reserve_close_id), TALER_ARL_SET_PP (wire_batch_deposit_id), TALER_ARL_SET_PP (wire_aggregation_id), NULL); - if (0 >= qs) + if (0 > qs) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to update auditor DB, not recording progress\n"); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + TALER_ARL_adb->rollback (TALER_ARL_adb->cls); + TALER_ARL_edb->rollback (TALER_ARL_edb->cls); return; } GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -603,35 +577,32 @@ commit (enum GNUNET_DB_QueryStatus qs) (unsigned long long) TALER_ARL_USE_PP (wire_aggregation_id), (unsigned long long) TALER_ARL_USE_PP (wire_batch_deposit_id)); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) - { - qs = TALER_ARL_edb->commit (TALER_ARL_edb->cls); - if (0 > qs) - { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Exchange DB commit failed, rolling back transaction\n"); - TALER_ARL_adb->rollback (TALER_ARL_adb->cls); - } - else - { - qs = TALER_ARL_adb->commit (TALER_ARL_adb->cls); - if (0 > qs) - { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Auditor DB commit failed!\n"); - } - } - } - else + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing failed, rolling back transaction\n"); TALER_ARL_adb->rollback (TALER_ARL_adb->cls); TALER_ARL_edb->rollback (TALER_ARL_edb->cls); + return; + } + + qs = TALER_ARL_edb->commit (TALER_ARL_edb->cls); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Exchange DB commit failed, rolling back transaction\n"); + TALER_ARL_adb->rollback (TALER_ARL_adb->cls); + return; + } + qs = TALER_ARL_adb->commit (TALER_ARL_adb->cls); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Auditor DB commit failed!\n"); + return; } - return; } @@ -1831,10 +1802,7 @@ begin_transaction (void) GNUNET_break (0); return qs; case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - had_start_balance = false; - break; case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: - had_start_balance = true; break; } for (struct WireAccount *wa = wa_head; @@ -1849,42 +1817,38 @@ begin_transaction (void) "wire-%s-%s", wa->ai->section_name, "wire_off_out"); - wa->qsx = TALER_ARL_adb->get_auditor_progress ( + qs = TALER_ARL_adb->get_auditor_progress ( TALER_ARL_adb->cls, wa->label_wire_out_serial_id, &wa->last_wire_out_serial_id, wa->label_wire_off_out, &wa->wire_off_out, NULL); - if (0 > wa->qsx) + if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == wa->qsx); - return GNUNET_DB_STATUS_HARD_ERROR; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } wa->start_wire_out_serial_id = wa->last_wire_out_serial_id; } - qsx_gwap = TALER_ARL_adb->get_auditor_progress ( + qs = TALER_ARL_adb->get_auditor_progress ( TALER_ARL_adb->cls, TALER_ARL_GET_PP (wire_reserve_close_id), TALER_ARL_GET_PP (wire_batch_deposit_id), TALER_ARL_GET_PP (wire_aggregation_id), NULL); - if (0 > qsx_gwap) + if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx_gwap); - return GNUNET_DB_STATUS_HARD_ERROR; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return qs; } - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsx_gwap) + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "First analysis of with wire auditor, starting audit from scratch\n"); } else { - if (TALER_ARL_USE_PP (wire_reserve_close_id) == 0) - had_start_progress = false; - else - had_start_progress = true; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Resuming wire audit at %llu / %llu / %llu\n", (unsigned long long) TALER_ARL_USE_PP (wire_reserve_close_id), @@ -1892,19 +1856,15 @@ begin_transaction (void) (unsigned long long) TALER_ARL_USE_PP (wire_aggregation_id)); } + qs = TALER_ARL_edb->select_reserve_closed_above_serial_id ( + TALER_ARL_edb->cls, + TALER_ARL_USE_PP (wire_reserve_close_id), + &reserve_closed_cb, + NULL); + if (0 > qs) { - enum GNUNET_DB_QueryStatus qs; - - qs = TALER_ARL_edb->select_reserve_closed_above_serial_id ( - TALER_ARL_edb->cls, - TALER_ARL_USE_PP (wire_reserve_close_id), - &reserve_closed_cb, - NULL); - if (0 > qs) - { - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); - return GNUNET_DB_STATUS_HARD_ERROR; - } + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + return GNUNET_DB_STATUS_HARD_ERROR; } begin_debit_audit (); return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; diff --git a/src/exchangedb/pg_select_purse_deposits_above_serial_id.c b/src/exchangedb/pg_select_purse_deposits_above_serial_id.c @@ -88,7 +88,7 @@ purse_deposit_serial_helper_cb (void *cls, &purse_balance), TALER_PQ_RESULT_SPEC_AMOUNT ("total", &purse_total), - TALER_PQ_RESULT_SPEC_AMOUNT ("deposit_fee", + TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", &deposit.deposit_fee), GNUNET_PQ_result_spec_allow_null ( GNUNET_PQ_result_spec_string ("partner_base_url", @@ -176,6 +176,7 @@ TEH_PG_select_purse_deposits_above_serial_id ( ",pd.coin_sig" ",partner_base_url" ",denom.denom_pub" + ",denom.fee_deposit" ",pm.reserve_pub" ",kc.coin_pub" ",kc.age_commitment_hash"