summaryrefslogtreecommitdiff
path: root/src/auditor/taler-helper-auditor-reserves.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/auditor/taler-helper-auditor-reserves.c')
-rw-r--r--src/auditor/taler-helper-auditor-reserves.c1447
1 files changed, 711 insertions, 736 deletions
diff --git a/src/auditor/taler-helper-auditor-reserves.c b/src/auditor/taler-helper-auditor-reserves.c
index 547a45871..aa35c6a75 100644
--- a/src/auditor/taler-helper-auditor-reserves.c
+++ b/src/auditor/taler-helper-auditor-reserves.c
@@ -39,6 +39,14 @@
static int global_ret;
/**
+ * 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;
+
+/**
* After how long should idle reserves be closed?
*/
static struct GNUNET_TIME_Relative idle_reserve_expiration_time;
@@ -46,15 +54,29 @@ static struct GNUNET_TIME_Relative idle_reserve_expiration_time;
/**
* Checkpointing our progress for reserves.
*/
-static struct TALER_AUDITORDB_ProgressPointReserve ppr;
+static TALER_ARL_DEF_PP (reserves_reserve_in_serial_id);
+static TALER_ARL_DEF_PP (reserves_reserve_out_serial_id);
+static TALER_ARL_DEF_PP (reserves_reserve_recoup_serial_id);
+static TALER_ARL_DEF_PP (reserves_reserve_open_serial_id);
+static TALER_ARL_DEF_PP (reserves_reserve_close_serial_id);
+static TALER_ARL_DEF_PP (reserves_purse_decisions_serial_id);
+static TALER_ARL_DEF_PP (reserves_account_merges_serial_id);
+static TALER_ARL_DEF_PP (reserves_history_requests_serial_id);
/**
- * Checkpointing our progress for reserves.
+ * Tracked global reserve balances.
*/
-static struct TALER_AUDITORDB_ProgressPointReserve ppr_start;
+static TALER_ARL_DEF_AB (reserves_reserve_total_balance);
+static TALER_ARL_DEF_AB (reserves_reserve_loss);
+static TALER_ARL_DEF_AB (reserves_withdraw_fee_revenue);
+static TALER_ARL_DEF_AB (reserves_close_fee_revenue);
+static TALER_ARL_DEF_AB (reserves_purse_fee_revenue);
+static TALER_ARL_DEF_AB (reserves_open_fee_revenue);
+static TALER_ARL_DEF_AB (reserves_history_fee_revenue);
+
/**
- * Array of reports about row inconsitencies.
+ * Array of reports about row inconsistencies.
*/
static json_t *report_row_inconsistencies;
@@ -65,39 +87,36 @@ static json_t *report_row_inconsistencies;
static json_t *denomination_key_validity_withdraw_inconsistencies;
/**
- * Array of reports about reserve balance insufficient inconsitencies.
+ * Array of reports about reserve balance insufficient inconsistencies.
*/
static json_t *report_reserve_balance_insufficient_inconsistencies;
/**
- * Array of reports about purse balance insufficient inconsitencies.
+ * Array of reports about purse balance insufficient inconsistencies.
*/
static json_t *report_purse_balance_insufficient_inconsistencies;
/**
- * Total amount reserves were charged beyond their balance.
- */
-static struct TALER_Amount total_balance_insufficient_loss;
-
-/**
* Array of reports about reserve balance summary wrong in database.
*/
static json_t *report_reserve_balance_summary_wrong_inconsistencies;
/**
* Total delta between expected and stored reserve balance summaries,
- * for positive deltas.
+ * for positive deltas. Used only when internal checks are
+ * enabled.
*/
static struct TALER_Amount total_balance_summary_delta_plus;
/**
* Total delta between expected and stored reserve balance summaries,
- * for negative deltas.
+ * for negative deltas. Used only when internal checks are
+ * enabled.
*/
static struct TALER_Amount total_balance_summary_delta_minus;
/**
- * Array of reports about reserve's not being closed inconsitencies.
+ * Array of reports about reserve's not being closed inconsistencies.
*/
static json_t *report_reserve_not_closed_inconsistencies;
@@ -123,31 +142,6 @@ static struct TALER_Amount total_arithmetic_delta_plus;
static struct TALER_Amount total_arithmetic_delta_minus;
/**
- * Expected balance in the escrow account.
- */
-static struct TALER_Amount total_escrow_balance;
-
-/**
- * Recoups we made on denominations that were not revoked (!?).
- */
-static struct TALER_Amount total_irregular_recoups;
-
-/**
- * Total withdraw fees earned.
- */
-static struct TALER_Amount total_withdraw_fee_income;
-
-/**
- * Total purse fees earned.
- */
-static struct TALER_Amount total_purse_fee_income;
-
-/**
- * Total history fees earned.
- */
-static struct TALER_Amount total_history_fee_income;
-
-/**
* Array of reports about coin operations with bad signatures.
*/
static json_t *report_bad_sig_losses;
@@ -220,8 +214,8 @@ report_amount_arithmetic_inconsistency (
if (0 != profitable)
{
target = (1 == profitable)
- ? &total_arithmetic_delta_plus
- : &total_arithmetic_delta_minus;
+ ? &total_arithmetic_delta_plus
+ : &total_arithmetic_delta_minus;
TALER_ARL_amount_add (target,
target,
&delta);
@@ -279,21 +273,15 @@ struct ReserveSummary
struct TALER_Amount total_out;
/**
- * Sum of withdraw fees encountered during this transaction.
+ * Sum of balance and fees encountered during this transaction.
*/
- struct TALER_Amount total_fee;
+ struct TALER_AUDITORDB_ReserveFeeBalance curr_balance;
/**
- * Previous balance of the reserve as remembered by the auditor.
+ * Previous balances of the reserve as remembered by the auditor.
* (updated based on @e total_in and @e total_out at the end).
*/
- struct TALER_Amount balance_at_previous_audit;
-
- /**
- * Previous withdraw fee balance of the reserve, as remembered by the auditor.
- * (updated based on @e total_fee at the end).
- */
- struct TALER_Amount a_withdraw_fee_balance;
+ struct TALER_AUDITORDB_ReserveFeeBalance prev_balance;
/**
* Previous reserve expiration data, as remembered by the auditor.
@@ -333,10 +321,8 @@ load_auditor_reserve_summary (struct ReserveSummary *rs)
qs = TALER_ARL_adb->get_reserve_info (TALER_ARL_adb->cls,
&rs->reserve_pub,
- &TALER_ARL_master_pub,
&rowid,
- &rs->balance_at_previous_audit,
- &rs->a_withdraw_fee_balance,
+ &rs->prev_balance,
&rs->a_expiration_date,
&rs->sender_account);
if (0 > qs)
@@ -349,31 +335,35 @@ load_auditor_reserve_summary (struct ReserveSummary *rs)
rs->had_ri = false;
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (rs->total_in.currency,
- &rs->balance_at_previous_audit));
+ &rs->prev_balance.reserve_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (rs->total_in.currency,
+ &rs->prev_balance.reserve_loss));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (rs->total_in.currency,
- &rs->a_withdraw_fee_balance));
+ &rs->prev_balance.withdraw_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (rs->total_in.currency,
+ &rs->prev_balance.close_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (rs->total_in.currency,
+ &rs->prev_balance.purse_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (rs->total_in.currency,
+ &rs->prev_balance.open_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (rs->total_in.currency,
+ &rs->prev_balance.history_fee_balance));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating fresh reserve `%s' with starting balance %s\n",
- TALER_B2S (&rs->reserve_pub),
- TALER_amount2s (&rs->balance_at_previous_audit));
+ "Creating fresh reserve `%s'\n",
+ TALER_B2S (&rs->reserve_pub));
return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
}
rs->had_ri = true;
- if ( (GNUNET_YES !=
- TALER_amount_cmp_currency (&rs->balance_at_previous_audit,
- &rs->a_withdraw_fee_balance)) ||
- (GNUNET_YES !=
- TALER_amount_cmp_currency (&rs->total_in,
- &rs->balance_at_previous_audit)) )
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Auditor remembers reserve `%s' has balance %s\n",
TALER_B2S (&rs->reserve_pub),
- TALER_amount2s (&rs->balance_at_previous_audit));
+ TALER_amount2s (&rs->prev_balance.reserve_balance));
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
}
@@ -436,7 +426,25 @@ setup_reserve (struct ReserveContext *rc,
&rs->total_out));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &rs->total_fee));
+ &rs->curr_balance.reserve_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &rs->curr_balance.reserve_loss));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &rs->curr_balance.withdraw_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &rs->curr_balance.close_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &rs->curr_balance.purse_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &rs->curr_balance.open_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &rs->curr_balance.history_fee_balance));
if (0 > (qs = load_auditor_reserve_summary (rs)))
{
GNUNET_free (rs);
@@ -479,9 +487,8 @@ handle_reserve_in (void *cls,
(void) wire_reference;
/* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_reserve_in_serial_id);
- ppr.last_reserve_in_serial_id = rowid + 1;
-
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (reserves_reserve_in_serial_id));
+ TALER_ARL_USE_PP (reserves_reserve_in_serial_id) = rowid + 1;
rs = setup_reserve (rc,
reserve_pub);
if (NULL == rs)
@@ -489,9 +496,6 @@ handle_reserve_in (void *cls,
GNUNET_break (0);
return GNUNET_SYSERR;
}
- TALER_ARL_amount_add (&rs->total_in,
- &rs->total_in,
- credit);
if (NULL == rs->sender_account)
rs->sender_account = GNUNET_strdup (sender_account_details);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -503,6 +507,9 @@ handle_reserve_in (void *cls,
idle_reserve_expiration_time));
rs->a_expiration_date = GNUNET_TIME_timestamp_max (rs->a_expiration_date,
expiry);
+ TALER_ARL_amount_add (&rs->total_in,
+ &rs->total_in,
+ credit);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
return GNUNET_OK;
@@ -541,8 +548,8 @@ handle_reserve_out (void *cls,
struct TALER_DenominationHashP h_denom_pub;
/* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_reserve_out_serial_id);
- ppr.last_reserve_out_serial_id = rowid + 1;
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (reserves_reserve_out_serial_id));
+ TALER_ARL_USE_PP (reserves_reserve_out_serial_id) = rowid + 1;
/* lookup denomination pub data (make sure denom_pub is valid, establish fees);
initializes wsrd.h_denomination_pub! */
@@ -618,7 +625,7 @@ handle_reserve_out (void *cls,
amount_with_fee);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
- return GNUNET_OK; /* exit function here, we cannot add this to the legitimate withdrawals */
+ return GNUNET_OK; /* exit function here, we cannot add this to the legitimate withdrawals */
}
TALER_ARL_amount_add (&auditor_amount_with_fee,
@@ -639,9 +646,6 @@ handle_reserve_out (void *cls,
GNUNET_break (0);
return GNUNET_SYSERR;
}
- TALER_ARL_amount_add (&rs->total_out,
- &rs->total_out,
- &auditor_amount_with_fee);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Reserve `%s' reduced by %s from withdraw\n",
TALER_B2S (reserve_pub),
@@ -649,9 +653,15 @@ handle_reserve_out (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Increasing withdraw profits by fee %s\n",
TALER_amount2s (&issue->fees.withdraw));
- TALER_ARL_amount_add (&rs->total_fee,
- &rs->total_fee,
+ TALER_ARL_amount_add (&rs->curr_balance.withdraw_fee_balance,
+ &rs->curr_balance.withdraw_fee_balance,
+ &issue->fees.withdraw);
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (reserves_withdraw_fee_revenue),
+ &TALER_ARL_USE_AB (reserves_withdraw_fee_revenue),
&issue->fees.withdraw);
+ TALER_ARL_amount_add (&rs->total_out,
+ &rs->total_out,
+ &auditor_amount_with_fee);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
return GNUNET_OK;
@@ -684,7 +694,7 @@ handle_recoup_by_reserve (
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 ReserveContext *rc = cls;
struct ReserveSummary *rs;
@@ -696,8 +706,8 @@ handle_recoup_by_reserve (
(void) denom_pub;
/* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_reserve_recoup_serial_id);
- ppr.last_reserve_recoup_serial_id = rowid + 1;
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (reserves_reserve_recoup_serial_id));
+ TALER_ARL_USE_PP (reserves_reserve_recoup_serial_id) = rowid + 1;
/* We know that denom_pub matches denom_pub_hash because this
is how the SQL statement joined the tables. */
if (GNUNET_OK !=
@@ -741,8 +751,8 @@ handle_recoup_by_reserve (
report_row_inconsistency ("recoup",
rowid,
"denomination key not in revocation set");
- TALER_ARL_amount_add (&total_irregular_recoups,
- &total_irregular_recoups,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (reserves_reserve_loss),
+ &TALER_ARL_USE_AB (reserves_reserve_loss),
amount);
}
else
@@ -770,10 +780,11 @@ handle_recoup_by_reserve (
}
else
{
- rev_rowid = 0; /* reported elsewhere */
+ rev_rowid = 0; /* reported elsewhere */
}
if ( (NULL != rev) &&
- (0 == strcmp (rev, "master signature invalid")) )
+ (0 == strcmp (rev,
+ "master signature invalid")) )
{
TALER_ARL_report (report_bad_sig_losses,
GNUNET_JSON_PACK (
@@ -868,6 +879,88 @@ get_closing_fee (const char *receiver_account,
/**
+ * Function called about reserve opening operations.
+ *
+ * @param cls closure
+ * @param rowid row identifier used to uniquely identify the reserve closing operation
+ * @param reserve_payment how much to pay from the
+ * reserve's own balance for opening the reserve
+ * @param request_timestamp when was the request created
+ * @param reserve_expiration desired expiration time for the reserve
+ * @param purse_limit minimum number of purses the client
+ * wants to have concurrently open for this reserve
+ * @param reserve_pub public key of the reserve
+ * @param reserve_sig signature affirming the operation
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+handle_reserve_open (
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_Amount *reserve_payment,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ struct GNUNET_TIME_Timestamp reserve_expiration,
+ uint32_t purse_limit,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReserveSignatureP *reserve_sig)
+{
+ struct ReserveContext *rc = cls;
+ struct ReserveSummary *rs;
+
+ /* should be monotonically increasing */
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (reserves_reserve_open_serial_id));
+ TALER_ARL_USE_PP (reserves_reserve_open_serial_id) = rowid + 1;
+
+ rs = setup_reserve (rc,
+ reserve_pub);
+ if (NULL == rs)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_wallet_reserve_open_verify (reserve_payment,
+ request_timestamp,
+ reserve_expiration,
+ purse_limit,
+ reserve_pub,
+ reserve_sig))
+ {
+ TALER_ARL_report (report_bad_sig_losses,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("operation",
+ "reserve-open"),
+ GNUNET_JSON_pack_uint64 ("row",
+ rowid),
+ TALER_JSON_pack_amount ("loss",
+ reserve_payment),
+ GNUNET_JSON_pack_data_auto ("reserve_pub",
+ reserve_pub)));
+ TALER_ARL_amount_add (&total_bad_sig_loss,
+ &total_bad_sig_loss,
+ reserve_payment);
+ return GNUNET_OK;
+ }
+ TALER_ARL_amount_add (&rs->curr_balance.open_fee_balance,
+ &rs->curr_balance.open_fee_balance,
+ reserve_payment);
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (reserves_open_fee_revenue),
+ &TALER_ARL_USE_AB (reserves_open_fee_revenue),
+ reserve_payment);
+ TALER_ARL_amount_add (&rs->total_out,
+ &rs->total_out,
+ reserve_payment);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Additional open operation for reserve `%s' of %s\n",
+ TALER_B2S (reserve_pub),
+ TALER_amount2s (reserve_payment));
+ if (TALER_ARL_do_abort ())
+ return GNUNET_SYSERR;
+ return GNUNET_OK;
+}
+
+
+/**
* Function called about reserve closing operations
* the aggregator triggered.
*
@@ -879,6 +972,8 @@ get_closing_fee (const char *receiver_account,
* @param reserve_pub public key of the reserve
* @param receiver_account where did we send the funds
* @param transfer_details details about the wire transfer
+ * @param close_request_row which close request triggered the operation?
+ * 0 if it was a timeout
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
*/
static enum GNUNET_GenericReturnValue
@@ -890,15 +985,16 @@ handle_reserve_closed (
const struct TALER_Amount *closing_fee,
const struct TALER_ReservePublicKeyP *reserve_pub,
const char *receiver_account,
- const struct TALER_WireTransferIdentifierRawP *transfer_details)
+ const struct TALER_WireTransferIdentifierRawP *transfer_details,
+ uint64_t close_request_row)
{
struct ReserveContext *rc = cls;
struct ReserveSummary *rs;
(void) transfer_details;
/* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_reserve_close_serial_id);
- ppr.last_reserve_close_serial_id = rowid + 1;
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (reserves_reserve_close_serial_id));
+ TALER_ARL_USE_PP (reserves_reserve_close_serial_id) = rowid + 1;
rs = setup_reserve (rc,
reserve_pub);
@@ -910,12 +1006,6 @@ handle_reserve_closed (
{
struct TALER_Amount expected_fee;
- TALER_ARL_amount_add (&rs->total_out,
- &rs->total_out,
- amount_with_fee);
- TALER_ARL_amount_add (&rs->total_fee,
- &rs->total_fee,
- closing_fee);
/* verify closing_fee is correct! */
if (GNUNET_OK !=
get_closing_fee (receiver_account,
@@ -935,20 +1025,117 @@ handle_reserve_closed (
1);
}
}
- if (NULL == rs->sender_account)
- {
- GNUNET_break (! rs->had_ri);
- report_row_inconsistency ("reserves_close",
- rowid,
- "target account not verified, auditor does not know reserve");
+
+ TALER_ARL_amount_add (&rs->curr_balance.close_fee_balance,
+ &rs->curr_balance.close_fee_balance,
+ closing_fee);
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (reserves_close_fee_revenue),
+ &TALER_ARL_USE_AB (reserves_close_fee_revenue),
+ closing_fee);
+ TALER_ARL_amount_add (&rs->total_out,
+ &rs->total_out,
+ amount_with_fee);
+ if (0 != close_request_row)
+ {
+ struct TALER_ReserveSignatureP reserve_sig;
+ struct GNUNET_TIME_Timestamp request_timestamp;
+ struct TALER_Amount close_balance;
+ struct TALER_Amount close_fee;
+ char *payto_uri;
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TALER_ARL_edb->select_reserve_close_request_info (
+ TALER_ARL_edb->cls,
+ reserve_pub,
+ close_request_row,
+ &reserve_sig,
+ &request_timestamp,
+ &close_balance,
+ &close_fee,
+ &payto_uri);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
+ {
+ report_row_inconsistency ("reserves_close",
+ rowid,
+ "reserve close request unknown");
+ }
+ else
+ {
+ struct TALER_PaytoHashP h_payto;
+
+ TALER_payto_hash (payto_uri,
+ &h_payto);
+ if (GNUNET_OK !=
+ TALER_wallet_reserve_close_verify (
+ request_timestamp,
+ &h_payto,
+ reserve_pub,
+ &reserve_sig))
+ {
+ TALER_ARL_report (report_bad_sig_losses,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("operation",
+ "close-request"),
+ GNUNET_JSON_pack_uint64 ("row",
+ close_request_row),
+ TALER_JSON_pack_amount ("loss",
+ amount_with_fee),
+ GNUNET_JSON_pack_data_auto ("reserve_pub",
+ reserve_pub)));
+ TALER_ARL_amount_add (&total_bad_sig_loss,
+ &total_bad_sig_loss,
+ amount_with_fee);
+ }
+ }
+ if ( (NULL == payto_uri) &&
+ (NULL == rs->sender_account) )
+ {
+ GNUNET_break (! rs->had_ri);
+ report_row_inconsistency ("reserves_close",
+ rowid,
+ "target account not verified, auditor does not know reserve");
+ }
+ if (NULL == payto_uri)
+ {
+ if ( (NULL == rs->sender_account) ||
+ (0 != strcmp (rs->sender_account,
+ receiver_account)) )
+ {
+ report_row_inconsistency ("reserves_close",
+ rowid,
+ "target account does not match origin account");
+ }
+ }
+ else
+ {
+ if (0 != strcmp (payto_uri,
+ receiver_account))
+ {
+ report_row_inconsistency ("reserves_close",
+ rowid,
+ "target account does not match origin account");
+ }
+ }
+ GNUNET_free (payto_uri);
}
- else if (0 != strcmp (rs->sender_account,
- receiver_account))
+ else
{
- report_row_inconsistency ("reserves_close",
- rowid,
- "target account does not match origin account");
+ if (NULL == rs->sender_account)
+ {
+ GNUNET_break (! rs->had_ri);
+ report_row_inconsistency ("reserves_close",
+ rowid,
+ "target account not verified, auditor does not know reserve");
+ }
+ else if (0 != strcmp (rs->sender_account,
+ receiver_account))
+ {
+ report_row_inconsistency ("reserves_close",
+ rowid,
+ "target account does not match origin account");
+ }
}
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Additional closing operation for reserve `%s' of %s\n",
TALER_B2S (reserve_pub),
@@ -960,6 +1147,137 @@ handle_reserve_closed (
/**
+ * Function called with details about account merge requests that have been
+ * made, with the goal of accounting for the merge fee paid by the reserve (if
+ * applicable).
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param reserve_pub reserve affected by the merge
+ * @param purse_pub purse being merged
+ * @param h_contract_terms hash over contract of the purse
+ * @param purse_expiration when would the purse expire
+ * @param amount total amount in the purse
+ * @param min_age minimum age of all coins deposited into the purse
+ * @param flags how was the purse created
+ * @param purse_fee if a purse fee was paid, how high is it
+ * @param merge_timestamp when was the merge approved
+ * @param reserve_sig signature by reserve approving the merge
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+handle_account_merged (
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ struct GNUNET_TIME_Timestamp purse_expiration,
+ const struct TALER_Amount *amount,
+ uint32_t min_age,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_Amount *purse_fee,
+ struct GNUNET_TIME_Timestamp merge_timestamp,
+ const struct TALER_ReserveSignatureP *reserve_sig)
+{
+ struct ReserveContext *rc = cls;
+ struct ReserveSummary *rs;
+
+ /* should be monotonically increasing */
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (reserves_account_merges_serial_id));
+ TALER_ARL_USE_PP (reserves_account_merges_serial_id) = rowid + 1;
+ if (GNUNET_OK !=
+ TALER_wallet_account_merge_verify (merge_timestamp,
+ purse_pub,
+ purse_expiration,
+ h_contract_terms,
+ amount,
+ purse_fee,
+ min_age,
+ flags,
+ reserve_pub,
+ reserve_sig))
+ {
+ TALER_ARL_report (report_bad_sig_losses,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("operation",
+ "account-merge"),
+ GNUNET_JSON_pack_uint64 ("row",
+ rowid),
+ TALER_JSON_pack_amount ("loss",
+ purse_fee),
+ GNUNET_JSON_pack_data_auto ("key_pub",
+ reserve_pub)));
+ TALER_ARL_amount_add (&total_bad_sig_loss,
+ &total_bad_sig_loss,
+ purse_fee);
+ return GNUNET_OK;
+ }
+ if ( (flags & TALER_WAMF_MERGE_MODE_MASK) !=
+ TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE)
+ return GNUNET_OK; /* no impact on reserve balance */
+ rs = setup_reserve (rc,
+ reserve_pub);
+ if (NULL == rs)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (reserves_purse_fee_revenue),
+ &TALER_ARL_USE_AB (reserves_purse_fee_revenue),
+ purse_fee);
+ TALER_ARL_amount_add (&rs->curr_balance.purse_fee_balance,
+ &rs->curr_balance.purse_fee_balance,
+ purse_fee);
+ TALER_ARL_amount_add (&rs->total_out,
+ &rs->total_out,
+ purse_fee);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called with details about a purse that was merged into an account.
+ * Only updates the reserve balance, the actual verifications are done in the
+ * purse helper.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the refund in our DB
+ * @param purse_pub public key of the purse
+ * @param reserve_pub which reserve is the purse credited to
+ * @param purse_value what is the target value of the purse
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+purse_decision_cb (void *cls,
+ uint64_t rowid,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *purse_value)
+{
+ struct ReserveContext *rc = cls;
+ struct ReserveSummary *rs;
+
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (
+ reserves_purse_decisions_serial_id)); /* should be monotonically increasing */
+ TALER_ARL_USE_PP (reserves_purse_decisions_serial_id) = rowid + 1;
+ rs = setup_reserve (rc,
+ reserve_pub);
+ if (NULL == rs)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ TALER_ARL_amount_add (&rs->total_in,
+ &rs->total_in,
+ purse_value);
+ if (TALER_ARL_do_abort ())
+ return GNUNET_SYSERR;
+ return GNUNET_OK;
+}
+
+
+/**
* Check that the reserve summary matches what the exchange database
* thinks about the reserve, and update our own state of the reserve.
*
@@ -977,29 +1295,32 @@ verify_reserve_balance (void *cls,
{
struct ReserveContext *rc = cls;
struct ReserveSummary *rs = value;
- struct TALER_Amount balance;
+ struct TALER_Amount mbalance;
struct TALER_Amount nbalance;
enum GNUNET_DB_QueryStatus qs;
- int ret;
+ enum GNUNET_GenericReturnValue ret;
ret = GNUNET_OK;
/* Check our reserve summary balance calculation shows that
the reserve balance is acceptable (i.e. non-negative) */
- TALER_ARL_amount_add (&balance,
+ TALER_ARL_amount_add (&mbalance,
&rs->total_in,
- &rs->balance_at_previous_audit);
+ &rs->prev_balance.reserve_balance);
if (TALER_ARL_SR_INVALID_NEGATIVE ==
TALER_ARL_amount_subtract_neg (&nbalance,
- &balance,
+ &mbalance,
&rs->total_out))
{
struct TALER_Amount loss;
TALER_ARL_amount_subtract (&loss,
&rs->total_out,
- &balance);
- TALER_ARL_amount_add (&total_balance_insufficient_loss,
- &total_balance_insufficient_loss,
+ &mbalance);
+ TALER_ARL_amount_add (&rs->curr_balance.reserve_loss,
+ &rs->prev_balance.reserve_loss,
+ &loss);
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (reserves_reserve_loss),
+ &TALER_ARL_USE_AB (reserves_reserve_loss),
&loss);
TALER_ARL_report (report_reserve_balance_insufficient_inconsistencies,
GNUNET_JSON_PACK (
@@ -1009,8 +1330,13 @@ verify_reserve_balance (void *cls,
&loss)));
/* Continue with a reserve balance of zero */
GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (balance.currency,
- &nbalance));
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &rs->curr_balance.reserve_balance));
+ }
+ else
+ {
+ /* Update remaining reserve balance! */
+ rs->curr_balance.reserve_balance = nbalance;
}
if (internal_checks)
@@ -1020,13 +1346,10 @@ verify_reserve_balance (void *cls,
internal audit, as otherwise the balance of the 'reserves' table
is not replicated at the auditor. */
struct TALER_EXCHANGEDB_Reserve reserve;
- struct TALER_EXCHANGEDB_KycStatus kyc;
reserve.pub = rs->reserve_pub;
qs = TALER_ARL_edb->reserves_get (TALER_ARL_edb->cls,
- &reserve,
- &kyc);
- // FIXME: figure out what to do with KYC status!
+ &reserve);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
/* If the exchange doesn't have this reserve in the summary, it
@@ -1051,17 +1374,17 @@ verify_reserve_balance (void *cls,
else
{
/* Check that exchange's balance matches our expected balance for the reserve */
- if (0 != TALER_amount_cmp (&nbalance,
+ if (0 != TALER_amount_cmp (&rs->curr_balance.reserve_balance,
&reserve.balance))
{
struct TALER_Amount delta;
- if (0 < TALER_amount_cmp (&nbalance,
+ if (0 < TALER_amount_cmp (&rs->curr_balance.reserve_balance,
&reserve.balance))
{
/* balance > reserve.balance */
TALER_ARL_amount_subtract (&delta,
- &nbalance,
+ &rs->curr_balance.reserve_balance,
&reserve.balance);
TALER_ARL_amount_add (&total_balance_summary_delta_plus,
&total_balance_summary_delta_plus,
@@ -1072,7 +1395,7 @@ verify_reserve_balance (void *cls,
/* balance < reserve.balance */
TALER_ARL_amount_subtract (&delta,
&reserve.balance,
- &nbalance);
+ &rs->curr_balance.reserve_balance);
TALER_ARL_amount_add (&total_balance_summary_delta_minus,
&total_balance_summary_delta_minus,
&delta);
@@ -1084,10 +1407,11 @@ verify_reserve_balance (void *cls,
TALER_JSON_pack_amount ("exchange",
&reserve.balance),
TALER_JSON_pack_amount ("auditor",
- &nbalance)));
+ &rs->curr_balance.
+ reserve_balance)));
}
}
- } /* end of 'if (internal_checks)' */
+ } /* end of 'if (internal_checks)' */
/* Check that reserve is being closed if it is past its expiration date
(and the closing fee would not exceed the remaining balance) */
@@ -1144,26 +1468,43 @@ verify_reserve_balance (void *cls,
}
}
- /* Add withdraw fees we encountered to totals */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Reserve reserve `%s' made %s in withdraw fees\n",
- TALER_B2S (&rs->reserve_pub),
- TALER_amount2s (&rs->total_fee));
- TALER_ARL_amount_add (&rs->a_withdraw_fee_balance,
- &rs->a_withdraw_fee_balance,
- &rs->total_fee);
- TALER_ARL_amount_add (&total_escrow_balance,
- &total_escrow_balance,
+ /* We already computed the 'new' balance in 'curr_balance'
+ to include the previous balance, so this one is just
+ an assignment, not adding up! */
+ rs->prev_balance.reserve_balance = rs->curr_balance.reserve_balance;
+
+ /* Add up new totals to previous totals */
+ TALER_ARL_amount_add (&rs->prev_balance.reserve_loss,
+ &rs->prev_balance.reserve_loss,
+ &rs->curr_balance.reserve_loss);
+ TALER_ARL_amount_add (&rs->prev_balance.withdraw_fee_balance,
+ &rs->prev_balance.withdraw_fee_balance,
+ &rs->curr_balance.withdraw_fee_balance);
+ TALER_ARL_amount_add (&rs->prev_balance.close_fee_balance,
+ &rs->prev_balance.close_fee_balance,
+ &rs->curr_balance.close_fee_balance);
+ TALER_ARL_amount_add (&rs->prev_balance.purse_fee_balance,
+ &rs->prev_balance.purse_fee_balance,
+ &rs->curr_balance.purse_fee_balance);
+ TALER_ARL_amount_add (&rs->prev_balance.open_fee_balance,
+ &rs->prev_balance.open_fee_balance,
+ &rs->curr_balance.open_fee_balance);
+ TALER_ARL_amount_add (&rs->prev_balance.history_fee_balance,
+ &rs->prev_balance.history_fee_balance,
+ &rs->curr_balance.history_fee_balance);
+
+ /* Update global balance: add incoming first, then try
+ to subtract outgoing... */
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (reserves_reserve_total_balance),
+ &TALER_ARL_USE_AB (reserves_reserve_total_balance),
&rs->total_in);
- TALER_ARL_amount_add (&total_withdraw_fee_income,
- &total_withdraw_fee_income,
- &rs->total_fee);
{
struct TALER_Amount r;
if (TALER_ARL_SR_INVALID_NEGATIVE ==
TALER_ARL_amount_subtract_neg (&r,
- &total_escrow_balance,
+ &TALER_ARL_USE_AB (
+ reserves_reserve_total_balance),
&rs->total_out))
{
/* We could not reduce our total balance, i.e. exchange allowed IN TOTAL (!)
@@ -1171,34 +1512,33 @@ verify_reserve_balance (void *cls,
went negative!). Woopsie. Calculate how badly it went and log. */
report_amount_arithmetic_inconsistency ("global escrow balance",
0,
- &total_escrow_balance, /* what we had */
- &rs->total_out, /* what we needed */
+ &TALER_ARL_USE_AB (
+ reserves_reserve_total_balance), /* what we had */
+ &rs->total_out, /* what we needed */
0 /* specific profit/loss does not apply to the total summary */);
/* We unexpectedly went negative, so a sane value to continue from
would be zero. */
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_escrow_balance));
+ &TALER_ARL_USE_AB (
+ reserves_reserve_total_balance)));
}
else
{
- total_escrow_balance = r;
+ TALER_ARL_USE_AB (reserves_reserve_total_balance) = r;
}
}
- if ( (0ULL == balance.value) &&
- (0U == balance.fraction) )
+ if (TALER_amount_is_zero (&rs->prev_balance.reserve_balance))
{
/* balance is zero, drop reserve details (and then do not update/insert) */
if (rs->had_ri)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Final balance of reserve `%s' is %s, dropping it\n",
- TALER_B2S (&rs->reserve_pub),
- TALER_amount2s (&nbalance));
+ "Final balance of reserve `%s' is zero, dropping it\n",
+ TALER_B2S (&rs->reserve_pub));
qs = TALER_ARL_adb->del_reserve_info (TALER_ARL_adb->cls,
- &rs->reserve_pub,
- &TALER_ARL_master_pub);
+ &rs->reserve_pub);
if (0 >= qs)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@@ -1209,9 +1549,8 @@ verify_reserve_balance (void *cls,
else
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Final balance of reserve `%s' is %s, no need to remember it\n",
- TALER_B2S (&rs->reserve_pub),
- TALER_amount2s (&nbalance));
+ "Final balance of reserve `%s' is zero, no need to remember it\n",
+ TALER_B2S (&rs->reserve_pub));
}
}
else
@@ -1220,20 +1559,16 @@ verify_reserve_balance (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Remembering final balance of reserve `%s' as %s\n",
TALER_B2S (&rs->reserve_pub),
- TALER_amount2s (&nbalance));
+ TALER_amount2s (&rs->prev_balance.reserve_balance));
if (rs->had_ri)
qs = TALER_ARL_adb->update_reserve_info (TALER_ARL_adb->cls,
&rs->reserve_pub,
- &TALER_ARL_master_pub,
- &nbalance,
- &rs->a_withdraw_fee_balance,
+ &rs->prev_balance,
rs->a_expiration_date);
else
qs = TALER_ARL_adb->insert_reserve_info (TALER_ARL_adb->cls,
&rs->reserve_pub,
- &TALER_ARL_master_pub,
- &nbalance,
- &rs->a_withdraw_fee_balance,
+ &rs->prev_balance,
rs->a_expiration_date,
rs->sender_account);
if (0 >= qs)
@@ -1243,7 +1578,7 @@ verify_reserve_balance (void *cls,
rc->qs = qs;
}
}
-
+ /* now we can discard the cached entry */
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_remove (rc->reserves,
key,
@@ -1255,426 +1590,6 @@ verify_reserve_balance (void *cls,
/**
- * Function called with details about purse deposits that have been made, with
- * the goal of auditing the deposit's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param deposit deposit details
- * @param reserve_pub which reserve is the purse merged into, NULL if unknown
- * @param flags purse flags
- * @param auditor_balance purse balance (according to the
- * auditor during auditing)
- * @param purse_total target amount the purse should reach
- * @param denom_pub denomination public key of @a coin_pub
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-static enum GNUNET_GenericReturnValue
-handle_purse_deposits (
- void *cls,
- uint64_t rowid,
- const struct TALER_EXCHANGEDB_PurseDeposit *deposit,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- enum TALER_WalletAccountMergeFlags flags,
- const struct TALER_Amount *auditor_balance,
- const struct TALER_Amount *purse_total,
- const struct TALER_DenominationPublicKey *denom_pub)
-{
- struct ReserveContext *rc = cls;
- const char *base_url
- = (NULL == deposit->exchange_base_url)
- ? TALER_ARL_exchange_url
- : deposit->exchange_base_url;
- enum GNUNET_DB_QueryStatus qs;
- struct TALER_Amount amount_minus_fee;
- struct TALER_Amount new_balance;
- struct ReserveSummary *rs;
- struct TALER_DenominationHashP h_denom_pub;
-
- /* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_purse_deposits_serial_id);
- ppr.last_purse_deposits_serial_id = rowid + 1;
-
- {
- const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue;
- enum GNUNET_DB_QueryStatus qs;
-
- qs = TALER_ARL_get_denomination_info (denom_pub,
- &issue,
- &h_denom_pub);
- if (0 > qs)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- if (GNUNET_DB_STATUS_HARD_ERROR == qs)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Hard database error trying to get denomination %s from database!\n",
- TALER_B2S (denom_pub));
- rc->qs = qs;
- return GNUNET_SYSERR;
- }
- if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
- {
- report_row_inconsistency ("purse-deposit",
- rowid,
- "denomination key not found");
- if (TALER_ARL_do_abort ())
- return GNUNET_SYSERR;
- return GNUNET_OK;
- }
- TALER_ARL_amount_subtract (&amount_minus_fee,
- &deposit->amount,
- &issue->fees.deposit);
- }
-
- if (GNUNET_OK !=
- TALER_wallet_purse_deposit_verify (base_url,
- &deposit->purse_pub,
- &deposit->amount,
- &h_denom_pub,
- &deposit->h_age_commitment,
- &deposit->coin_pub,
- &deposit->coin_sig))
- {
- TALER_ARL_report (report_bad_sig_losses,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("operation",
- "purse-deposit"),
- GNUNET_JSON_pack_uint64 ("row",
- rowid),
- TALER_JSON_pack_amount ("loss",
- &deposit->amount),
- GNUNET_JSON_pack_data_auto ("key_pub",
- &deposit->coin_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
- &deposit->amount);
- return GNUNET_OK;
- }
-
- TALER_ARL_amount_add (&new_balance,
- auditor_balance,
- &amount_minus_fee);
- qs = TALER_ARL_edb->set_purse_balance (TALER_ARL_edb->cls,
- &deposit->purse_pub,
- &new_balance);
- GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs);
- if (qs < 0)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
- rc->qs = qs;
- return GNUNET_SYSERR;
- }
- if (TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE !=
- (flags & TALER_WAMF_MERGE_MODE_MASK))
- {
- /* This just created the purse, actual credit to
- the reserve will be done in handle_account_merged() */
- return GNUNET_OK;
- }
- if ( (NULL != deposit->exchange_base_url) &&
- (0 != strcmp (deposit->exchange_base_url,
- TALER_ARL_exchange_url)) )
- {
- /* credited reserve is at another exchange, do NOT credit here! */
- return GNUNET_OK;
- }
-
- rs = setup_reserve (rc,
- reserve_pub);
- if (NULL == rs)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- if ( (-1 != TALER_amount_cmp (&new_balance,
- purse_total)) &&
- (-1 == TALER_amount_cmp (auditor_balance,
- purse_total)) )
- {
- /* new balance at or above purse_total
- (and previous balance was below); thus
- credit reserve with purse value! */
- TALER_ARL_amount_add (&rs->total_in,
- &rs->total_in,
- purse_total);
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Function called with details about purse
- * merges that have been made, with
- * the goal of auditing the purse merge execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param partner_base_url where is the reserve, NULL for this exchange
- * @param amount total amount expected in the purse
- * @param balance current balance in the purse (according to the auditor)
- * @param flags purse flags
- * @param merge_pub merge capability key
- * @param reserve_pub reserve the merge affects
- * @param merge_sig signature affirming the merge
- * @param purse_pub purse key
- * @param merge_timestamp when did the merge happen
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-static enum GNUNET_GenericReturnValue
-handle_purse_merged (
- void *cls,
- uint64_t rowid,
- const char *partner_base_url,
- const struct TALER_Amount *amount,
- const struct TALER_Amount *balance,
- enum TALER_WalletAccountMergeFlags flags,
- const struct TALER_PurseMergePublicKeyP *merge_pub,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_PurseMergeSignatureP *merge_sig,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- struct GNUNET_TIME_Timestamp merge_timestamp)
-{
- struct ReserveContext *rc = cls;
- struct ReserveSummary *rs;
- char *reserve_url;
-
- /* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_purse_merges_serial_id);
- ppr.last_purse_merges_serial_id = rowid + 1;
- reserve_url
- = TALER_reserve_make_payto (NULL == partner_base_url
- ? TALER_ARL_exchange_url
- : partner_base_url,
- reserve_pub);
- if (GNUNET_OK !=
- TALER_wallet_purse_merge_verify (reserve_url,
- merge_timestamp,
- purse_pub,
- merge_pub,
- merge_sig))
- {
- GNUNET_free (reserve_url);
- TALER_ARL_report (report_bad_sig_losses,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("operation",
- "merge-purse"),
- GNUNET_JSON_pack_uint64 ("row",
- rowid),
- TALER_JSON_pack_amount ("loss",
- amount),
- GNUNET_JSON_pack_data_auto ("key_pub",
- merge_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
- amount);
- return GNUNET_OK;
- }
- GNUNET_free (reserve_url);
- if (TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE ==
- (flags & TALER_WAMF_MERGE_MODE_MASK))
- {
- /* This just created the purse, actual credit to
- the reserve will be done in handle_purse_deposits() */
- return GNUNET_OK;
- }
- if ( (NULL != partner_base_url) &&
- (0 != strcmp (partner_base_url,
- TALER_ARL_exchange_url)) )
- {
- /* credited reserve is at another exchange, do NOT credit here! */
- return GNUNET_OK;
- }
- rs = setup_reserve (rc,
- reserve_pub);
- if (NULL == rs)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- if (-1 == TALER_amount_cmp (balance,
- amount))
- {
- struct TALER_Amount loss;
-
- TALER_ARL_amount_subtract (&loss,
- amount,
- balance);
- /* illegal merge, balance is still below total purse value */
- TALER_ARL_report (report_purse_balance_insufficient_inconsistencies,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("operation",
- "merge-purse"),
- GNUNET_JSON_pack_uint64 ("row",
- rowid),
- TALER_JSON_pack_amount ("loss",
- &loss),
- GNUNET_JSON_pack_data_auto ("purse_pub",
- purse_pub)));
- TALER_ARL_amount_add (&total_balance_insufficient_loss,
- &total_balance_insufficient_loss,
- &loss);
- return GNUNET_OK;
- }
- TALER_ARL_amount_add (&rs->total_in,
- &rs->total_in,
- amount);
- // rs->a_expiration_date = FIXME: do we care? If so, set to what (so that the auditor no longer complains about the reserve not being closed)
- return GNUNET_OK;
-}
-
-
-/**
- * Function called with details about
- * account merge requests that have been made, with
- * the goal of auditing the account merge execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param reserve_pub reserve affected by the merge
- * @param purse_pub purse being merged
- * @param h_contract_terms hash over contract of the purse
- * @param purse_expiration when would the purse expire
- * @param amount total amount in the purse
- * @param min_age minimum age of all coins deposited into the purse
- * @param flags how was the purse created
- * @param purse_fee if a purse fee was paid, how high is it
- * @param merge_timestamp when was the merge approved
- * @param reserve_sig signature by reserve approving the merge
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-static enum GNUNET_GenericReturnValue
-handle_account_merged (
- void *cls,
- uint64_t rowid,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- struct GNUNET_TIME_Timestamp purse_expiration,
- const struct TALER_Amount *amount,
- uint32_t min_age,
- enum TALER_WalletAccountMergeFlags flags,
- const struct TALER_Amount *purse_fee,
- struct GNUNET_TIME_Timestamp merge_timestamp,
- const struct TALER_ReserveSignatureP *reserve_sig)
-{
- struct ReserveContext *rc = cls;
- struct ReserveSummary *rs;
-
- /* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_account_merges_serial_id);
- ppr.last_account_merges_serial_id = rowid + 1;
- if (GNUNET_OK !=
- TALER_wallet_account_merge_verify (merge_timestamp,
- purse_pub,
- purse_expiration,
- h_contract_terms,
- amount,
- purse_fee,
- min_age,
- flags,
- reserve_pub,
- reserve_sig))
- {
- TALER_ARL_report (report_bad_sig_losses,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("operation",
- "account-merge"),
- GNUNET_JSON_pack_uint64 ("row",
- rowid),
- TALER_JSON_pack_amount ("loss",
- purse_fee),
- GNUNET_JSON_pack_data_auto ("key_pub",
- reserve_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
- purse_fee);
- return GNUNET_OK;
- }
- rs = setup_reserve (rc,
- reserve_pub);
- if (NULL == rs)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- TALER_ARL_amount_add (&total_purse_fee_income,
- &total_purse_fee_income,
- purse_fee);
- TALER_ARL_amount_add (&rs->total_out,
- &rs->total_out,
- purse_fee);
- return GNUNET_OK;
-}
-
-
-/**
- * Function called with details about
- * history requests that have been made, with
- * the goal of auditing the history request execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param history_fee fee paid for the request
- * @param ts timestamp of the request
- * @param reserve_pub reserve history was requested for
- * @param reserve_sig signature approving the @a history_fee
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-static enum GNUNET_GenericReturnValue
-handle_history_request (
- void *cls,
- uint64_t rowid,
- const struct TALER_Amount *history_fee,
- const struct GNUNET_TIME_Timestamp ts,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_ReserveSignatureP *reserve_sig)
-{
- struct ReserveContext *rc = cls;
- struct ReserveSummary *rs;
-
- /* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_history_requests_serial_id);
- ppr.last_history_requests_serial_id = rowid + 1;
- if (GNUNET_OK !=
- TALER_wallet_reserve_history_verify (ts,
- history_fee,
- reserve_pub,
- reserve_sig))
- {
- TALER_ARL_report (report_bad_sig_losses,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("operation",
- "account-history"),
- GNUNET_JSON_pack_uint64 ("row",
- rowid),
- TALER_JSON_pack_amount ("loss",
- history_fee),
- GNUNET_JSON_pack_data_auto ("key_pub",
- reserve_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
- history_fee);
- return GNUNET_OK;
- }
- rs = setup_reserve (rc,
- reserve_pub);
- if (NULL == rs)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- TALER_ARL_amount_add (&total_history_fee_income,
- &total_history_fee_income,
- history_fee);
- TALER_ARL_amount_add (&rs->total_out,
- &rs->total_out,
- history_fee);
- return GNUNET_OK;
-}
-
-
-/**
* Analyze reserves for being well-formed.
*
* @param cls NULL
@@ -1691,9 +1606,17 @@ analyze_reserves (void *cls)
(void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Analyzing reserves\n");
- qsp = TALER_ARL_adb->get_auditor_progress_reserve (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppr);
+ qsp = 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),
+ TALER_ARL_GET_PP (reserves_reserve_recoup_serial_id),
+ TALER_ARL_GET_PP (reserves_reserve_open_serial_id),
+ TALER_ARL_GET_PP (reserves_reserve_close_serial_id),
+ TALER_ARL_GET_PP (reserves_purse_decisions_serial_id),
+ TALER_ARL_GET_PP (reserves_account_merges_serial_id),
+ TALER_ARL_GET_PP (reserves_history_requests_serial_id),
+ NULL);
if (0 > qsp)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsp);
@@ -1706,26 +1629,36 @@ analyze_reserves (void *cls)
}
else
{
- ppr_start = ppr;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Resuming reserve audit at %llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu\n",
- (unsigned long long) ppr.last_reserve_in_serial_id,
- (unsigned long long) ppr.last_reserve_out_serial_id,
- (unsigned long long) ppr.last_reserve_recoup_serial_id,
- (unsigned long long) ppr.last_reserve_close_serial_id,
- (unsigned long long) ppr.last_purse_merges_serial_id,
- (unsigned long long) ppr.last_purse_deposits_serial_id,
- (unsigned long long) ppr.last_account_merges_serial_id,
- (unsigned long long) ppr.last_history_requests_serial_id,
- (unsigned long long) ppr.last_close_requests_serial_id);
+ "Resuming reserve audit at %llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu\n",
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_in_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_out_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_recoup_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_open_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_close_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_purse_decisions_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_account_merges_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_history_requests_serial_id));
}
rc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
- qsx = TALER_ARL_adb->get_reserve_summary (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_escrow_balance,
- &total_withdraw_fee_income,
- &total_purse_fee_income,
- &total_history_fee_income);
+ qsx = TALER_ARL_adb->get_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_GET_AB (reserves_reserve_total_balance),
+ TALER_ARL_GET_AB (reserves_reserve_loss),
+ TALER_ARL_GET_AB (reserves_withdraw_fee_revenue),
+ TALER_ARL_GET_AB (reserves_close_fee_revenue),
+ TALER_ARL_GET_AB (reserves_purse_fee_revenue),
+ TALER_ARL_GET_AB (reserves_open_fee_revenue),
+ TALER_ARL_GET_AB (reserves_history_fee_revenue),
+ NULL);
if (qsx < 0)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx);
@@ -1735,10 +1668,9 @@ analyze_reserves (void *cls)
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,
- ppr.last_reserve_in_serial_id,
+ TALER_ARL_USE_PP (reserves_reserve_in_serial_id),
&handle_reserve_in,
&rc);
if (qs < 0)
@@ -1748,7 +1680,7 @@ analyze_reserves (void *cls)
}
qs = TALER_ARL_edb->select_withdrawals_above_serial_id (
TALER_ARL_edb->cls,
- ppr.last_reserve_out_serial_id,
+ TALER_ARL_USE_PP (reserves_reserve_out_serial_id),
&handle_reserve_out,
&rc);
if (qs < 0)
@@ -1758,7 +1690,7 @@ analyze_reserves (void *cls)
}
qs = TALER_ARL_edb->select_recoup_above_serial_id (
TALER_ARL_edb->cls,
- ppr.last_reserve_recoup_serial_id,
+ TALER_ARL_USE_PP (reserves_reserve_recoup_serial_id),
&handle_recoup_by_reserve,
&rc);
if (qs < 0)
@@ -1766,72 +1698,51 @@ 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,
- ppr.last_reserve_close_serial_id,
- &handle_reserve_closed,
- &rc);
- if (qs < 0)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- return qs;
- }
- qs = TALER_ARL_edb->select_purse_deposits_above_serial_id (
- TALER_ARL_edb->cls,
- ppr.last_purse_deposits_serial_id,
- &handle_purse_deposits,
- &rc);
- if (qs < 0)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- return qs;
- }
- /* Charge purse fee! */
- qs = TALER_ARL_edb->select_account_merges_above_serial_id (
+ qs = TALER_ARL_edb->select_reserve_open_above_serial_id (
TALER_ARL_edb->cls,
- ppr.last_account_merges_serial_id,
- &handle_account_merged,
+ TALER_ARL_USE_PP (reserves_reserve_open_serial_id),
+ &handle_reserve_open,
&rc);
if (qs < 0)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
- /* Credit purse value (if last op)! */
- qs = TALER_ARL_edb->select_purse_merges_above_serial_id (
+ qs = TALER_ARL_edb->select_reserve_closed_above_serial_id (
TALER_ARL_edb->cls,
- ppr.last_purse_merges_serial_id,
- &handle_purse_merged,
+ TALER_ARL_USE_PP (reserves_reserve_close_serial_id),
+ &handle_reserve_closed,
&rc);
if (qs < 0)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
- /* Charge history fee! */
- qs = TALER_ARL_edb->select_history_requests_above_serial_id (
- TALER_ARL_edb->cls,
- ppr.last_history_requests_serial_id,
- &handle_history_request,
- &rc);
- if (qs < 0)
+ /* process purse_decisions (to credit reserve) */
+ if (0 >
+ (qs = TALER_ARL_edb->select_purse_decisions_above_serial_id (
+ TALER_ARL_edb->cls,
+ TALER_ARL_USE_PP (reserves_purse_decisions_serial_id),
+ false, /* only go for merged purses! */
+ &purse_decision_cb,
+ &rc)))
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
-#if 0
- /* FIXME #7269 (support for explicit reserve closure request) */
- qs = TALER_ARL_edb->select_close_requests_above_serial_id (
+ if (0 > rc.qs)
+ return rc.qs;
+ /* Charge purse fee! */
+ qs = TALER_ARL_edb->select_account_merges_above_serial_id (
TALER_ARL_edb->cls,
- ppr.last_close_requests_serial_id,
- &handle_close_request,
+ TALER_ARL_USE_PP (reserves_account_merges_serial_id),
+ &handle_account_merged,
&rc);
if (qs < 0)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
-#endif
GNUNET_CONTAINER_multihashmap_iterate (rc.reserves,
&verify_reserve_balance,
&rc);
@@ -1839,27 +1750,33 @@ analyze_reserves (void *cls)
GNUNET_CONTAINER_multihashmap_size (rc.reserves));
GNUNET_CONTAINER_multihashmap_destroy (rc.reserves);
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_reserve_summary (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_escrow_balance,
- &total_withdraw_fee_income,
- &total_purse_fee_income,
- &total_history_fee_income);
+ 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),
+ NULL);
}
else
{
- qs = TALER_ARL_adb->update_reserve_summary (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_escrow_balance,
- &total_withdraw_fee_income,
- &total_purse_fee_income,
- &total_history_fee_income);
+ 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),
+ NULL);
}
if (0 >= qs)
{
@@ -1867,13 +1784,29 @@ analyze_reserves (void *cls)
return qs;
}
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp)
- qs = TALER_ARL_adb->update_auditor_progress_reserve (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppr);
+ 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);
else
- qs = TALER_ARL_adb->insert_auditor_progress_reserve (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppr);
+ 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_log (GNUNET_ERROR_TYPE_INFO,
@@ -1882,16 +1815,23 @@ analyze_reserves (void *cls)
return qs;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Concluded reserve audit step at %llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu\n",
- (unsigned long long) ppr.last_reserve_in_serial_id,
- (unsigned long long) ppr.last_reserve_out_serial_id,
- (unsigned long long) ppr.last_reserve_recoup_serial_id,
- (unsigned long long) ppr.last_reserve_close_serial_id,
- (unsigned long long) ppr.last_purse_merges_serial_id,
- (unsigned long long) ppr.last_purse_deposits_serial_id,
- (unsigned long long) ppr.last_account_merges_serial_id,
- (unsigned long long) ppr.last_history_requests_serial_id,
- (unsigned long long) ppr.last_close_requests_serial_id);
+ "Concluded reserve audit step at %llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu\n",
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_in_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_out_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_recoup_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_open_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_close_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_purse_decisions_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_account_merges_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_history_requests_serial_id));
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
}
@@ -1937,22 +1877,33 @@ run (void *cls,
"Starting audit\n");
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_escrow_balance));
+ &TALER_ARL_USE_AB (
+ reserves_reserve_total_balance)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_irregular_recoups));
+ &TALER_ARL_USE_AB (
+ reserves_reserve_loss)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_withdraw_fee_income));
+ &TALER_ARL_USE_AB (
+ reserves_withdraw_fee_revenue)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_history_fee_income));
+ &TALER_ARL_USE_AB (
+ reserves_close_fee_revenue)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_purse_fee_income));
+ &TALER_ARL_USE_AB (
+ reserves_purse_fee_revenue)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_balance_insufficient_loss));
+ &TALER_ARL_USE_AB (
+ reserves_open_fee_revenue)));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &TALER_ARL_USE_AB (
+ reserves_history_fee_revenue)));
+ // REVIEW:
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
&total_balance_summary_delta_plus));
@@ -1971,6 +1922,7 @@ run (void *cls,
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
&total_bad_sig_loss));
+
GNUNET_assert (NULL !=
(report_row_inconsistencies = json_array ()));
GNUNET_assert (NULL !=
@@ -2002,15 +1954,6 @@ run (void *cls,
}
TALER_ARL_done (
GNUNET_JSON_PACK (
- GNUNET_JSON_pack_array_steal (
- "reserve_balance_insufficient_inconsistencies",
- report_reserve_balance_insufficient_inconsistencies),
- GNUNET_JSON_pack_array_steal (
- "purse_balance_insufficient_inconsistencies",
- report_purse_balance_insufficient_inconsistencies),
- /* Tested in test-auditor.sh #3 */
- TALER_JSON_pack_amount ("total_loss_balance_insufficient",
- &total_balance_insufficient_loss),
/* Tested in test-auditor.sh #3 */
GNUNET_JSON_pack_array_steal (
"reserve_balance_summary_wrong_inconsistencies",
@@ -2019,26 +1962,49 @@ run (void *cls,
&total_balance_summary_delta_plus),
TALER_JSON_pack_amount ("total_balance_summary_delta_minus",
&total_balance_summary_delta_minus),
+ /* Tested in test-auditor.sh #21 */
+ TALER_JSON_pack_amount ("total_balance_reserve_not_closed",
+ &total_balance_reserve_not_closed),
+ /* Tested in test-auditor.sh #7 */
+ TALER_JSON_pack_amount ("total_bad_sig_loss",
+ &total_bad_sig_loss),
+ TALER_JSON_pack_amount ("total_arithmetic_delta_plus",
+ &total_arithmetic_delta_plus),
+ TALER_JSON_pack_amount ("total_arithmetic_delta_minus",
+ &total_arithmetic_delta_minus),
+
+ /* Global 'balances' */
TALER_JSON_pack_amount ("total_escrow_balance",
- &total_escrow_balance),
+ &TALER_ARL_USE_AB (
+ reserves_reserve_total_balance)),
+ /* Tested in test-auditor.sh #3 */
+ TALER_JSON_pack_amount ("total_irregular_loss",
+ &TALER_ARL_USE_AB (reserves_reserve_loss)),
TALER_JSON_pack_amount ("total_withdraw_fee_income",
- &total_withdraw_fee_income),
- TALER_JSON_pack_amount ("total_history_fee_income",
- &total_history_fee_income),
+ &TALER_ARL_USE_AB (
+ reserves_withdraw_fee_revenue)),
+ TALER_JSON_pack_amount ("total_close_fee_income",
+ &TALER_ARL_USE_AB (reserves_close_fee_revenue)),
TALER_JSON_pack_amount ("total_purse_fee_income",
- &total_purse_fee_income),
+ &TALER_ARL_USE_AB (reserves_purse_fee_revenue)),
+ TALER_JSON_pack_amount ("total_open_fee_income",
+ &TALER_ARL_USE_AB (reserves_open_fee_revenue)),
+ TALER_JSON_pack_amount ("total_history_fee_income",
+ &TALER_ARL_USE_AB (reserves_history_fee_revenue)),
+
+ /* Detailed report tables */
+ GNUNET_JSON_pack_array_steal (
+ "reserve_balance_insufficient_inconsistencies",
+ report_reserve_balance_insufficient_inconsistencies),
+ GNUNET_JSON_pack_array_steal (
+ "purse_balance_insufficient_inconsistencies",
+ report_purse_balance_insufficient_inconsistencies),
/* Tested in test-auditor.sh #21 */
GNUNET_JSON_pack_array_steal ("reserve_not_closed_inconsistencies",
report_reserve_not_closed_inconsistencies),
- /* Tested in test-auditor.sh #21 */
- TALER_JSON_pack_amount ("total_balance_reserve_not_closed",
- &total_balance_reserve_not_closed),
/* Tested in test-auditor.sh #7 */
GNUNET_JSON_pack_array_steal ("bad_sig_losses",
report_bad_sig_losses),
- /* Tested in test-auditor.sh #7 */
- TALER_JSON_pack_amount ("total_bad_sig_loss",
- &total_bad_sig_loss),
/* Tested in test-revocation.sh #4 */
GNUNET_JSON_pack_array_steal ("row_inconsistencies",
report_row_inconsistencies),
@@ -2048,42 +2014,52 @@ run (void *cls,
denomination_key_validity_withdraw_inconsistencies),
GNUNET_JSON_pack_array_steal ("amount_arithmetic_inconsistencies",
report_amount_arithmetic_inconsistencies),
- TALER_JSON_pack_amount ("total_arithmetic_delta_plus",
- &total_arithmetic_delta_plus),
- TALER_JSON_pack_amount ("total_arithmetic_delta_minus",
- &total_arithmetic_delta_minus),
+
+ /* Information about audited range ... */
TALER_JSON_pack_time_abs_human ("auditor_start_time",
start_time),
TALER_JSON_pack_time_abs_human ("auditor_end_time",
GNUNET_TIME_absolute_get ()),
- TALER_JSON_pack_amount ("total_irregular_recoups",
- &total_irregular_recoups),
GNUNET_JSON_pack_uint64 ("start_ppr_reserve_in_serial_id",
- ppr_start.last_reserve_in_serial_id),
+ 0 /* no longer supported */),
GNUNET_JSON_pack_uint64 ("start_ppr_reserve_out_serial_id",
- ppr_start.last_reserve_out_serial_id),
+ 0 /* no longer supported */),
GNUNET_JSON_pack_uint64 ("start_ppr_reserve_recoup_serial_id",
- ppr_start.last_reserve_recoup_serial_id),
+ 0 /* no longer supported */),
+ GNUNET_JSON_pack_uint64 ("start_ppr_reserve_open_serial_id",
+ 0 /* no longer supported */),
GNUNET_JSON_pack_uint64 ("start_ppr_reserve_close_serial_id",
- ppr_start.last_reserve_close_serial_id),
+ 0 /* no longer supported */),
+ GNUNET_JSON_pack_uint64 ("start_ppr_purse_decisions_serial_id",
+ 0 /* no longer supported */),
+ GNUNET_JSON_pack_uint64 ("start_ppr_account_merges_serial_id",
+ 0 /* no longer supported */),
+ GNUNET_JSON_pack_uint64 ("start_ppr_history_requests_serial_id",
+ 0 /* no longer supported */),
GNUNET_JSON_pack_uint64 ("end_ppr_reserve_in_serial_id",
- ppr.last_reserve_in_serial_id),
+ TALER_ARL_USE_PP (
+ reserves_reserve_in_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppr_reserve_out_serial_id",
- ppr.last_reserve_out_serial_id),
+ TALER_ARL_USE_PP (
+ reserves_reserve_out_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppr_reserve_recoup_serial_id",
- ppr.last_reserve_recoup_serial_id),
+ TALER_ARL_USE_PP (
+ reserves_reserve_recoup_serial_id)),
+ GNUNET_JSON_pack_uint64 ("end_ppr_reserve_open_serial_id",
+ TALER_ARL_USE_PP (
+ reserves_reserve_open_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppr_reserve_close_serial_id",
- ppr.last_reserve_close_serial_id),
- GNUNET_JSON_pack_uint64 ("end_ppr_purse_merges_serial_id",
- ppr.last_purse_merges_serial_id),
- GNUNET_JSON_pack_uint64 ("end_ppr_purse_deposits_serial_id",
- ppr.last_purse_deposits_serial_id),
+ TALER_ARL_USE_PP (
+ reserves_reserve_close_serial_id)),
+ GNUNET_JSON_pack_uint64 ("end_ppr_purse_decisions_serial_id",
+ TALER_ARL_USE_PP (
+ reserves_purse_decisions_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppr_account_merges_serial_id",
- ppr.last_account_merges_serial_id),
+ TALER_ARL_USE_PP (
+ reserves_account_merges_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppr_history_requests_serial_id",
- ppr.last_history_requests_serial_id),
- GNUNET_JSON_pack_uint64 ("end_ppr_close_requests_serial_id",
- ppr.last_close_requests_serial_id)));
+ TALER_ARL_USE_PP (
+ reserves_history_requests_serial_id))));
}
@@ -2103,11 +2079,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