diff options
Diffstat (limited to 'src/auditor/taler-helper-auditor-coins.c')
-rw-r--r-- | src/auditor/taler-helper-auditor-coins.c | 473 |
1 files changed, 282 insertions, 191 deletions
diff --git a/src/auditor/taler-helper-auditor-coins.c b/src/auditor/taler-helper-auditor-coins.c index 7637e463d..f88f39eaf 100644 --- a/src/auditor/taler-helper-auditor-coins.c +++ b/src/auditor/taler-helper-auditor-coins.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 @@ -45,14 +45,37 @@ static int global_ret; /** - * Checkpointing our progress for coins. + * Run in test mode. Exit when idle instead of + * going to sleep and waiting for more work. + * + * FIXME: not yet implemented! */ -static struct TALER_AUDITORDB_ProgressPointCoin ppc; +static int test_mode; /** * Checkpointing our progress for coins. */ -static struct TALER_AUDITORDB_ProgressPointCoin ppc_start; +static TALER_ARL_DEF_PP (coins_withdraw_serial_id); +static TALER_ARL_DEF_PP (coins_deposit_serial_id); +static TALER_ARL_DEF_PP (coins_melt_serial_id); +static TALER_ARL_DEF_PP (coins_refund_serial_id); +static TALER_ARL_DEF_PP (coins_recoup_serial_id); +static TALER_ARL_DEF_PP (coins_recoup_refresh_serial_id); +static TALER_ARL_DEF_PP (coins_purse_deposits_serial_id); +static TALER_ARL_DEF_PP (coins_purse_refunds_serial_id); + + +/** + * Global coin balance sheet (for coins). + */ +static TALER_ARL_DEF_AB (coin_balance_risk); +static TALER_ARL_DEF_AB (total_escrowed); +static TALER_ARL_DEF_AB (coin_irregular_loss); +static TALER_ARL_DEF_AB (coin_melt_fee_revenue); +static TALER_ARL_DEF_AB (coin_deposit_fee_revenue); +static TALER_ARL_DEF_AB (coin_refund_fee_revenue); +static TALER_ARL_DEF_AB (total_recoup_loss); + /** * Array of reports about denomination keys with an @@ -67,7 +90,7 @@ static json_t *report_emergencies; static json_t *report_emergencies_by_count; /** - * Array of reports about row inconsitencies. + * Array of reports about row inconsistencies. */ static json_t *report_row_inconsistencies; @@ -112,10 +135,6 @@ static struct TALER_Amount reported_emergency_loss; */ static struct TALER_Amount reported_emergency_loss_by_count; -/** - * Global coin balance sheet (for coins). - */ -static struct TALER_AUDITORDB_GlobalCoinBalance balance; /** * Array of reports about coin operations with bad signatures. @@ -126,7 +145,7 @@ static json_t *report_bad_sig_losses; * Array of refresh transactions where the /refresh/reveal has not yet * happened (and may of course never happen). */ -static json_t *report_refreshs_hanging; +static json_t *report_refreshes_hanging; /** * Total amount lost by operations for which signatures were invalid. @@ -172,9 +191,9 @@ coin_history_index (const struct TALER_CoinSpendPublicKeyP *coin_pub) { uint32_t i; - memcpy (&i, - coin_pub, - sizeof (i)); + GNUNET_memcpy (&i, + coin_pub, + sizeof (i)); return i % MAX_COIN_HISTORIES; } @@ -435,10 +454,24 @@ check_coin_history (const struct TALER_CoinSpendPublicKeyP *coin_pub, struct TALER_Amount refunded; struct TALER_Amount deposit_fee; bool have_refund; + uint64_t etag_out; - qs = TALER_ARL_edb->get_coin_transactions (TALER_ARL_edb->cls, - coin_pub, - &tl); + /* TODO: could use 'etag' mechanism to only fetch transactions + we did not yet process, instead of going over them + again and again. */ + { + struct TALER_Amount balance; + struct TALER_DenominationHashP h_denom_pub; + + qs = TALER_ARL_edb->get_coin_transactions (TALER_ARL_edb->cls, + coin_pub, + 0, + 0, + &etag_out, + &balance, + &h_denom_pub, + &tl); + } if (0 >= qs) return qs; GNUNET_assert (GNUNET_OK == @@ -784,8 +817,8 @@ sync_denomination (void *cls, /* The denomination expired and carried a balance; we can now book the remaining balance as profit, and reduce our risk exposure by the accumulated risk of the denomination. */ - TALER_ARL_amount_subtract (&balance.risk, - &balance.risk, + TALER_ARL_amount_subtract (&TALER_ARL_USE_AB (coin_balance_risk), + &TALER_ARL_USE_AB (coin_balance_risk), &ds->dcd.denom_risk); /* If the above fails, our risk assessment is inconsistent! This is really, really bad (auditor-internal invariant @@ -804,7 +837,6 @@ sync_denomination (void *cls, if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != (qs = TALER_ARL_adb->insert_historic_denom_revenue ( TALER_ARL_adb->cls, - &TALER_ARL_master_pub, &denom_h, expire_deposit, &ds->dcd.denom_balance, @@ -924,8 +956,9 @@ withdraw_cb (void *cls, (void) execution_date; (void) amount_with_fee; - GNUNET_assert (rowid >= ppc.last_withdraw_serial_id); /* should be monotonically increasing */ - ppc.last_withdraw_serial_id = rowid + 1; + GNUNET_assert (rowid >= + TALER_ARL_USE_PP (coins_withdraw_serial_id)); /* should be monotonically increasing */ + TALER_ARL_USE_PP (coins_withdraw_serial_id) = rowid + 1; qs = TALER_ARL_get_denomination_info (denom_pub, &issue, @@ -963,11 +996,11 @@ withdraw_cb (void *cls, "New balance of denomination `%s' is %s\n", GNUNET_h2s (&dh.hash), TALER_amount2s (&ds->dcd.denom_balance)); - TALER_ARL_amount_add (&balance.total_escrowed, - &balance.total_escrowed, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_escrowed), + &TALER_ARL_USE_AB (total_escrowed), &issue->value); - TALER_ARL_amount_add (&balance.risk, - &balance.risk, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_balance_risk), + &TALER_ARL_USE_AB (coin_balance_risk), &issue->value); ds->dcd.num_issued++; TALER_ARL_amount_add (&ds->dcd.denom_balance, @@ -1128,8 +1161,8 @@ check_known_coin ( loss_potential), GNUNET_JSON_pack_data_auto ("coin_pub", coin_pub))); - TALER_ARL_amount_add (&balance.irregular_loss, - &balance.irregular_loss, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss), + &TALER_ARL_USE_AB (coin_irregular_loss), loss_potential); } TALER_denom_sig_free (&ci.denom_sig); @@ -1140,7 +1173,7 @@ check_known_coin ( /** * Update the denom balance in @a dso reducing it by * @a amount_with_fee. If this is not possible, report - * an emergency. Also updates the #balance. + * an emergency. Also updates the balance. * * @param dso denomination summary to update * @param rowid responsible row (for logging) @@ -1167,7 +1200,7 @@ reduce_denom_balance (struct DenominationSummary *dso, { dso->dcd.denom_balance = tmp; } - if (-1 == TALER_amount_cmp (&balance.total_escrowed, + if (-1 == TALER_amount_cmp (&TALER_ARL_USE_AB (total_escrowed), amount_with_fee)) { /* This can theoretically happen if for example the exchange @@ -1179,14 +1212,14 @@ reduce_denom_balance (struct DenominationSummary *dso, report_amount_arithmetic_inconsistency ( "subtracting amount from escrow balance", rowid, - &balance.total_escrowed, + &TALER_ARL_USE_AB (total_escrowed), amount_with_fee, 0); } else { - TALER_ARL_amount_subtract (&balance.total_escrowed, - &balance.total_escrowed, + TALER_ARL_amount_subtract (&TALER_ARL_USE_AB (total_escrowed), + &TALER_ARL_USE_AB (total_escrowed), amount_with_fee); } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -1232,8 +1265,9 @@ refresh_session_cb (void *cls, enum GNUNET_DB_QueryStatus qs; (void) noreveal_index; - GNUNET_assert (rowid >= ppc.last_melt_serial_id); /* should be monotonically increasing */ - ppc.last_melt_serial_id = rowid + 1; + GNUNET_assert (rowid >= + TALER_ARL_USE_PP (coins_melt_serial_id)); /* should be monotonically increasing */ + TALER_ARL_USE_PP (coins_melt_serial_id) = rowid + 1; qs = TALER_ARL_get_denomination_info (denom_pub, &issue, @@ -1292,8 +1326,8 @@ refresh_session_cb (void *cls, amount_with_fee), GNUNET_JSON_pack_data_auto ("coin_pub", coin_pub))); - TALER_ARL_amount_add (&balance.irregular_loss, - &balance.irregular_loss, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss), + &TALER_ARL_USE_AB (coin_irregular_loss), amount_with_fee); } } @@ -1326,7 +1360,7 @@ refresh_session_cb (void *cls, /* This can legitimately happen if reveal was not yet called or only with invalid data, even if the exchange is correctly operating. We still report it. */ - TALER_ARL_report (report_refreshs_hanging, + TALER_ARL_report (report_refreshes_hanging, GNUNET_JSON_PACK ( GNUNET_JSON_pack_uint64 ("row", rowid), @@ -1439,11 +1473,11 @@ refresh_session_cb (void *cls, "New balance of denomination `%s' is %s\n", GNUNET_h2s (&ni->denom_hash.hash), TALER_amount2s (&dsi->dcd.denom_balance)); - TALER_ARL_amount_add (&balance.total_escrowed, - &balance.total_escrowed, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_escrowed), + &TALER_ARL_USE_AB (total_escrowed), &ni->value); - TALER_ARL_amount_add (&balance.risk, - &balance.risk, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_balance_risk), + &TALER_ARL_USE_AB (coin_balance_risk), &ni->value); } } @@ -1468,8 +1502,8 @@ refresh_session_cb (void *cls, } /* update global melt fees */ - TALER_ARL_amount_add (&balance.melt_fee_balance, - &balance.melt_fee_balance, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_melt_fee_revenue), + &TALER_ARL_USE_AB (coin_melt_fee_revenue), &issue->fees.refresh); if (TALER_ARL_do_abort ()) return GNUNET_SYSERR; @@ -1504,8 +1538,9 @@ deposit_cb (void *cls, (void) done; (void) exchange_timestamp; - GNUNET_assert (rowid >= ppc.last_deposit_serial_id); /* should be monotonically increasing */ - ppc.last_deposit_serial_id = rowid + 1; + GNUNET_assert (rowid >= + TALER_ARL_USE_PP (coins_deposit_serial_id)); /* should be monotonically increasing */ + TALER_ARL_USE_PP (coins_deposit_serial_id) = rowid + 1; qs = TALER_ARL_get_denomination_info (denom_pub, &issue, @@ -1565,6 +1600,9 @@ deposit_cb (void *cls, &issue->fees.deposit, &h_wire, &deposit->h_contract_terms, + deposit->no_wallet_data_hash + ? NULL + : &deposit->wallet_data_hash, &deposit->coin.h_age_commitment, &deposit->h_policy, &h_denom_pub, @@ -1584,8 +1622,8 @@ deposit_cb (void *cls, &deposit->amount_with_fee), GNUNET_JSON_pack_data_auto ("coin_pub", &deposit->coin.coin_pub))); - TALER_ARL_amount_add (&balance.irregular_loss, - &balance.irregular_loss, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss), + &TALER_ARL_USE_AB (coin_irregular_loss), &deposit->amount_with_fee); if (TALER_ARL_do_abort ()) return GNUNET_SYSERR; @@ -1616,8 +1654,8 @@ deposit_cb (void *cls, } /* update global deposit fees */ - TALER_ARL_amount_add (&balance.deposit_fee_balance, - &balance.deposit_fee_balance, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_deposit_fee_revenue), + &TALER_ARL_USE_AB (coin_deposit_fee_revenue), &issue->fees.deposit); if (TALER_ARL_do_abort ()) return GNUNET_SYSERR; @@ -1661,8 +1699,8 @@ refund_cb (void *cls, struct TALER_Amount amount_without_fee; enum GNUNET_DB_QueryStatus qs; - GNUNET_assert (rowid >= ppc.last_refund_serial_id); /* should be monotonically increasing */ - ppc.last_refund_serial_id = rowid + 1; + GNUNET_assert (rowid >= TALER_ARL_USE_PP (coins_refund_serial_id)); /* should be monotonically increasing */ + TALER_ARL_USE_PP (coins_refund_serial_id) = rowid + 1; qs = TALER_ARL_get_denomination_info (denom_pub, &issue, @@ -1701,8 +1739,8 @@ refund_cb (void *cls, amount_with_fee), GNUNET_JSON_pack_data_auto ("coin_pub", coin_pub))); - TALER_ARL_amount_add (&balance.irregular_loss, - &balance.irregular_loss, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss), + &TALER_ARL_USE_AB (coin_irregular_loss), amount_with_fee); if (TALER_ARL_do_abort ()) return GNUNET_SYSERR; @@ -1748,11 +1786,11 @@ refund_cb (void *cls, TALER_ARL_amount_add (&ds->dcd.denom_risk, &ds->dcd.denom_risk, &amount_without_fee); - TALER_ARL_amount_add (&balance.total_escrowed, - &balance.total_escrowed, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_escrowed), + &TALER_ARL_USE_AB (total_escrowed), &amount_without_fee); - TALER_ARL_amount_add (&balance.risk, - &balance.risk, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_balance_risk), + &TALER_ARL_USE_AB (coin_balance_risk), &amount_without_fee); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New balance of denomination `%s' after refund is %s\n", @@ -1760,13 +1798,13 @@ refund_cb (void *cls, TALER_amount2s (&ds->dcd.denom_balance)); } /* update total refund fee balance */ - TALER_ARL_amount_add (&balance.refund_fee_balance, - &balance.refund_fee_balance, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_refund_fee_revenue), + &TALER_ARL_USE_AB (coin_refund_fee_revenue), &issue->fees.refund); if (full_refund) { - TALER_ARL_amount_subtract (&balance.deposit_fee_balance, - &balance.deposit_fee_balance, + TALER_ARL_amount_subtract (&TALER_ARL_USE_AB (coin_deposit_fee_revenue), + &TALER_ARL_USE_AB (coin_deposit_fee_revenue), &issue->fees.deposit); } if (TALER_ARL_do_abort ()) @@ -1840,11 +1878,11 @@ purse_refund_coin_cb ( TALER_ARL_amount_add (&ds->dcd.denom_risk, &ds->dcd.denom_risk, amount_with_fee); - TALER_ARL_amount_add (&balance.total_escrowed, - &balance.total_escrowed, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_escrowed), + &TALER_ARL_USE_AB (total_escrowed), amount_with_fee); - TALER_ARL_amount_add (&balance.risk, - &balance.risk, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_balance_risk), + &TALER_ARL_USE_AB (coin_balance_risk), amount_with_fee); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New balance of denomination `%s' after purse-refund is %s\n", @@ -1852,8 +1890,8 @@ purse_refund_coin_cb ( TALER_amount2s (&ds->dcd.denom_balance)); } /* update total deposit fee balance */ - TALER_ARL_amount_subtract (&balance.deposit_fee_balance, - &balance.deposit_fee_balance, + TALER_ARL_amount_subtract (&TALER_ARL_USE_AB (coin_deposit_fee_revenue), + &TALER_ARL_USE_AB (coin_deposit_fee_revenue), &issue->fees.deposit); return GNUNET_OK; @@ -1884,8 +1922,9 @@ purse_refund_cb (void *cls, (void) val; /* irrelevant on refund */ (void) reserve_pub; /* irrelevant, may even be NULL */ - GNUNET_assert (rowid >= ppc.last_purse_refunds_serial_id); /* should be monotonically increasing */ - ppc.last_purse_refunds_serial_id = rowid + 1; + GNUNET_assert (rowid >= + TALER_ARL_USE_PP (coins_purse_refunds_serial_id)); /* should be monotonically increasing */ + TALER_ARL_USE_PP (coins_purse_refunds_serial_id) = rowid + 1; qs = TALER_ARL_edb->select_purse_deposits_by_purse (TALER_ARL_edb->cls, purse_pub, &purse_refund_coin_cb, @@ -1923,7 +1962,7 @@ check_recoup (struct CoinContext *cc, const struct TALER_CoinPublicInfo *coin, const struct TALER_DenominationPublicKey *denom_pub, const struct TALER_CoinSpendSignatureP *coin_sig, - const union TALER_DenominationBlindingKeyP *coin_blind) + const union GNUNET_CRYPTO_BlindingSecretP *coin_blind) { struct DenominationSummary *ds; enum GNUNET_DB_QueryStatus qs; @@ -1953,8 +1992,8 @@ check_recoup (struct CoinContext *cc, amount), GNUNET_JSON_pack_data_auto ("coin_pub", &coin->denom_pub_hash))); - TALER_ARL_amount_add (&balance.irregular_loss, - &balance.irregular_loss, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss), + &TALER_ARL_USE_AB (coin_irregular_loss), amount); } qs = TALER_ARL_get_denomination_info_by_hash (&coin->denom_pub_hash, @@ -2014,15 +2053,15 @@ check_recoup (struct CoinContext *cc, amount), GNUNET_JSON_pack_data_auto ("coin_pub", &coin->coin_pub))); - TALER_ARL_amount_add (&balance.irregular_loss, - &balance.irregular_loss, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss), + &TALER_ARL_USE_AB (coin_irregular_loss), amount); } TALER_ARL_amount_add (&ds->dcd.recoup_loss, &ds->dcd.recoup_loss, amount); - TALER_ARL_amount_add (&balance.loss, - &balance.loss, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_recoup_loss), + &TALER_ARL_USE_AB (total_recoup_loss), amount); } if (TALER_ARL_do_abort ()) @@ -2054,12 +2093,12 @@ recoup_cb (void *cls, const struct TALER_CoinPublicInfo *coin, const struct TALER_DenominationPublicKey *denom_pub, const struct TALER_CoinSpendSignatureP *coin_sig, - const union TALER_DenominationBlindingKeyP *coin_blind) + const union GNUNET_CRYPTO_BlindingSecretP *coin_blind) { struct CoinContext *cc = cls; - GNUNET_assert (rowid >= ppc.last_recoup_serial_id); /* should be monotonically increasing */ - ppc.last_recoup_serial_id = rowid + 1; + GNUNET_assert (rowid >= TALER_ARL_USE_PP (coins_recoup_serial_id)); /* should be monotonically increasing */ + TALER_ARL_USE_PP (coins_recoup_serial_id) = rowid + 1; (void) timestamp; (void) reserve_pub; if (GNUNET_OK != @@ -2078,8 +2117,8 @@ recoup_cb (void *cls, amount), GNUNET_JSON_pack_data_auto ("coin_pub", &coin->coin_pub))); - TALER_ARL_amount_add (&balance.irregular_loss, - &balance.irregular_loss, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss), + &TALER_ARL_USE_AB (coin_irregular_loss), amount); if (TALER_ARL_do_abort ()) return GNUNET_SYSERR; @@ -2122,7 +2161,7 @@ recoup_refresh_cb (void *cls, const struct TALER_CoinPublicInfo *coin, const struct TALER_DenominationPublicKey *denom_pub, const struct TALER_CoinSpendSignatureP *coin_sig, - const union TALER_DenominationBlindingKeyP *coin_blind) + const union GNUNET_CRYPTO_BlindingSecretP *coin_blind) { struct CoinContext *cc = cls; const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue; @@ -2130,8 +2169,8 @@ recoup_refresh_cb (void *cls, (void) timestamp; (void) old_coin_pub; - GNUNET_assert (rowid >= ppc.last_recoup_refresh_serial_id); /* should be monotonically increasing */ - ppc.last_recoup_refresh_serial_id = rowid + 1; + GNUNET_assert (rowid >= TALER_ARL_USE_PP (coins_recoup_refresh_serial_id)); /* should be monotonically increasing */ + TALER_ARL_USE_PP (coins_recoup_refresh_serial_id) = rowid + 1; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recoup-refresh amount is %s\n", TALER_amount2s (amount)); @@ -2192,8 +2231,8 @@ recoup_refresh_cb (void *cls, amount), GNUNET_JSON_pack_data_auto ("coin_pub", &coin->coin_pub))); - TALER_ARL_amount_add (&balance.irregular_loss, - &balance.irregular_loss, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss), + &TALER_ARL_USE_AB (coin_irregular_loss), amount); if (TALER_ARL_do_abort ()) return GNUNET_SYSERR; @@ -2316,8 +2355,9 @@ purse_deposit_cb ( (void) auditor_balance; (void) purse_total; (void) reserve_pub; - GNUNET_assert (rowid >= ppc.last_purse_deposits_serial_id); - ppc.last_purse_deposits_serial_id = rowid + 1; + GNUNET_assert (rowid >= + TALER_ARL_USE_PP (coins_purse_deposits_serial_id)); + TALER_ARL_USE_PP (coins_purse_deposits_serial_id) = rowid + 1; qs = TALER_ARL_get_denomination_info (denom_pub, &issue, &dh); @@ -2365,8 +2405,8 @@ purse_deposit_cb ( &deposit->amount), GNUNET_JSON_pack_data_auto ("coin_pub", &deposit->coin_pub))); - TALER_ARL_amount_add (&balance.irregular_loss, - &balance.irregular_loss, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss), + &TALER_ARL_USE_AB (coin_irregular_loss), &deposit->amount); if (TALER_ARL_do_abort ()) return GNUNET_SYSERR; @@ -2391,8 +2431,8 @@ purse_deposit_cb ( } /* update global deposit fees */ - TALER_ARL_amount_add (&balance.deposit_fee_balance, - &balance.deposit_fee_balance, + TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_deposit_fee_revenue), + &TALER_ARL_USE_AB (coin_deposit_fee_revenue), &issue->fees.deposit); if (TALER_ARL_do_abort ()) return GNUNET_SYSERR; @@ -2427,9 +2467,17 @@ analyze_coins (void *cls) } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Analyzing coins\n"); - qsp = TALER_ARL_adb->get_auditor_progress_coin (TALER_ARL_adb->cls, - &TALER_ARL_master_pub, - &ppc); + qsp = 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), + TALER_ARL_GET_PP (coins_melt_serial_id), + TALER_ARL_GET_PP (coins_refund_serial_id), + TALER_ARL_GET_PP (coins_recoup_serial_id), + TALER_ARL_GET_PP (coins_recoup_refresh_serial_id), + TALER_ARL_GET_PP (coins_purse_deposits_serial_id), + TALER_ARL_GET_PP (coins_purse_refunds_serial_id), + NULL); if (0 > qsp) { GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsp); @@ -2442,26 +2490,39 @@ analyze_coins (void *cls) } else { - ppc_start = ppc; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Resuming coin audit at %llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu\n", - (unsigned long long) ppc.last_deposit_serial_id, - (unsigned long long) ppc.last_melt_serial_id, - (unsigned long long) ppc.last_refund_serial_id, - (unsigned long long) ppc.last_withdraw_serial_id, - (unsigned long long) ppc.last_recoup_refresh_serial_id, - (unsigned long long) ppc.last_open_deposits_serial_id, - (unsigned long long) ppc.last_purse_deposits_serial_id, - (unsigned long long) ppc.last_purse_refunds_serial_id); + GNUNET_log ( + GNUNET_ERROR_TYPE_INFO, + "Resuming coin audit at %llu/%llu/%llu/%llu/%llu/%llu/%llu\n", + (unsigned long long) TALER_ARL_USE_PP ( + coins_deposit_serial_id), + (unsigned long long) TALER_ARL_USE_PP ( + coins_melt_serial_id), + (unsigned long long) TALER_ARL_USE_PP ( + coins_refund_serial_id), + (unsigned long long) TALER_ARL_USE_PP ( + coins_withdraw_serial_id), + (unsigned long long) TALER_ARL_USE_PP ( + coins_recoup_refresh_serial_id), + (unsigned long long) TALER_ARL_USE_PP ( + coins_purse_deposits_serial_id), + (unsigned long long) TALER_ARL_USE_PP ( + coins_purse_refunds_serial_id)); } /* setup 'cc' */ cc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; cc.denom_summaries = GNUNET_CONTAINER_multihashmap_create (256, GNUNET_NO); - qsx = TALER_ARL_adb->get_balance_summary (TALER_ARL_adb->cls, - &TALER_ARL_master_pub, - &balance); + qsx = TALER_ARL_adb->get_balance ( + TALER_ARL_adb->cls, + TALER_ARL_GET_AB (coin_balance_risk), + TALER_ARL_GET_AB (total_escrowed), + TALER_ARL_GET_AB (coin_irregular_loss), + TALER_ARL_GET_AB (coin_melt_fee_revenue), + TALER_ARL_GET_AB (coin_deposit_fee_revenue), + TALER_ARL_GET_AB (coin_refund_fee_revenue), + TALER_ARL_GET_AB (total_recoup_loss), + NULL); if (0 > qsx) { GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx); @@ -2472,7 +2533,7 @@ analyze_coins (void *cls) if (0 > (qs = TALER_ARL_edb->select_withdrawals_above_serial_id ( TALER_ARL_edb->cls, - ppc.last_withdraw_serial_id, + TALER_ARL_USE_PP (coins_withdraw_serial_id), &withdraw_cb, &cc)) ) { @@ -2486,7 +2547,7 @@ analyze_coins (void *cls) if (0 > (qs = TALER_ARL_edb->select_refunds_above_serial_id ( TALER_ARL_edb->cls, - ppc.last_refund_serial_id, + TALER_ARL_USE_PP (coins_refund_serial_id), &refund_cb, &cc))) { @@ -2500,7 +2561,7 @@ analyze_coins (void *cls) if (0 > (qs = TALER_ARL_edb->select_purse_decisions_above_serial_id ( TALER_ARL_edb->cls, - ppc.last_purse_refunds_serial_id, + TALER_ARL_USE_PP (coins_purse_refunds_serial_id), true, /* only go for refunds! */ &purse_refund_cb, &cc))) @@ -2515,7 +2576,7 @@ analyze_coins (void *cls) if (0 > (qs = TALER_ARL_edb->select_recoup_refresh_above_serial_id ( TALER_ARL_edb->cls, - ppc.last_recoup_refresh_serial_id, + TALER_ARL_USE_PP (coins_recoup_refresh_serial_id), &recoup_refresh_cb, &cc))) { @@ -2527,7 +2588,7 @@ analyze_coins (void *cls) if (0 > (qs = TALER_ARL_edb->select_recoup_above_serial_id ( TALER_ARL_edb->cls, - ppc.last_recoup_serial_id, + TALER_ARL_USE_PP (coins_recoup_serial_id), &recoup_cb, &cc))) { @@ -2537,11 +2598,11 @@ analyze_coins (void *cls) if (0 > cc.qs) return cc.qs; - /* process refreshs */ + /* process refreshes */ if (0 > (qs = TALER_ARL_edb->select_refreshes_above_serial_id ( TALER_ARL_edb->cls, - ppc.last_melt_serial_id, + TALER_ARL_USE_PP (coins_melt_serial_id), &refresh_session_cb, &cc))) { @@ -2553,9 +2614,9 @@ analyze_coins (void *cls) /* process deposits */ if (0 > - (qs = TALER_ARL_edb->select_deposits_above_serial_id ( + (qs = TALER_ARL_edb->select_coin_deposits_above_serial_id ( TALER_ARL_edb->cls, - ppc.last_deposit_serial_id, + TALER_ARL_USE_PP (coins_deposit_serial_id), &deposit_cb, &cc))) { @@ -2569,7 +2630,7 @@ analyze_coins (void *cls) if (0 > (qs = TALER_ARL_edb->select_purse_deposits_above_serial_id ( TALER_ARL_edb->cls, - ppc.last_purse_deposits_serial_id, + TALER_ARL_USE_PP (coins_purse_deposits_serial_id), &purse_deposit_cb, &cc))) { @@ -2591,13 +2652,27 @@ analyze_coins (void *cls) return cc.qs; } if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsx) - qs = TALER_ARL_adb->update_balance_summary (TALER_ARL_adb->cls, - &TALER_ARL_master_pub, - &balance); + 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), + NULL); else - qs = TALER_ARL_adb->insert_balance_summary (TALER_ARL_adb->cls, - &TALER_ARL_master_pub, - &balance); + 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), + NULL); if (0 >= qs) { GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); @@ -2605,13 +2680,29 @@ analyze_coins (void *cls) } if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp) - qs = TALER_ARL_adb->update_auditor_progress_coin (TALER_ARL_adb->cls, - &TALER_ARL_master_pub, - &ppc); + 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); else - qs = TALER_ARL_adb->insert_auditor_progress_coin (TALER_ARL_adb->cls, - &TALER_ARL_master_pub, - &ppc); + 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) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -2620,15 +2711,17 @@ analyze_coins (void *cls) return qs; } GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Concluded coin audit step at %llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu\n", - (unsigned long long) ppc.last_deposit_serial_id, - (unsigned long long) ppc.last_melt_serial_id, - (unsigned long long) ppc.last_refund_serial_id, - (unsigned long long) ppc.last_withdraw_serial_id, - (unsigned long long) ppc.last_recoup_refresh_serial_id, - (unsigned long long) ppc.last_open_deposits_serial_id, - (unsigned long long) ppc.last_purse_deposits_serial_id, - (unsigned long long) ppc.last_purse_refunds_serial_id); + "Concluded coin audit step at %llu/%llu/%llu/%llu/%llu/%llu/%llu\n", + (unsigned long long) TALER_ARL_USE_PP (coins_deposit_serial_id), + (unsigned long long) TALER_ARL_USE_PP (coins_melt_serial_id), + (unsigned long long) TALER_ARL_USE_PP (coins_refund_serial_id), + (unsigned long long) TALER_ARL_USE_PP (coins_withdraw_serial_id), + (unsigned long long) TALER_ARL_USE_PP ( + coins_recoup_refresh_serial_id), + (unsigned long long) TALER_ARL_USE_PP ( + coins_purse_deposits_serial_id), + (unsigned long long) TALER_ARL_USE_PP ( + coins_purse_refunds_serial_id)); return qs; } @@ -2674,31 +2767,29 @@ run (void *cls, &reported_emergency_loss_by_count)); GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (TALER_ARL_currency, - &balance.total_escrowed)); - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero (TALER_ARL_currency, - &balance.deposit_fee_balance)); - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero (TALER_ARL_currency, - &balance.melt_fee_balance)); + &TALER_ARL_USE_AB (total_escrowed))); GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (TALER_ARL_currency, - &balance.refund_fee_balance)); + &TALER_ARL_USE_AB ( + coin_deposit_fee_revenue))); GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (TALER_ARL_currency, - &balance.purse_fee_balance)); + &TALER_ARL_USE_AB ( + coin_melt_fee_revenue))); GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (TALER_ARL_currency, - &balance.open_deposit_fee_balance)); + &TALER_ARL_USE_AB ( + coin_refund_fee_revenue))); GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (TALER_ARL_currency, - &balance.risk)); + &TALER_ARL_USE_AB (coin_balance_risk))); GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (TALER_ARL_currency, - &balance.loss)); + &TALER_ARL_USE_AB (total_recoup_loss))); GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (TALER_ARL_currency, - &balance.irregular_loss)); + &TALER_ARL_USE_AB ( + coin_irregular_loss))); GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (TALER_ARL_currency, &total_arithmetic_delta_plus)); @@ -2722,7 +2813,7 @@ run (void *cls, GNUNET_assert (NULL != (report_bad_sig_losses = json_array ())); GNUNET_assert (NULL != - (report_refreshs_hanging = json_array ())); + (report_refreshes_hanging = json_array ())); if (GNUNET_OK != TALER_ARL_setup_sessions_and_run (&analyze_coins, NULL)) @@ -2735,24 +2826,20 @@ run (void *cls, TALER_ARL_done ( GNUNET_JSON_PACK ( TALER_JSON_pack_amount ("total_escrow_balance", - &balance.total_escrowed), + &TALER_ARL_USE_AB (total_escrowed)), TALER_JSON_pack_amount ("total_deposit_fee_income", - &balance.deposit_fee_balance), + &TALER_ARL_USE_AB (coin_deposit_fee_revenue)), TALER_JSON_pack_amount ("total_melt_fee_income", - &balance.melt_fee_balance), + &TALER_ARL_USE_AB (coin_melt_fee_revenue)), TALER_JSON_pack_amount ("total_refund_fee_income", - &balance.refund_fee_balance), - TALER_JSON_pack_amount ("total_purse_fee_income", - &balance.purse_fee_balance), - TALER_JSON_pack_amount ("total_open_deposit_fee_income", - &balance.open_deposit_fee_balance), + &TALER_ARL_USE_AB (coin_refund_fee_revenue)), TALER_JSON_pack_amount ("total_active_risk", - &balance.risk), + &TALER_ARL_USE_AB (coin_balance_risk)), TALER_JSON_pack_amount ("total_recoup_loss", - &balance.loss), + &TALER_ARL_USE_AB (total_recoup_loss)), /* Tested in test-auditor.sh #4/#5/#6/#13/#26 */ TALER_JSON_pack_amount ("irregular_loss", - &balance.irregular_loss), + &TALER_ARL_USE_AB (coin_irregular_loss)), /* Tested in test-auditor.sh #18 */ GNUNET_JSON_pack_array_steal ("emergencies", report_emergencies), @@ -2775,7 +2862,7 @@ run (void *cls, report_bad_sig_losses), /* Tested in test-auditor.sh #12 */ GNUNET_JSON_pack_array_steal ("refresh_hanging", - report_refreshs_hanging), + report_refreshes_hanging), /* Tested in test-auditor.sh #18 */ GNUNET_JSON_pack_array_steal ("emergencies_by_count", report_emergencies_by_count), @@ -2789,43 +2876,48 @@ run (void *cls, TALER_JSON_pack_amount ("emergencies_loss_by_count", &reported_emergency_loss_by_count), GNUNET_JSON_pack_uint64 ("start_ppc_withdraw_serial_id", - ppc_start.last_withdraw_serial_id), + 0 /* not implemented */), GNUNET_JSON_pack_uint64 ("start_ppc_deposit_serial_id", - ppc_start.last_deposit_serial_id), + 0 /* not implemented */), GNUNET_JSON_pack_uint64 ("start_ppc_melt_serial_id", - ppc_start.last_melt_serial_id), + 0 /* not implemented */), GNUNET_JSON_pack_uint64 ("start_ppc_refund_serial_id", - ppc_start.last_refund_serial_id), + 0 /* not implemented */), GNUNET_JSON_pack_uint64 ("start_ppc_recoup_serial_id", - ppc_start.last_recoup_serial_id), + 0 /* not implemented */), GNUNET_JSON_pack_uint64 ("start_ppc_recoup_refresh_serial_id", - ppc_start.last_recoup_refresh_serial_id), + 0 /* not implemented */), GNUNET_JSON_pack_uint64 ("start_ppc_purse_deposits_serial_id", - ppc_start.last_purse_deposits_serial_id), + 0 /* not implemented */), GNUNET_JSON_pack_uint64 ("start_ppc_purse_refunds_serial_id", - ppc_start.last_purse_refunds_serial_id), + 0 /* not implemented */), GNUNET_JSON_pack_uint64 ("end_ppc_withdraw_serial_id", - ppc.last_withdraw_serial_id), + TALER_ARL_USE_PP (coins_withdraw_serial_id)), GNUNET_JSON_pack_uint64 ("end_ppc_deposit_serial_id", - ppc.last_deposit_serial_id), + TALER_ARL_USE_PP (coins_deposit_serial_id)), GNUNET_JSON_pack_uint64 ("end_ppc_melt_serial_id", - ppc.last_melt_serial_id), + TALER_ARL_USE_PP (coins_melt_serial_id)), GNUNET_JSON_pack_uint64 ("end_ppc_refund_serial_id", - ppc.last_refund_serial_id), + TALER_ARL_USE_PP (coins_refund_serial_id)), GNUNET_JSON_pack_uint64 ("end_ppc_recoup_serial_id", - ppc.last_recoup_serial_id), + TALER_ARL_USE_PP (coins_recoup_serial_id)), GNUNET_JSON_pack_uint64 ("end_ppc_recoup_refresh_serial_id", - ppc.last_recoup_refresh_serial_id), + TALER_ARL_USE_PP ( + coins_recoup_refresh_serial_id)), GNUNET_JSON_pack_uint64 ("end_ppc_purse_deposits_serial_id", - ppc.last_purse_deposits_serial_id), + TALER_ARL_USE_PP ( + coins_purse_deposits_serial_id)), GNUNET_JSON_pack_uint64 ("end_ppc_purse_refunds_serial_id", - ppc.last_purse_refunds_serial_id), - TALER_JSON_pack_time_abs_human ("auditor_start_time", - start_time), + TALER_ARL_USE_PP ( + coins_purse_refunds_serial_id)), + TALER_JSON_pack_time_abs_human ( + "auditor_start_time", + start_time), TALER_JSON_pack_time_abs_human ("auditor_end_time", GNUNET_TIME_absolute_get ()), - GNUNET_JSON_pack_array_steal ("unsigned_denominations", - report_denominations_without_sigs))); + GNUNET_JSON_pack_array_steal ( + "unsigned_denominations", + report_denominations_without_sigs))); } @@ -2845,11 +2937,10 @@ main (int argc, "internal", "perform checks only applicable for exchange-internal audits", &internal_checks), - GNUNET_GETOPT_option_base32_auto ('m', - "exchange-key", - "KEY", - "public key of the exchange (Crockford base32 encoded)", - &TALER_ARL_master_pub), + GNUNET_GETOPT_option_flag ('t', + "test", + "run in test mode and exit when idle", + &test_mode), GNUNET_GETOPT_option_timetravel ('T', "timetravel"), GNUNET_GETOPT_OPTION_END |