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.c541
1 files changed, 294 insertions, 247 deletions
diff --git a/src/auditor/taler-helper-auditor-aggregation.c b/src/auditor/taler-helper-auditor-aggregation.c
index 468f66b44..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-2021 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 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;
@@ -297,22 +301,17 @@ struct WireFeeInfo
/**
* When does the fee go into effect (inclusive).
*/
- struct GNUNET_TIME_Absolute start_date;
+ struct GNUNET_TIME_Timestamp start_date;
/**
* When does the fee stop being in effect (exclusive).
*/
- struct GNUNET_TIME_Absolute end_date;
-
- /**
- * How high is the wire fee.
- */
- struct TALER_Amount wire_fee;
+ struct GNUNET_TIME_Timestamp end_date;
/**
- * How high is the closing fee.
+ * How high are the wire fees.
*/
- struct TALER_Amount closing_fee;
+ struct TALER_WireFeeSet fees;
};
@@ -358,14 +357,14 @@ struct WireCheckContext
struct TALER_Amount total_deposits;
/**
- * Hash of the wire transfer details of the receiver.
+ * Target account details of the receiver.
*/
- struct GNUNET_HashCode h_wire;
+ const char *payto_uri;
/**
* Execution time of the wire transfer.
*/
- struct GNUNET_TIME_Absolute date;
+ struct GNUNET_TIME_Timestamp date;
/**
* Database transaction status.
@@ -390,12 +389,12 @@ struct WireCheckContext
* @param[out] deposit_gain amount the coin contributes excluding refunds
* @return #GNUNET_OK on success, #GNUNET_SYSERR if the transaction must fail (hard error)
*/
-static int
+static enum GNUNET_GenericReturnValue
check_transaction_history_for_deposit (
const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct GNUNET_HashCode *h_contract_terms,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct TALER_DenominationKeyValidityPS *issue,
+ const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue,
const struct TALER_EXCHANGEDB_TransactionList *tl_head,
struct TALER_Amount *merchant_gain,
struct TALER_Amount *deposit_gain)
@@ -403,9 +402,9 @@ check_transaction_history_for_deposit (
struct TALER_Amount expenditures;
struct TALER_Amount refunds;
struct TALER_Amount spent;
+ struct TALER_Amount *deposited = NULL;
struct TALER_Amount merchant_loss;
const struct TALER_Amount *deposit_fee;
- int refund_deposit_fee;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Checking transaction history of coin %s\n",
@@ -426,46 +425,34 @@ check_transaction_history_for_deposit (
to reconstruct the order of the events, so instead of subtracting we
compute positive (deposit, melt) and negative (refund) values separately
here, and then subtract the negative from the positive at the end (after
- the loops). *///
- refund_deposit_fee = GNUNET_NO;
+ the loops). */
deposit_fee = NULL;
for (const struct TALER_EXCHANGEDB_TransactionList *tl = tl_head;
NULL != tl;
tl = tl->next)
{
- const struct TALER_Amount *amount_with_fee;
const struct TALER_Amount *fee_claimed;
switch (tl->type)
{
case TALER_EXCHANGEDB_TT_DEPOSIT:
/* check wire and h_wire are consistent */
+ if (NULL != deposited)
{
- struct GNUNET_HashCode hw;
-
- if (GNUNET_OK !=
- TALER_JSON_merchant_wire_signature_hash (
- tl->details.deposit->receiver_wire_account,
- &hw))
- {
- report_row_inconsistency ("deposits",
- tl->serial_id,
- "wire account given is malformed");
- }
- else if (0 !=
- GNUNET_memcmp (&hw,
- &tl->details.deposit->h_wire))
- {
- report_row_inconsistency ("deposits",
- tl->serial_id,
- "h(wire) does not match wire");
- }
+ TALER_ARL_report (report_row_inconsistencies,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("table",
+ "deposits"),
+ GNUNET_JSON_pack_uint64 ("row",
+ tl->serial_id),
+ GNUNET_JSON_pack_string ("diagnostic",
+ "multiple deposits of the same coin into the same contract detected")));
}
- amount_with_fee = &tl->details.deposit->amount_with_fee; /* according to exchange*/
+ deposited = &tl->details.deposit->amount_with_fee; /* according to exchange*/
fee_claimed = &tl->details.deposit->deposit_fee; /* Fee according to exchange DB */
TALER_ARL_amount_add (&expenditures,
&expenditures,
- amount_with_fee);
+ deposited);
/* Check if this deposit is within the remit of the aggregation
we are investigating, if so, include it in the totals. */
if ( (0 == GNUNET_memcmp (merchant_pub,
@@ -476,7 +463,7 @@ check_transaction_history_for_deposit (
struct TALER_Amount amount_without_fee;
TALER_ARL_amount_subtract (&amount_without_fee,
- amount_with_fee,
+ deposited,
fee_claimed);
TALER_ARL_amount_add (merchant_gain,
merchant_gain,
@@ -487,120 +474,168 @@ check_transaction_history_for_deposit (
deposit_fee = fee_claimed; /* We had a deposit, remember the fee, we may need it */
}
/* Check that the fees given in the transaction list and in dki match */
+ if (0 !=
+ TALER_amount_cmp (&issue->fees.deposit,
+ fee_claimed))
+ {
+ /* Disagreement in fee structure between auditor and exchange DB! */
+ report_amount_arithmetic_inconsistency ("deposit fee",
+ 0,
+ fee_claimed,
+ &issue->fees.deposit,
+ 1);
+ }
+ break;
+ case TALER_EXCHANGEDB_TT_MELT:
{
- struct TALER_Amount fee_expected;
+ const struct TALER_Amount *amount_with_fee;
- /* Fee according to denomination data of auditor */
- TALER_amount_ntoh (&fee_expected,
- &issue->fee_deposit);
+ amount_with_fee = &tl->details.melt->amount_with_fee;
+ fee_claimed = &tl->details.melt->melt_fee;
+ TALER_ARL_amount_add (&expenditures,
+ &expenditures,
+ amount_with_fee);
+ /* Check that the fees given in the transaction list and in dki match */
if (0 !=
- TALER_amount_cmp (&fee_expected,
+ TALER_amount_cmp (&issue->fees.refresh,
fee_claimed))
{
- /* Disagreement in fee structure between auditor and exchange DB! */
- report_amount_arithmetic_inconsistency ("deposit fee",
+ /* Disagreement in fee structure between exchange and auditor */
+ report_amount_arithmetic_inconsistency ("melt fee",
0,
fee_claimed,
- &fee_expected,
+ &issue->fees.refresh,
1);
}
+ break;
}
- break;
- case TALER_EXCHANGEDB_TT_MELT:
- amount_with_fee = &tl->details.melt->amount_with_fee;
- fee_claimed = &tl->details.melt->melt_fee;
- TALER_ARL_amount_add (&expenditures,
- &expenditures,
- amount_with_fee);
- /* Check that the fees given in the transaction list and in dki match */
+ case TALER_EXCHANGEDB_TT_REFUND:
{
- struct TALER_Amount fee_expected;
+ const struct TALER_Amount *amount_with_fee;
- TALER_amount_ntoh (&fee_expected,
- &issue->fee_refresh);
+ amount_with_fee = &tl->details.refund->refund_amount;
+ fee_claimed = &tl->details.refund->refund_fee;
+ TALER_ARL_amount_add (&refunds,
+ &refunds,
+ amount_with_fee);
+ TALER_ARL_amount_add (&expenditures,
+ &expenditures,
+ fee_claimed);
+ /* Check if this refund is within the remit of the aggregation
+ we are investigating, if so, include it in the totals. */
+ if ( (0 == GNUNET_memcmp (merchant_pub,
+ &tl->details.refund->merchant_pub)) &&
+ (0 == GNUNET_memcmp (h_contract_terms,
+ &tl->details.refund->h_contract_terms)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Detected applicable refund of %s\n",
+ TALER_amount2s (amount_with_fee));
+ TALER_ARL_amount_add (&merchant_loss,
+ &merchant_loss,
+ amount_with_fee);
+ }
+ /* Check that the fees given in the transaction list and in dki match */
if (0 !=
- TALER_amount_cmp (&fee_expected,
+ TALER_amount_cmp (&issue->fees.refund,
fee_claimed))
{
- /* Disagreement in fee structure between exchange and auditor */
- report_amount_arithmetic_inconsistency ("melt fee",
+ /* Disagreement in fee structure between exchange and auditor! */
+ report_amount_arithmetic_inconsistency ("refund fee",
0,
fee_claimed,
- &fee_expected,
+ &issue->fees.refund,
1);
}
+ break;
}
- break;
- case TALER_EXCHANGEDB_TT_REFUND:
- amount_with_fee = &tl->details.refund->refund_amount;
- fee_claimed = &tl->details.refund->refund_fee;
- TALER_ARL_amount_add (&refunds,
- &refunds,
- amount_with_fee);
- TALER_ARL_amount_add (&expenditures,
- &expenditures,
- fee_claimed);
- /* Check if this refund is within the remit of the aggregation
- we are investigating, if so, include it in the totals. */
- if ( (0 == GNUNET_memcmp (merchant_pub,
- &tl->details.refund->merchant_pub)) &&
- (0 == GNUNET_memcmp (h_contract_terms,
- &tl->details.refund->h_contract_terms)) )
+ case TALER_EXCHANGEDB_TT_OLD_COIN_RECOUP:
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Detected applicable refund of %s\n",
- TALER_amount2s (amount_with_fee));
- TALER_ARL_amount_add (&merchant_loss,
- &merchant_loss,
+ const struct TALER_Amount *amount_with_fee;
+
+ amount_with_fee = &tl->details.old_coin_recoup->value;
+ /* We count recoups of refreshed coins like refunds for the dirty old
+ coin, as they equivalently _increase_ the remaining value on the
+ _old_ coin */
+ TALER_ARL_amount_add (&refunds,
+ &refunds,
amount_with_fee);
- /* If there is a refund, we give back the deposit fee */
- refund_deposit_fee = GNUNET_YES;
+ break;
}
- /* Check that the fees given in the transaction list and in dki match */
+ case TALER_EXCHANGEDB_TT_RECOUP:
{
- struct TALER_Amount fee_expected;
+ const struct TALER_Amount *amount_with_fee;
- TALER_amount_ntoh (&fee_expected,
- &issue->fee_refund);
+ /* We count recoups of the coin as expenditures, as it
+ equivalently decreases the remaining value of the recouped coin. */
+ amount_with_fee = &tl->details.recoup->value;
+ TALER_ARL_amount_add (&expenditures,
+ &expenditures,
+ amount_with_fee);
+ break;
+ }
+ case TALER_EXCHANGEDB_TT_RECOUP_REFRESH:
+ {
+ const struct TALER_Amount *amount_with_fee;
+
+ /* We count recoups of the coin as expenditures, as it
+ equivalently decreases the remaining value of the recouped coin. */
+ amount_with_fee = &tl->details.recoup_refresh->value;
+ TALER_ARL_amount_add (&expenditures,
+ &expenditures,
+ amount_with_fee);
+ break;
+ }
+ case TALER_EXCHANGEDB_TT_PURSE_DEPOSIT:
+ {
+ const struct TALER_Amount *amount_with_fee;
+
+ amount_with_fee = &tl->details.purse_deposit->amount;
+ if (! tl->details.purse_deposit->refunded)
+ TALER_ARL_amount_add (&expenditures,
+ &expenditures,
+ 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 (&fee_expected,
+ 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,
- &fee_expected,
+ &issue->fees.refund,
1);
}
+ break;
}
- break;
- case TALER_EXCHANGEDB_TT_OLD_COIN_RECOUP:
- amount_with_fee = &tl->details.old_coin_recoup->value;
- /* We count recoups of refreshed coins like refunds for the dirty old
- coin, as they equivalently _increase_ the remaining value on the
- _old_ coin */
- TALER_ARL_amount_add (&refunds,
- &refunds,
- amount_with_fee);
- break;
- case TALER_EXCHANGEDB_TT_RECOUP:
- /* We count recoups of the coin as expenditures, as it
- equivalently decreases the remaining value of the recouped coin. */
- amount_with_fee = &tl->details.recoup->value;
- TALER_ARL_amount_add (&expenditures,
- &expenditures,
- amount_with_fee);
- break;
- case TALER_EXCHANGEDB_TT_RECOUP_REFRESH:
- /* We count recoups of the coin as expenditures, as it
- equivalently decreases the remaining value of the recouped coin. */
- amount_with_fee = &tl->details.recoup_refresh->value;
- TALER_ARL_amount_add (&expenditures,
- &expenditures,
- amount_with_fee);
- 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,
@@ -610,11 +645,15 @@ check_transaction_history_for_deposit (
"Aggregation loss due to refunds is %s\n",
TALER_amount2s (&merchant_loss));
*deposit_gain = *merchant_gain;
- if ( (GNUNET_YES == refund_deposit_fee) &&
- (NULL != deposit_fee) )
+ if ( (NULL != deposited) &&
+ (NULL != deposit_fee) &&
+ (0 == TALER_amount_cmp (&refunds,
+ deposited)) )
{
- /* We had a /deposit operation AND a /refund operation,
- and should thus not charge the merchant the /deposit fee */
+ /* We had a /deposit operation AND /refund operations adding up to the
+ total deposited value including deposit fee. Thus, we should not
+ subtract the /deposit fee from the merchant gain (as it was also
+ refunded). */
TALER_ARL_amount_add (merchant_gain,
merchant_gain,
deposit_fee);
@@ -667,18 +706,14 @@ check_transaction_history_for_deposit (
else
{
/* Now check that 'spent' is less or equal than the total coin value */
- struct TALER_Amount value;
-
- TALER_amount_ntoh (&value,
- &issue->value);
if (1 == TALER_amount_cmp (&spent,
- &value))
+ &issue->value))
{
/* spent > value */
report_coin_arithmetic_inconsistency ("spend",
coin_pub,
&spent,
- &value,
+ &issue->value,
-1);
}
}
@@ -691,7 +726,7 @@ check_transaction_history_for_deposit (
"Coin %s contributes %s to contract %s\n",
TALER_B2S (coin_pub),
TALER_amount2s (merchant_gain),
- GNUNET_h2s (h_contract_terms));
+ GNUNET_h2s (&h_contract_terms->hash));
return GNUNET_OK;
}
@@ -703,8 +738,8 @@ check_transaction_history_for_deposit (
* @param[in,out] cls a `struct WireCheckContext`
* @param rowid which row in the table is the information from (for diagnostics)
* @param merchant_pub public key of the merchant (should be same for all callbacks with the same @e cls)
- * @param h_wire hash of wire transfer details of the merchant (should be same for all callbacks with the same @e cls)
- * @param account_details where did we transfer the funds?
+ * @param account_pay_uri where did we transfer the funds?
+ * @param h_payto hash over @a account_payto_uri as it is in the DB
* @param exec_time execution time of the wire transfer (should be same for all callbacks with the same @e cls)
* @param h_contract_terms which proposal was this payment about
* @param denom_pub denomination of @a coin_pub
@@ -719,46 +754,53 @@ wire_transfer_information_cb (
void *cls,
uint64_t rowid,
const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct GNUNET_HashCode *h_wire,
- const json_t *account_details,
- struct GNUNET_TIME_Absolute exec_time,
- const struct GNUNET_HashCode *h_contract_terms,
+ const char *account_pay_uri,
+ const struct TALER_PaytoHashP *h_payto,
+ struct GNUNET_TIME_Timestamp exec_time,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_DenominationPublicKey *denom_pub,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_Amount *coin_value,
const struct TALER_Amount *deposit_fee)
{
struct WireCheckContext *wcc = cls;
- const struct TALER_DenominationKeyValidityPS *issue;
+ const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue;
struct TALER_Amount computed_value;
struct TALER_Amount total_deposit_without_refunds;
struct TALER_EXCHANGEDB_TransactionList *tl;
struct TALER_CoinPublicInfo coin;
enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_HashCode hw;
-
- if (GNUNET_OK !=
- TALER_JSON_merchant_wire_signature_hash (account_details,
- &hw))
+ struct TALER_PaytoHashP hpt;
+ uint64_t etag_out;
+
+ TALER_payto_hash (account_pay_uri,
+ &hpt);
+ if (0 !=
+ GNUNET_memcmp (&hpt,
+ h_payto))
{
- report_row_inconsistency ("aggregation",
+ report_row_inconsistency ("wire_targets",
rowid,
- "failed to compute hash of given wire data");
+ "h-payto does not match payto URI");
}
- else if (0 !=
- GNUNET_memcmp (&hw,
- h_wire))
+ /* Obtain coin's transaction history */
+ /* TODO: could use 'start' mechanism to only fetch transactions
+ we did not yet process, instead of going over them
+ again and again.*/
+
{
- report_row_inconsistency ("aggregation",
- rowid,
- "database contains wrong hash code for wire details");
+ 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);
}
-
- /* Obtain coin's transaction history */
- qs = TALER_ARL_edb->get_coin_transactions (TALER_ARL_edb->cls,
- coin_pub,
- GNUNET_YES,
- &tl);
if ( (qs < 0) ||
(NULL == tl) )
{
@@ -788,7 +830,7 @@ wire_transfer_information_cb (
&issue);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
- GNUNET_CRYPTO_rsa_signature_free (coin.denom_sig.rsa_signature);
+ TALER_denom_sig_free (&coin.denom_sig);
TALER_ARL_edb->free_coin_transaction_list (TALER_ARL_edb->cls,
tl);
if (0 == qs)
@@ -819,7 +861,7 @@ wire_transfer_information_cb (
TALER_ARL_amount_add (&total_bad_sig_loss,
&total_bad_sig_loss,
coin_value);
- GNUNET_CRYPTO_rsa_signature_free (coin.denom_sig.rsa_signature);
+ TALER_denom_sig_free (&coin.denom_sig);
TALER_ARL_edb->free_coin_transaction_list (TALER_ARL_edb->cls,
tl);
report_row_inconsistency ("deposit",
@@ -827,8 +869,7 @@ wire_transfer_information_cb (
"coin denomination signature invalid");
return;
}
- GNUNET_CRYPTO_rsa_signature_free (coin.denom_sig.rsa_signature);
- coin.denom_sig.rsa_signature = NULL; /* just to be sure */
+ TALER_denom_sig_free (&coin.denom_sig);
GNUNET_assert (NULL != issue); /* mostly to help static analysis */
/* Check transaction history to see if it supports aggregate
valuation */
@@ -879,20 +920,21 @@ wire_transfer_information_cb (
"aggregation (contribution)",
rowid,
&coin_value_without_fee,
- &
- total_deposit_without_refunds,
+ &total_deposit_without_refunds,
-1);
}
}
/* Check other details of wire transfer match */
- if (0 != GNUNET_memcmp (h_wire,
- &wcc->h_wire))
+ if (0 != strcmp (account_pay_uri,
+ wcc->payto_uri))
{
report_row_inconsistency ("aggregation",
rowid,
"target of outgoing wire transfer do not match hash of wire from deposit");
}
- if (exec_time.abs_value_us != wcc->date.abs_value_us)
+ if (GNUNET_TIME_timestamp_cmp (exec_time,
+ !=,
+ wcc->date) )
{
/* This should be impossible from database constraints */
GNUNET_break (0);
@@ -924,7 +966,7 @@ wire_transfer_information_cb (
static const struct TALER_Amount *
get_wire_fee (struct AggregationContext *ac,
const char *method,
- struct GNUNET_TIME_Absolute timestamp)
+ struct GNUNET_TIME_Timestamp timestamp)
{
struct WireFeeInfo *wfi;
struct WireFeeInfo *pos;
@@ -933,10 +975,16 @@ get_wire_fee (struct AggregationContext *ac,
/* Check if fee is already loaded in cache */
for (pos = ac->fee_head; NULL != pos; pos = pos->next)
{
- if ( (pos->start_date.abs_value_us <= timestamp.abs_value_us) &&
- (pos->end_date.abs_value_us > timestamp.abs_value_us) )
- return &pos->wire_fee;
- if (pos->start_date.abs_value_us > timestamp.abs_value_us)
+ if (GNUNET_TIME_timestamp_cmp (pos->start_date,
+ <=,
+ timestamp) &&
+ GNUNET_TIME_timestamp_cmp (pos->end_date,
+ >,
+ timestamp) )
+ return &pos->fees.wire;
+ if (GNUNET_TIME_timestamp_cmp (pos->start_date,
+ >,
+ timestamp))
break;
}
@@ -948,8 +996,7 @@ get_wire_fee (struct AggregationContext *ac,
timestamp,
&wfi->start_date,
&wfi->end_date,
- &wfi->wire_fee,
- &wfi->closing_fee,
+ &wfi->fees,
&master_sig))
{
GNUNET_break (0);
@@ -966,13 +1013,12 @@ get_wire_fee (struct AggregationContext *ac,
method,
wfi->start_date,
wfi->end_date,
- &wfi->wire_fee,
- &wfi->closing_fee,
+ &wfi->fees,
&TALER_ARL_master_pub,
&master_sig))
{
report_row_inconsistency ("wire-fee",
- timestamp.abs_value_us,
+ timestamp.abs_time.abs_value_us,
"wire fee signature invalid at given time");
}
}
@@ -980,8 +1026,8 @@ get_wire_fee (struct AggregationContext *ac,
/* Established fee, keep in sorted list */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Wire fee is %s starting at %s\n",
- TALER_amount2s (&wfi->wire_fee),
- GNUNET_STRINGS_absolute_time_to_string (wfi->start_date));
+ TALER_amount2s (&wfi->fees.wire),
+ GNUNET_TIME_timestamp2s (wfi->start_date));
if ( (NULL == pos) ||
(NULL == pos->prev) )
GNUNET_CONTAINER_DLL_insert (ac->fee_head,
@@ -994,7 +1040,9 @@ get_wire_fee (struct AggregationContext *ac,
wfi);
/* Check non-overlaping fee invariant */
if ( (NULL != wfi->prev) &&
- (wfi->prev->end_date.abs_value_us > wfi->start_date.abs_value_us) )
+ GNUNET_TIME_timestamp_cmp (wfi->prev->end_date,
+ >,
+ wfi->start_date) )
{
TALER_ARL_report (report_fee_time_inconsistencies,
GNUNET_JSON_PACK (
@@ -1003,10 +1051,12 @@ get_wire_fee (struct AggregationContext *ac,
GNUNET_JSON_pack_string ("diagnostic",
"start date before previous end date"),
TALER_JSON_pack_time_abs_human ("time",
- wfi->start_date)));
+ wfi->start_date.abs_time)));
}
if ( (NULL != wfi->next) &&
- (wfi->next->start_date.abs_value_us >= wfi->end_date.abs_value_us) )
+ GNUNET_TIME_timestamp_cmp (wfi->next->start_date,
+ >=,
+ wfi->end_date) )
{
TALER_ARL_report (report_fee_time_inconsistencies,
GNUNET_JSON_PACK (
@@ -1015,9 +1065,9 @@ get_wire_fee (struct AggregationContext *ac,
GNUNET_JSON_pack_string ("diagnostic",
"end date date after next start date"),
TALER_JSON_pack_time_abs_human ("time",
- wfi->end_date)));
+ wfi->end_date.abs_time)));
}
- return &wfi->wire_fee;
+ return &wfi->fees.wire;
}
@@ -1029,16 +1079,16 @@ get_wire_fee (struct AggregationContext *ac,
* @param rowid identifier of the respective row in the database
* @param date timestamp of the wire transfer (roughly)
* @param wtid wire transfer subject
- * @param wire wire transfer details of the receiver
+ * @param payto_uri bank account details of the receiver
* @param amount amount that was wired
* @return #GNUNET_OK to continue, #GNUNET_SYSERR to stop iteration
*/
-static int
+static enum GNUNET_GenericReturnValue
check_wire_out_cb (void *cls,
uint64_t rowid,
- struct GNUNET_TIME_Absolute date,
+ struct GNUNET_TIME_Timestamp date,
const struct TALER_WireTransferIdentifierRawP *wtid,
- const json_t *wire,
+ const char *payto_uri,
const struct TALER_Amount *amount)
{
struct AggregationContext *ac = cls;
@@ -1049,15 +1099,16 @@ 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",
TALER_B2S (wtid),
TALER_amount2s (amount),
- GNUNET_STRINGS_absolute_time_to_string (date));
- if (NULL == (method = TALER_JSON_wire_to_method (wire)))
+ GNUNET_TIME_timestamp2s (date));
+ if (NULL == (method = TALER_payto_get_method (payto_uri)))
{
report_row_inconsistency ("wire_out",
rowid,
@@ -1071,14 +1122,7 @@ check_wire_out_cb (void *cls,
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (amount->currency,
&wcc.total_deposits));
- if (GNUNET_OK !=
- TALER_JSON_merchant_wire_signature_hash (wire,
- &wcc.h_wire))
- {
- GNUNET_break (0);
- GNUNET_free (method);
- return GNUNET_SYSERR;
- }
+ wcc.payto_uri = payto_uri;
qs = TALER_ARL_edb->lookup_wire_transfer (TALER_ARL_edb->cls,
wtid,
&wire_transfer_information_cb,
@@ -1096,7 +1140,7 @@ check_wire_out_cb (void *cls,
in #wire_transfer_information_cb, so here we
only log for debugging */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Inconsitency for wire_out %llu (WTID %s) detected\n",
+ "Inconsistency for wire_out %llu (WTID %s) detected\n",
(unsigned long long) rowid,
TALER_B2S (wtid));
}
@@ -1112,7 +1156,7 @@ check_wire_out_cb (void *cls,
if (NULL == wire_fee)
{
report_row_inconsistency ("wire-fee",
- date.abs_value_us,
+ date.abs_time.abs_value_us,
"wire fee unavailable for given time");
/* If fee is unknown, we just assume the fee is zero */
final_amount = wcc.total_deposits;
@@ -1144,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 */
@@ -1178,8 +1222,8 @@ check_wire_out_cb (void *cls,
TALER_ARL_report (report_wire_out_inconsistencies,
GNUNET_JSON_PACK (
- GNUNET_JSON_pack_object_incref ("destination_account",
- (json_t *) wire),
+ GNUNET_JSON_pack_string ("destination_account",
+ payto_uri),
GNUNET_JSON_pack_uint64 ("rowid",
rowid),
TALER_JSON_pack_amount ("expected",
@@ -1217,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);
@@ -1232,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);
@@ -1252,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)
@@ -1278,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,
@@ -1311,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;
}
@@ -1346,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));
@@ -1440,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",
@@ -1477,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