summaryrefslogtreecommitdiff
path: root/src/auditor/taler-helper-auditor-aggregation.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/auditor/taler-helper-auditor-aggregation.c')
-rw-r--r--src/auditor/taler-helper-auditor-aggregation.c165
1 files changed, 111 insertions, 54 deletions
diff --git a/src/auditor/taler-helper-auditor-aggregation.c b/src/auditor/taler-helper-auditor-aggregation.c
index c03dffe35..a0f2a190f 100644
--- a/src/auditor/taler-helper-auditor-aggregation.c
+++ b/src/auditor/taler-helper-auditor-aggregation.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
@@ -34,17 +34,26 @@
static int global_ret;
/**
- * Checkpointing our progress for aggregations.
+ * 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_ProgressPointAggregation ppa;
+static int test_mode;
/**
* Checkpointing our progress for aggregations.
*/
-static struct TALER_AUDITORDB_ProgressPointAggregation ppa_start;
+static TALER_ARL_DEF_PP (aggregation_last_wire_out_serial_id);
+
+/**
+ * Total aggregation fees (wire fees) earned.
+ */
+static TALER_ARL_DEF_AB (aggregation_total_wire_fee_revenue);
+
/**
- * Array of reports about row inconsitencies.
+ * Array of reports about row inconsistencies.
*/
static json_t *report_row_inconsistencies;
@@ -102,11 +111,6 @@ static struct TALER_Amount total_arithmetic_delta_plus;
static struct TALER_Amount total_arithmetic_delta_minus;
/**
- * Total aggregation fees (wire fees) earned.
- */
-static struct TALER_Amount total_aggregation_fee_income;
-
-/**
* Array of reports about coin operations with bad signatures.
*/
static json_t *report_bad_sig_losses;
@@ -593,7 +597,45 @@ check_transaction_history_for_deposit (
amount_with_fee);
break;
}
- }
+
+ case TALER_EXCHANGEDB_TT_PURSE_REFUND:
+ {
+ const struct TALER_Amount *amount_with_fee;
+
+ amount_with_fee = &tl->details.purse_refund->refund_amount;
+ fee_claimed = &tl->details.purse_refund->refund_fee;
+ TALER_ARL_amount_add (&refunds,
+ &refunds,
+ amount_with_fee);
+ TALER_ARL_amount_add (&expenditures,
+ &expenditures,
+ fee_claimed);
+ /* Check that the fees given in the transaction list and in dki match */
+ if (0 !=
+ TALER_amount_cmp (&issue->fees.refund,
+ fee_claimed))
+ {
+ /* Disagreement in fee structure between exchange and auditor! */
+ report_amount_arithmetic_inconsistency ("refund fee",
+ 0,
+ fee_claimed,
+ &issue->fees.refund,
+ 1);
+ }
+ break;
+ }
+
+ case TALER_EXCHANGEDB_TT_RESERVE_OPEN:
+ {
+ const struct TALER_Amount *amount_with_fee;
+
+ amount_with_fee = &tl->details.reserve_open->coin_contribution;
+ TALER_ARL_amount_add (&expenditures,
+ &expenditures,
+ amount_with_fee);
+ break;
+ }
+ } /* switch (tl->type) */
} /* for 'tl' */
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -729,10 +771,7 @@ wire_transfer_information_cb (
struct TALER_CoinPublicInfo coin;
enum GNUNET_DB_QueryStatus qs;
struct TALER_PaytoHashP hpt;
-
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "DEPFEE: %s\n",
- TALER_amount2s (deposit_fee));
+ uint64_t etag_out;
TALER_payto_hash (account_pay_uri,
&hpt);
@@ -745,9 +784,23 @@ wire_transfer_information_cb (
"h-payto does not match payto URI");
}
/* Obtain coin's transaction history */
- qs = TALER_ARL_edb->get_coin_transactions (TALER_ARL_edb->cls,
- coin_pub,
- &tl);
+ /* TODO: could use 'start' 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 ( (qs < 0) ||
(NULL == tl) )
{
@@ -1046,8 +1099,9 @@ check_wire_out_cb (void *cls,
char *method;
/* should be monotonically increasing */
- GNUNET_assert (rowid >= ppa.last_wire_out_serial_id);
- ppa.last_wire_out_serial_id = rowid + 1;
+ GNUNET_assert (rowid >=
+ TALER_ARL_USE_PP (aggregation_last_wire_out_serial_id));
+ TALER_ARL_USE_PP (aggregation_last_wire_out_serial_id) = rowid + 1;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Checking wire transfer %s over %s performed on %s\n",
@@ -1134,8 +1188,8 @@ check_wire_out_cb (void *cls,
&wcc.total_deposits,
&final_amount);
/* Sum up aggregation fees (we simply include the rounding gains) */
- TALER_ARL_amount_add (&total_aggregation_fee_income,
- &total_aggregation_fee_income,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (aggregation_total_wire_fee_revenue),
+ &TALER_ARL_USE_AB (aggregation_total_wire_fee_revenue),
&exchange_gain);
/* Check that calculated amount matches actual amount */
@@ -1207,9 +1261,10 @@ analyze_aggregations (void *cls)
(void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Analyzing aggregations\n");
- qsp = TALER_ARL_adb->get_auditor_progress_aggregation (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppa);
+ qsp = TALER_ARL_adb->get_auditor_progress (
+ TALER_ARL_adb->cls,
+ TALER_ARL_GET_PP (aggregation_last_wire_out_serial_id),
+ NULL);
if (0 > qsp)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsp);
@@ -1222,18 +1277,19 @@ analyze_aggregations (void *cls)
}
else
{
- ppa_start = ppa;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Resuming aggregation audit at %llu\n",
- (unsigned long long) ppa.last_wire_out_serial_id);
+ (unsigned long long) TALER_ARL_USE_PP (
+ aggregation_last_wire_out_serial_id));
}
memset (&ac,
0,
sizeof (ac));
- qsx = TALER_ARL_adb->get_wire_fee_summary (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_aggregation_fee_income);
+ qsx = TALER_ARL_adb->get_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_GET_AB (aggregation_total_wire_fee_revenue),
+ NULL);
if (0 > qsx)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx);
@@ -1242,7 +1298,7 @@ analyze_aggregations (void *cls)
ac.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
qs = TALER_ARL_edb->select_wire_out_above_serial_id (
TALER_ARL_edb->cls,
- ppa.last_wire_out_serial_id,
+ TALER_ARL_USE_PP (aggregation_last_wire_out_serial_id),
&check_wire_out_cb,
&ac);
if (0 > qs)
@@ -1268,30 +1324,30 @@ analyze_aggregations (void *cls)
return ac.qs;
}
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsx)
- ac.qs = TALER_ARL_adb->insert_wire_fee_summary (
+ ac.qs = TALER_ARL_adb->insert_balance (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_aggregation_fee_income);
+ TALER_ARL_SET_AB (aggregation_total_wire_fee_revenue),
+ NULL);
else
- ac.qs = TALER_ARL_adb->update_wire_fee_summary (
+ ac.qs = TALER_ARL_adb->update_balance (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_aggregation_fee_income);
+ TALER_ARL_SET_AB (aggregation_total_wire_fee_revenue),
+ NULL);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != ac.qs)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == ac.qs);
return ac.qs;
}
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp)
- qs = TALER_ARL_adb->update_auditor_progress_aggregation (
+ qs = TALER_ARL_adb->update_auditor_progress (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppa);
+ TALER_ARL_SET_PP (aggregation_last_wire_out_serial_id),
+ NULL);
else
- qs = TALER_ARL_adb->insert_auditor_progress_aggregation (
+ qs = TALER_ARL_adb->insert_auditor_progress (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppa);
+ TALER_ARL_SET_PP (aggregation_last_wire_out_serial_id),
+ NULL);
if (0 >= qs)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -1301,7 +1357,8 @@ analyze_aggregations (void *cls)
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Concluded aggregation audit step at %llu\n",
- (unsigned long long) ppa.last_wire_out_serial_id);
+ (unsigned long long) TALER_ARL_USE_PP (
+ aggregation_last_wire_out_serial_id));
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
}
@@ -1336,7 +1393,8 @@ run (void *cls,
"Starting audit\n");
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_aggregation_fee_income));
+ &TALER_ARL_USE_AB (
+ aggregation_total_wire_fee_revenue)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
&total_wire_out_delta_plus));
@@ -1430,14 +1488,14 @@ run (void *cls,
"total_arithmetic_delta_minus",
&total_arithmetic_delta_minus),
TALER_JSON_pack_amount (
- "total_aggregation_fee_income",
- &total_aggregation_fee_income),
+ "aggregation_total_wire_fee_revenue",
+ &TALER_ARL_USE_AB (aggregation_total_wire_fee_revenue)),
GNUNET_JSON_pack_uint64 (
"start_ppa_wire_out_serial_id",
- ppa_start.last_wire_out_serial_id),
+ 0 /* defunct */),
GNUNET_JSON_pack_uint64 (
"end_ppa_wire_out_serial_id",
- ppa.last_wire_out_serial_id),
+ TALER_ARL_USE_PP (aggregation_last_wire_out_serial_id)),
/* block #4 */
TALER_JSON_pack_time_abs_human (
"auditor_start_time",
@@ -1467,11 +1525,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