From f3ceeb00ea81833433a781bc412bb539c453cd24 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 8 Jun 2022 17:05:51 +0200 Subject: -expand auditordb to track progress for p2p payments --- src/auditor/taler-helper-auditor-coins.c | 31 +++++++++++-------- src/auditordb/auditor-0001.sql | 5 +++ src/auditordb/plugin_auditordb_postgres.c | 51 ++++++++++++++++++++++++++----- src/include/taler_auditordb_plugin.h | 31 ++++++++++++++++++- 4 files changed, 96 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/auditor/taler-helper-auditor-coins.c b/src/auditor/taler-helper-auditor-coins.c index ad9048a17..c75899571 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-2021 Taler Systems SA + Copyright (C) 2016-2022 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 @@ -471,11 +471,11 @@ check_coin_history (const struct TALER_CoinSpendPublicKeyP *coin_pub, struct TALER_Amount spent; struct TALER_Amount refunded; struct TALER_Amount deposit_fee; - int have_refund; + bool have_refund; qs = TALER_ARL_edb->get_coin_transactions (TALER_ARL_edb->cls, coin_pub, - GNUNET_YES, + true, &tl); if (0 >= qs) return qs; @@ -489,7 +489,7 @@ check_coin_history (const struct TALER_CoinSpendPublicKeyP *coin_pub, GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (value->currency, &deposit_fee)); - have_refund = GNUNET_NO; + have_refund = false; for (struct TALER_EXCHANGEDB_TransactionList *pos = tl; NULL != pos; pos = pos->next) @@ -517,7 +517,7 @@ check_coin_history (const struct TALER_CoinSpendPublicKeyP *coin_pub, TALER_ARL_amount_add (&spent, &spent, &pos->details.refund->refund_fee); - have_refund = GNUNET_YES; + have_refund = true; break; case TALER_EXCHANGEDB_TT_OLD_COIN_RECOUP: /* refunded += pos->value */ @@ -537,6 +537,11 @@ check_coin_history (const struct TALER_CoinSpendPublicKeyP *coin_pub, &spent, &pos->details.recoup_refresh->value); break; + case TALER_EXCHANGEDB_TT_PURSE_DEPOSIT: + TALER_ARL_amount_add (&spent, + &spent, + &pos->details.purse_deposit->amount); + break; } } @@ -754,10 +759,10 @@ init_denomination (const struct TALER_DenominationHashP *denom_hash, * @return NULL on error */ static struct DenominationSummary * -get_denomination_summary (struct CoinContext *cc, - const struct - TALER_EXCHANGEDB_DenominationKeyInformation *issue, - const struct TALER_DenominationHashP *dh) +get_denomination_summary ( + struct CoinContext *cc, + const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue, + const struct TALER_DenominationHashP *dh) { struct DenominationSummary *ds; @@ -839,7 +844,7 @@ sync_denomination (void *cls, This is really, really bad (auditor-internal invariant would be violated). Hence we can "safely" assert. If this assertion fails, well, good luck: there is a bug - in the auditor _or_ the auditor's database is corrupt. */// + in the auditor _or_ the auditor's database is corrupt. */ } if ( (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) && ( (0 != ds->denom_balance.value) || @@ -1211,7 +1216,7 @@ check_known_coin (const char *operation, * @param rc what is the refresh commitment * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop */ -static int +static enum GNUNET_GenericReturnValue refresh_session_cb (void *cls, uint64_t rowid, const struct TALER_DenominationPublicKey *denom_pub, @@ -1480,7 +1485,7 @@ refresh_session_cb (void *cls, accepted a forged coin (i.e. emergency situation after private key compromise). In that case, we cannot even subtract the profit we make from the fee from the escrow - balance. Tested as part of test-auditor.sh, case #18 */// + balance. Tested as part of test-auditor.sh, case #18 */ report_amount_arithmetic_inconsistency ( "subtracting refresh fee from escrow balance", rowid, @@ -1668,7 +1673,7 @@ deposit_cb (void *cls, accepted a forged coin (i.e. emergency situation after private key compromise). In that case, we cannot even subtract the profit we make from the fee from the escrow - balance. Tested as part of test-auditor.sh, case #18 */// + balance. Tested as part of test-auditor.sh, case #18 */ report_amount_arithmetic_inconsistency ( "subtracting deposit fee from escrow balance", rowid, diff --git a/src/auditordb/auditor-0001.sql b/src/auditordb/auditor-0001.sql index 0faa890d7..ae22ff34d 100644 --- a/src/auditordb/auditor-0001.sql +++ b/src/auditordb/auditor-0001.sql @@ -47,6 +47,10 @@ CREATE TABLE IF NOT EXISTS auditor_progress_reserve ,last_reserve_out_serial_id INT8 NOT NULL DEFAULT 0 ,last_reserve_recoup_serial_id INT8 NOT NULL DEFAULT 0 ,last_reserve_close_serial_id INT8 NOT NULL DEFAULT 0 + ,last_purse_merges_serial_id INT8 NOT NULL DEFAULT 0 + ,last_account_merges_serial_id INT8 NOT NULL DEFAULT 0 + ,last_history_requests_serial_id INT8 NOT NULL DEFAULT 0 + ,last_close_requests_serial_id INT8 NOT NULL DEFAULT 0 ,PRIMARY KEY (master_pub) ); COMMENT ON TABLE auditor_progress_reserve @@ -82,6 +86,7 @@ CREATE TABLE IF NOT EXISTS auditor_progress_coin ,last_refund_serial_id INT8 NOT NULL DEFAULT 0 ,last_recoup_serial_id INT8 NOT NULL DEFAULT 0 ,last_recoup_refresh_serial_id INT8 NOT NULL DEFAULT 0 + ,last_purse_deposits_serial_id INT8 NOT NULL DEFAULT 0 ,PRIMARY KEY (master_pub) ); COMMENT ON TABLE auditor_progress_coin diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c index 6cee2b23a..26560465a 100644 --- a/src/auditordb/plugin_auditordb_postgres.c +++ b/src/auditordb/plugin_auditordb_postgres.c @@ -230,8 +230,12 @@ setup_connection (struct PostgresClosure *pg) ",last_reserve_out_serial_id=$2" ",last_reserve_recoup_serial_id=$3" ",last_reserve_close_serial_id=$4" - " WHERE master_pub=$5", - 5), + ",last_purse_merges_serial_id=$5" + ",last_account_merges_serial_id=$6" + ",last_history_requests_serial_id=$7" + ",last_close_requests_serial_id=$8" + " WHERE master_pub=$9", + 9), /* Used in #postgres_get_auditor_progress_reserve() */ GNUNET_PQ_make_prepare ("auditor_progress_select_reserve", "SELECT" @@ -239,6 +243,10 @@ setup_connection (struct PostgresClosure *pg) ",last_reserve_out_serial_id" ",last_reserve_recoup_serial_id" ",last_reserve_close_serial_id" + ",last_purse_merges_serial_id" + ",last_account_merges_serial_id" + ",last_history_requests_serial_id" + ",last_close_requests_serial_id" " FROM auditor_progress_reserve" " WHERE master_pub=$1;", 1), @@ -250,8 +258,12 @@ setup_connection (struct PostgresClosure *pg) ",last_reserve_out_serial_id" ",last_reserve_recoup_serial_id" ",last_reserve_close_serial_id" - ") VALUES ($1,$2,$3,$4,$5);", - 5), + ",last_purse_merges_serial_id" + ",last_account_merges_serial_id" + ",last_history_requests_serial_id" + ",last_close_requests_serial_id" + ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9);", + 9), /* Used in #postgres_update_auditor_progress_aggregation() */ GNUNET_PQ_make_prepare ("auditor_progress_update_aggregation", "UPDATE auditor_progress_aggregation SET " @@ -301,8 +313,9 @@ setup_connection (struct PostgresClosure *pg) ",last_refund_serial_id=$4" ",last_recoup_serial_id=$5" ",last_recoup_refresh_serial_id=$6" - " WHERE master_pub=$7", - 7), + ",last_purse_deposits_serial_id=$7" + " WHERE master_pub=$8", + 8), /* Used in #postgres_get_auditor_progress_coin() */ GNUNET_PQ_make_prepare ("auditor_progress_select_coin", "SELECT" @@ -312,6 +325,7 @@ setup_connection (struct PostgresClosure *pg) ",last_refund_serial_id" ",last_recoup_serial_id" ",last_recoup_refresh_serial_id" + ",last_purse_deposits_serial_id" " FROM auditor_progress_coin" " WHERE master_pub=$1;", 1), @@ -325,8 +339,9 @@ setup_connection (struct PostgresClosure *pg) ",last_refund_serial_id" ",last_recoup_serial_id" ",last_recoup_refresh_serial_id" - ") VALUES ($1,$2,$3,$4,$5,$6,$7);", - 7), + ",last_purse_deposits_serial_id" + ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8);", + 8), /* Used in #postgres_insert_wire_auditor_account_progress() */ GNUNET_PQ_make_prepare ("wire_auditor_account_progress_insert", "INSERT INTO wire_auditor_account_progress " @@ -1225,6 +1240,10 @@ postgres_insert_auditor_progress_reserve ( GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_out_serial_id), GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_recoup_serial_id), GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_close_serial_id), + GNUNET_PQ_query_param_uint64 (&ppr->last_purse_merges_serial_id), + GNUNET_PQ_query_param_uint64 (&ppr->last_account_merges_serial_id), + GNUNET_PQ_query_param_uint64 (&ppr->last_history_requests_serial_id), + GNUNET_PQ_query_param_uint64 (&ppr->last_close_requests_serial_id), GNUNET_PQ_query_param_end }; @@ -1255,6 +1274,10 @@ postgres_update_auditor_progress_reserve ( GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_out_serial_id), GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_recoup_serial_id), GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_close_serial_id), + GNUNET_PQ_query_param_uint64 (&ppr->last_purse_merges_serial_id), + GNUNET_PQ_query_param_uint64 (&ppr->last_account_merges_serial_id), + GNUNET_PQ_query_param_uint64 (&ppr->last_history_requests_serial_id), + GNUNET_PQ_query_param_uint64 (&ppr->last_close_requests_serial_id), GNUNET_PQ_query_param_auto_from_type (master_pub), GNUNET_PQ_query_param_end }; @@ -1293,6 +1316,14 @@ postgres_get_auditor_progress_reserve ( &ppr->last_reserve_recoup_serial_id), GNUNET_PQ_result_spec_uint64 ("last_reserve_close_serial_id", &ppr->last_reserve_close_serial_id), + GNUNET_PQ_result_spec_uint64 ("last_purse_merges_serial_id", + &ppr->last_purse_merges_serial_id), + GNUNET_PQ_result_spec_uint64 ("last_account_merges_serial_id", + &ppr->last_account_merges_serial_id), + GNUNET_PQ_result_spec_uint64 ("last_history_requests_serial_id", + &ppr->last_history_requests_serial_id), + GNUNET_PQ_result_spec_uint64 ("last_close_requests_serial_id", + &ppr->last_close_requests_serial_id), GNUNET_PQ_result_spec_end }; @@ -1503,6 +1534,7 @@ postgres_insert_auditor_progress_coin ( GNUNET_PQ_query_param_uint64 (&ppc->last_refund_serial_id), GNUNET_PQ_query_param_uint64 (&ppc->last_recoup_serial_id), GNUNET_PQ_query_param_uint64 (&ppc->last_recoup_refresh_serial_id), + GNUNET_PQ_query_param_uint64 (&ppc->last_purse_deposits_serial_id), GNUNET_PQ_query_param_end }; @@ -1535,6 +1567,7 @@ postgres_update_auditor_progress_coin ( GNUNET_PQ_query_param_uint64 (&ppc->last_refund_serial_id), GNUNET_PQ_query_param_uint64 (&ppc->last_recoup_serial_id), GNUNET_PQ_query_param_uint64 (&ppc->last_recoup_refresh_serial_id), + GNUNET_PQ_query_param_uint64 (&ppc->last_purse_deposits_serial_id), GNUNET_PQ_query_param_auto_from_type (master_pub), GNUNET_PQ_query_param_end }; @@ -1577,6 +1610,8 @@ postgres_get_auditor_progress_coin ( &ppc->last_recoup_serial_id), GNUNET_PQ_result_spec_uint64 ("last_recoup_refresh_serial_id", &ppc->last_recoup_refresh_serial_id), + GNUNET_PQ_result_spec_uint64 ("last_purse_deposits_serial_id", + &ppc->last_purse_deposits_serial_id), GNUNET_PQ_result_spec_end }; diff --git a/src/include/taler_auditordb_plugin.h b/src/include/taler_auditordb_plugin.h index 71cd79808..7a801c68e 100644 --- a/src/include/taler_auditordb_plugin.h +++ b/src/include/taler_auditordb_plugin.h @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2021 Taler Systems SA + Copyright (C) 2014-2022 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 @@ -157,6 +157,30 @@ struct TALER_AUDITORDB_ProgressPointReserve */ uint64_t last_reserve_close_serial_id; + /** + * serial ID of the last purse_merges + * entry the auditor processed. + */ + uint64_t last_purse_merges_serial_id; + + /** + * serial ID of the last account_merges + * entry the auditor processed. + */ + uint64_t last_account_merges_serial_id; + + /** + * serial ID of the last history_requests + * entry the auditor processed. + */ + uint64_t last_history_requests_serial_id; + + /** + * serial ID of the last close_requests + * entry the auditor processed. + */ + uint64_t last_close_requests_serial_id; + }; @@ -224,6 +248,11 @@ struct TALER_AUDITORDB_ProgressPointCoin */ uint64_t last_recoup_refresh_serial_id; + /** + * Serial ID of the last purse_deposits operation the auditor processed. + */ + uint64_t last_purse_deposits_serial_id; + }; -- cgit v1.2.3