rename fest on refactored auditor logic

This commit is contained in:
Christian Grothoff 2020-03-21 11:05:51 +01:00
parent 66616a97d7
commit 2ace9969b7
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
10 changed files with 1519 additions and 1516 deletions

View File

@ -13,3 +13,8 @@ test-wire-audit-inc.json
wirefees/ wirefees/
bank.err bank.err
libauditor.a libauditor.a
taler-helper-auditor-aggregation
taler-helper-auditor-coins
taler-helper-auditor-deposits
taler-helper-auditor-reserves
taler-helper-auditor-wire

View File

@ -13,11 +13,11 @@ pkgcfg_DATA = \
bin_PROGRAMS = \ bin_PROGRAMS = \
taler-auditor \ taler-auditor \
taler-auditor-reserves \ taler-helper-auditor-reserves \
taler-auditor-coins \ taler-helper-auditor-coins \
taler-auditor-aggregation \ taler-helper-auditor-aggregation \
taler-auditor-deposits \ taler-helper-auditor-deposits \
taler-wire-auditor \ taler-helper-auditor-wire \
taler-auditor-exchange \ taler-auditor-exchange \
taler-auditor-httpd \ taler-auditor-httpd \
taler-auditor-sign \ taler-auditor-sign \
@ -44,9 +44,9 @@ taler_auditor_dbinit_CPPFLAGS = \
-I$(top_srcdir)/src/pq/ \ -I$(top_srcdir)/src/pq/ \
$(POSTGRESQL_CPPFLAGS) $(POSTGRESQL_CPPFLAGS)
taler_auditor_reserves_SOURCES = \ taler_helper_auditor_reserves_SOURCES = \
taler-auditor-reserves.c taler-helper-auditor-reserves.c
taler_auditor_reserves_LDADD = \ taler_helper_auditor_reserves_LDADD = \
$(LIBGCRYPT_LIBS) \ $(LIBGCRYPT_LIBS) \
$(top_builddir)/src/util/libtalerutil.la \ $(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/json/libtalerjson.la \ $(top_builddir)/src/json/libtalerjson.la \
@ -58,9 +58,9 @@ taler_auditor_reserves_LDADD = \
-lgnunetjson \ -lgnunetjson \
-lgnunetutil -lgnunetutil
taler_auditor_coins_SOURCES = \ taler_helper_auditor_coins_SOURCES = \
taler-auditor-coins.c taler-helper-auditor-coins.c
taler_auditor_coins_LDADD = \ taler_helper_auditor_coins_LDADD = \
$(LIBGCRYPT_LIBS) \ $(LIBGCRYPT_LIBS) \
$(top_builddir)/src/util/libtalerutil.la \ $(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/json/libtalerjson.la \ $(top_builddir)/src/json/libtalerjson.la \
@ -72,9 +72,9 @@ taler_auditor_coins_LDADD = \
-lgnunetjson \ -lgnunetjson \
-lgnunetutil -lgnunetutil
taler_auditor_aggregation_SOURCES = \ taler_helper_auditor_aggregation_SOURCES = \
taler-auditor-aggregation.c taler-helper-auditor-aggregation.c
taler_auditor_aggregation_LDADD = \ taler_helper_auditor_aggregation_LDADD = \
$(LIBGCRYPT_LIBS) \ $(LIBGCRYPT_LIBS) \
$(top_builddir)/src/util/libtalerutil.la \ $(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/json/libtalerjson.la \ $(top_builddir)/src/json/libtalerjson.la \
@ -86,9 +86,9 @@ taler_auditor_aggregation_LDADD = \
-lgnunetjson \ -lgnunetjson \
-lgnunetutil -lgnunetutil
taler_auditor_deposits_SOURCES = \ taler_helper_auditor_deposits_SOURCES = \
taler-auditor-deposits.c taler-helper-auditor-deposits.c
taler_auditor_deposits_LDADD = \ taler_helper_auditor_deposits_LDADD = \
$(LIBGCRYPT_LIBS) \ $(LIBGCRYPT_LIBS) \
$(top_builddir)/src/util/libtalerutil.la \ $(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/json/libtalerjson.la \ $(top_builddir)/src/json/libtalerjson.la \
@ -100,6 +100,22 @@ taler_auditor_deposits_LDADD = \
-lgnunetjson \ -lgnunetjson \
-lgnunetutil -lgnunetutil
taler_helper_auditor_wire_SOURCES = \
taler-helper-auditor-wire.c
taler_helper_auditor_wire_LDADD = \
$(LIBGCRYPT_LIBS) \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/bank-lib/libtalerbank.la \
$(top_builddir)/src/exchangedb/libtalerexchangedb.la \
$(top_builddir)/src/auditordb/libtalerauditordb.la \
libauditor.a \
-ljansson \
-lgnunetjson \
-lgnunetcurl \
-lgnunetutil
taler_auditor_SOURCES = \ taler_auditor_SOURCES = \
taler-auditor.c taler-auditor.c
taler_auditor_LDADD = \ taler_auditor_LDADD = \
@ -131,20 +147,6 @@ taler_auditor_httpd_LDADD = \
-lgnunetutil \ -lgnunetutil \
-lz -lz
taler_wire_auditor_SOURCES = \
taler-wire-auditor.c
taler_wire_auditor_LDADD = \
$(LIBGCRYPT_LIBS) \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/bank-lib/libtalerbank.la \
$(top_builddir)/src/exchangedb/libtalerexchangedb.la \
$(top_builddir)/src/auditordb/libtalerauditordb.la \
-ljansson \
-lgnunetjson \
-lgnunetcurl \
-lgnunetutil
taler_auditor_sign_SOURCES = \ taler_auditor_sign_SOURCES = \
taler-auditor-sign.c taler-auditor-sign.c
taler_auditor_sign_LDADD = \ taler_auditor_sign_LDADD = \

View File

@ -22,49 +22,49 @@
#include "report-lib.h" #include "report-lib.h"
/** /**
* Command-line option "-r": restart audit from scratch * Command-line option "-r": TALER_ARL_restart audit from scratch
*/ */
int restart; int TALER_ARL_restart;
/** /**
* Handle to access the exchange's database. * Handle to access the exchange's database.
*/ */
struct TALER_EXCHANGEDB_Plugin *edb; struct TALER_EXCHANGEDB_Plugin *TALER_ARL_edb;
/** /**
* Which currency are we doing the audit for? * Which TALER_ARL_currency are we doing the audit for?
*/ */
char *currency; char *TALER_ARL_currency;
/** /**
* How many fractional digits does the currency use? * How many fractional digits does the TALER_ARL_currency use?
*/ */
struct TALER_Amount currency_round_unit; struct TALER_Amount TALER_ARL_currency_round_unit;
/** /**
* Our configuration. * Our configuration.
*/ */
const struct GNUNET_CONFIGURATION_Handle *cfg; const struct GNUNET_CONFIGURATION_Handle *TALER_ARL_cfg;
/** /**
* Our session with the #edb. * Our session with the #TALER_ARL_edb.
*/ */
struct TALER_EXCHANGEDB_Session *esession; struct TALER_EXCHANGEDB_Session *TALER_ARL_esession;
/** /**
* Handle to access the auditor's database. * Handle to access the auditor's database.
*/ */
struct TALER_AUDITORDB_Plugin *adb; struct TALER_AUDITORDB_Plugin *TALER_ARL_adb;
/** /**
* Our session with the #adb. * Our session with the #TALER_ARL_adb.
*/ */
struct TALER_AUDITORDB_Session *asession; struct TALER_AUDITORDB_Session *TALER_ARL_asession;
/** /**
* Master public key of the exchange to audit. * Master public key of the exchange to audit.
*/ */
struct TALER_MasterPublicKeyP master_pub; struct TALER_MasterPublicKeyP TALER_ARL_master_pub;
/** /**
* At what time did the auditor process start? * At what time did the auditor process start?
@ -85,7 +85,7 @@ static struct GNUNET_CONTAINER_MultiHashMap *denominations;
* @return human-readable string representing the time * @return human-readable string representing the time
*/ */
json_t * json_t *
json_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO at) TALER_ARL_TALER_ARL_json_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO at)
{ {
return json_string return json_string
(GNUNET_STRINGS_absolute_time_to_string (GNUNET_STRINGS_absolute_time_to_string
@ -100,7 +100,7 @@ json_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO at)
* @return human-readable string representing the time * @return human-readable string representing the time
*/ */
json_t * json_t *
json_from_time_abs (struct GNUNET_TIME_Absolute at) TALER_ARL_json_from_time_abs (struct GNUNET_TIME_Absolute at)
{ {
return json_string return json_string
(GNUNET_STRINGS_absolute_time_to_string (at)); (GNUNET_STRINGS_absolute_time_to_string (at));
@ -108,13 +108,13 @@ json_from_time_abs (struct GNUNET_TIME_Absolute at)
/** /**
* Add @a object to the report @a array. Fail hard if this fails. * Add @a object to the TALER_ARL_report @a array. Fail hard if this fails.
* *
* @param array report array to append @a object to * @param array TALER_ARL_report array to append @a object to
* @param object object to append, should be check that it is not NULL * @param object object to append, should be check that it is not NULL
*/ */
void void
report (json_t *array, TALER_ARL_report (json_t *array,
json_t *object) json_t *object)
{ {
GNUNET_assert (NULL != object); GNUNET_assert (NULL != object);
@ -185,7 +185,7 @@ add_denomination (void *cls,
* @return transaction status code * @return transaction status code
*/ */
enum GNUNET_DB_QueryStatus enum GNUNET_DB_QueryStatus
get_denomination_info_by_hash (const struct GNUNET_HashCode *dh, TALER_ARL_get_denomination_info_by_hash (const struct GNUNET_HashCode *dh,
const struct const struct
TALER_DenominationKeyValidityPS **issue) TALER_DenominationKeyValidityPS **issue)
{ {
@ -196,9 +196,9 @@ get_denomination_info_by_hash (const struct GNUNET_HashCode *dh,
{ {
denominations = GNUNET_CONTAINER_multihashmap_create (256, denominations = GNUNET_CONTAINER_multihashmap_create (256,
GNUNET_NO); GNUNET_NO);
qs = adb->select_denomination_info (adb->cls, qs = TALER_ARL_adb->select_denomination_info (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&add_denomination, &add_denomination,
NULL); NULL);
if (0 > qs) if (0 > qs)
@ -216,9 +216,9 @@ get_denomination_info_by_hash (const struct GNUNET_HashCode *dh,
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
} }
/* maybe database changed since we last iterated, give it one more shot */ /* maybe database changed since we last iterated, give it one more shot */
qs = adb->select_denomination_info (adb->cls, qs = TALER_ARL_adb->select_denomination_info (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&add_denomination, &add_denomination,
NULL); NULL);
if (qs <= 0) if (qs <= 0)
@ -255,7 +255,8 @@ get_denomination_info_by_hash (const struct GNUNET_HashCode *dh,
* @return transaction status code * @return transaction status code
*/ */
enum GNUNET_DB_QueryStatus enum GNUNET_DB_QueryStatus
get_denomination_info (const struct TALER_DenominationPublicKey *denom_pub, TALER_ARL_get_denomination_info (const struct
TALER_DenominationPublicKey *denom_pub,
const struct const struct
TALER_DenominationKeyValidityPS **issue, TALER_DenominationKeyValidityPS **issue,
struct GNUNET_HashCode *dh) struct GNUNET_HashCode *dh)
@ -266,7 +267,7 @@ get_denomination_info (const struct TALER_DenominationPublicKey *denom_pub,
dh = &hc; dh = &hc;
GNUNET_CRYPTO_rsa_public_key_hash (denom_pub->rsa_public_key, GNUNET_CRYPTO_rsa_public_key_hash (denom_pub->rsa_public_key,
dh); dh);
return get_denomination_info_by_hash (dh, return TALER_ARL_get_denomination_info_by_hash (dh,
issue); issue);
} }
@ -281,24 +282,24 @@ get_denomination_info (const struct TALER_DenominationPublicKey *denom_pub,
* #GNUNET_NO if we had an error on commit (retry may help) * #GNUNET_NO if we had an error on commit (retry may help)
* #GNUNET_SYSERR on hard errors * #GNUNET_SYSERR on hard errors
*/ */
int static int
transact (Analysis analysis, transact (TALER_ARL_Analysis analysis,
void *analysis_cls) void *analysis_cls)
{ {
int ret; int ret;
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
ret = adb->start (adb->cls, ret = TALER_ARL_adb->start (TALER_ARL_adb->cls,
asession); TALER_ARL_asession);
if (GNUNET_OK != ret) if (GNUNET_OK != ret)
{ {
GNUNET_break (0); GNUNET_break (0);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
edb->preflight (edb->cls, TALER_ARL_edb->preflight (TALER_ARL_edb->cls,
esession); TALER_ARL_esession);
ret = edb->start (edb->cls, ret = TALER_ARL_edb->start (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
"auditor"); "auditor");
if (GNUNET_OK != ret) if (GNUNET_OK != ret)
{ {
@ -308,20 +309,20 @@ transact (Analysis analysis,
qs = analysis (analysis_cls); qs = analysis (analysis_cls);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
{ {
qs = edb->commit (edb->cls, qs = TALER_ARL_edb->commit (TALER_ARL_edb->cls,
esession); TALER_ARL_esession);
if (0 > qs) if (0 > qs)
{ {
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Exchange DB commit failed, rolling back transaction\n"); "Exchange DB commit failed, rolling back transaction\n");
adb->rollback (adb->cls, TALER_ARL_adb->rollback (TALER_ARL_adb->cls,
asession); TALER_ARL_asession);
} }
else else
{ {
qs = adb->commit (adb->cls, qs = TALER_ARL_adb->commit (TALER_ARL_adb->cls,
asession); TALER_ARL_asession);
if (0 > qs) if (0 > qs)
{ {
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@ -334,10 +335,10 @@ transact (Analysis analysis,
{ {
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Processing failed (or no changes), rolling back transaction\n"); "Processing failed (or no changes), rolling back transaction\n");
adb->rollback (adb->cls, TALER_ARL_adb->rollback (TALER_ARL_adb->cls,
asession); TALER_ARL_asession);
edb->rollback (edb->cls, TALER_ARL_edb->rollback (TALER_ARL_edb->cls,
esession); TALER_ARL_esession);
} }
switch (qs) switch (qs)
{ {
@ -362,18 +363,18 @@ transact (Analysis analysis,
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
*/ */
int int
setup_sessions_and_run (Analysis ana, TALER_ARL_setup_sessions_and_run (TALER_ARL_Analysis ana,
void *ana_cls) void *ana_cls)
{ {
esession = edb->get_session (edb->cls); TALER_ARL_esession = TALER_ARL_edb->get_session (TALER_ARL_edb->cls);
if (NULL == esession) if (NULL == TALER_ARL_esession)
{ {
fprintf (stderr, fprintf (stderr,
"Failed to initialize exchange session.\n"); "Failed to initialize exchange session.\n");
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
asession = adb->get_session (adb->cls); TALER_ARL_asession = TALER_ARL_adb->get_session (TALER_ARL_adb->cls);
if (NULL == asession) if (NULL == TALER_ARL_asession)
{ {
fprintf (stderr, fprintf (stderr,
"Failed to initialize auditor session.\n"); "Failed to initialize auditor session.\n");
@ -388,7 +389,7 @@ setup_sessions_and_run (Analysis ana,
/** /**
* Test if the given @a mpub matches the #master_pub. * Test if the given @a mpub matches the #TALER_ARL_master_pub.
* If so, set "found" to GNUNET_YES. * If so, set "found" to GNUNET_YES.
* *
* @param cls a `int *` pointing to "found" * @param cls a `int *` pointing to "found"
@ -404,29 +405,35 @@ test_master_present (void *cls,
(void) exchange_url; (void) exchange_url;
if (0 == GNUNET_memcmp (mpub, if (0 == GNUNET_memcmp (mpub,
&master_pub)) &TALER_ARL_master_pub))
*found = GNUNET_YES; *found = GNUNET_YES;
} }
/**
* Setup global variables based on configuration.
*
* @param c configuration to use
* @return #GNUNET_OK on success
*/
int int
setup_globals (const struct GNUNET_CONFIGURATION_Handle *c) TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle *c)
{ {
int found; int found;
struct TALER_AUDITORDB_Session *as; struct TALER_AUDITORDB_Session *as;
cfg = c; TALER_ARL_cfg = c;
start_time = GNUNET_TIME_absolute_get (); start_time = GNUNET_TIME_absolute_get ();
if (0 == GNUNET_is_zero (&master_pub)) if (0 == GNUNET_is_zero (&TALER_ARL_master_pub))
{ {
/* -m option not given, try configuration */ /* -m option not given, try configuration */
char *master_public_key_str; char *TALER_ARL_master_public_key_str;
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, GNUNET_CONFIGURATION_get_value_string (TALER_ARL_cfg,
"exchange", "exchange",
"MASTER_PUBLIC_KEY", "MASTER_PUBLIC_KEY",
&master_public_key_str)) &TALER_ARL_master_public_key_str))
{ {
fprintf (stderr, fprintf (stderr,
"Pass option -m or set it in the configuration!\n"); "Pass option -m or set it in the configuration!\n");
@ -436,35 +443,37 @@ setup_globals (const struct GNUNET_CONFIGURATION_Handle *c)
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_public_key_from_string (master_public_key_str, GNUNET_CRYPTO_eddsa_public_key_from_string (
TALER_ARL_master_public_key_str,
strlen ( strlen (
master_public_key_str), TALER_ARL_master_public_key_str),
&master_pub.eddsa_pub)) &TALER_ARL_master_pub.
eddsa_pub))
{ {
fprintf (stderr, fprintf (stderr,
"Invalid master public key given in configuration file."); "Invalid master public key given in configuration file.");
GNUNET_free (master_public_key_str); GNUNET_free (TALER_ARL_master_public_key_str);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
GNUNET_free (master_public_key_str); GNUNET_free (TALER_ARL_master_public_key_str);
} /* end of -m not given */ } /* end of -m not given */
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Taler auditor running for exchange master public key %s\n", "Taler auditor running for exchange master public key %s\n",
TALER_B2S (&master_pub)); TALER_B2S (&TALER_ARL_master_pub));
if (GNUNET_OK != if (GNUNET_OK !=
TALER_config_get_currency (cfg, TALER_config_get_currency (TALER_ARL_cfg,
&currency)) &TALER_ARL_currency))
{ {
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
{ {
if (GNUNET_OK != if (GNUNET_OK !=
TALER_config_get_amount (cfg, TALER_config_get_amount (TALER_ARL_cfg,
"taler", "taler",
"CURRENCY_ROUND_UNIT", "CURRENCY_ROUND_UNIT",
&currency_round_unit)) &TALER_ARL_currency_round_unit))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Invalid or missing amount in `TALER' under `CURRENCY_ROUND_UNIT'\n"); "Invalid or missing amount in `TALER' under `CURRENCY_ROUND_UNIT'\n");
@ -472,31 +481,31 @@ setup_globals (const struct GNUNET_CONFIGURATION_Handle *c)
} }
} }
if (NULL == if (NULL ==
(edb = TALER_EXCHANGEDB_plugin_load (cfg))) (TALER_ARL_edb = TALER_EXCHANGEDB_plugin_load (TALER_ARL_cfg)))
{ {
fprintf (stderr, fprintf (stderr,
"Failed to initialize exchange database plugin.\n"); "Failed to initialize exchange database plugin.\n");
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (NULL == if (NULL ==
(adb = TALER_AUDITORDB_plugin_load (cfg))) (TALER_ARL_adb = TALER_AUDITORDB_plugin_load (TALER_ARL_cfg)))
{ {
fprintf (stderr, fprintf (stderr,
"Failed to initialize auditor database plugin.\n"); "Failed to initialize auditor database plugin.\n");
TALER_EXCHANGEDB_plugin_unload (edb); TALER_EXCHANGEDB_plugin_unload (TALER_ARL_edb);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
found = GNUNET_NO; found = GNUNET_NO;
as = adb->get_session (adb->cls); as = TALER_ARL_adb->get_session (TALER_ARL_adb->cls);
if (NULL == as) if (NULL == as)
{ {
fprintf (stderr, fprintf (stderr,
"Failed to start session with auditor database.\n"); "Failed to start session with auditor database.\n");
TALER_AUDITORDB_plugin_unload (adb); TALER_AUDITORDB_plugin_unload (TALER_ARL_adb);
TALER_EXCHANGEDB_plugin_unload (edb); TALER_EXCHANGEDB_plugin_unload (TALER_ARL_edb);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
(void) adb->list_exchanges (adb->cls, (void) TALER_ARL_adb->list_exchanges (TALER_ARL_adb->cls,
as, as,
&test_master_present, &test_master_present,
&found); &found);
@ -504,46 +513,54 @@ setup_globals (const struct GNUNET_CONFIGURATION_Handle *c)
{ {
fprintf (stderr, fprintf (stderr,
"Exchange's master public key `%s' not known to auditor DB. Did you forget to run `taler-auditor-exchange`?\n", "Exchange's master public key `%s' not known to auditor DB. Did you forget to run `taler-auditor-exchange`?\n",
GNUNET_p2s (&master_pub.eddsa_pub)); GNUNET_p2s (&TALER_ARL_master_pub.eddsa_pub));
TALER_AUDITORDB_plugin_unload (adb); TALER_AUDITORDB_plugin_unload (TALER_ARL_adb);
TALER_EXCHANGEDB_plugin_unload (edb); TALER_EXCHANGEDB_plugin_unload (TALER_ARL_edb);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (restart) if (TALER_ARL_restart)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Full audit restart requested, dropping old audit data.\n"); "Full audit TALER_ARL_restart requested, dropping old audit data.\n");
GNUNET_break (GNUNET_OK == GNUNET_break (GNUNET_OK ==
adb->drop_tables (adb->cls, TALER_ARL_adb->drop_tables (TALER_ARL_adb->cls,
GNUNET_NO)); GNUNET_NO));
TALER_AUDITORDB_plugin_unload (adb); TALER_AUDITORDB_plugin_unload (TALER_ARL_adb);
if (NULL == if (NULL ==
(adb = TALER_AUDITORDB_plugin_load (cfg))) (TALER_ARL_adb = TALER_AUDITORDB_plugin_load (TALER_ARL_cfg)))
{ {
fprintf (stderr, fprintf (stderr,
"Failed to initialize auditor database plugin after drop.\n"); "Failed to initialize auditor database plugin after drop.\n");
TALER_EXCHANGEDB_plugin_unload (edb); TALER_EXCHANGEDB_plugin_unload (TALER_ARL_edb);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
GNUNET_break (GNUNET_OK == GNUNET_break (GNUNET_OK ==
adb->create_tables (adb->cls)); TALER_ARL_adb->create_tables (TALER_ARL_adb->cls));
} }
return GNUNET_OK; return GNUNET_OK;
} }
/**
* Generate the report and close connectios to the database.
*
* @param report the report to output, may be NULL for no report
*/
void void
finish_report (json_t *report) TALER_ARL_done (json_t *report)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Audit complete\n"); "Audit complete\n");
TALER_AUDITORDB_plugin_unload (adb); TALER_AUDITORDB_plugin_unload (TALER_ARL_adb);
adb = NULL; TALER_ARL_adb = NULL;
TALER_EXCHANGEDB_plugin_unload (edb); TALER_EXCHANGEDB_plugin_unload (TALER_ARL_edb);
edb = NULL; TALER_ARL_edb = NULL;
if (NULL != report)
{
json_dumpf (report, json_dumpf (report,
stdout, stdout,
JSON_INDENT (2)); JSON_INDENT (2));
json_decref (report); json_decref (report);
} }
}

View File

@ -30,49 +30,49 @@
/** /**
* Command-line option "-r": restart audit from scratch * Command-line option "-r": TALER_ARL_restart audit from scratch
*/ */
extern int restart; extern int TALER_ARL_restart;
/** /**
* Handle to access the exchange's database. * Handle to access the exchange's database.
*/ */
extern struct TALER_EXCHANGEDB_Plugin *edb; extern struct TALER_EXCHANGEDB_Plugin *TALER_ARL_edb;
/** /**
* Which currency are we doing the audit for? * Which TALER_ARL_currency are we doing the audit for?
*/ */
extern char *currency; extern char *TALER_ARL_currency;
/** /**
* How many fractional digits does the currency use? * How many fractional digits does the TALER_ARL_currency use?
*/ */
extern struct TALER_Amount currency_round_unit; extern struct TALER_Amount TALER_ARL_currency_round_unit;
/** /**
* Our configuration. * Our configuration.
*/ */
extern const struct GNUNET_CONFIGURATION_Handle *cfg; extern const struct GNUNET_CONFIGURATION_Handle *TALER_ARL_cfg;
/** /**
* Our session with the #edb. * Our session with the #TALER_ARL_edb.
*/ */
extern struct TALER_EXCHANGEDB_Session *esession; extern struct TALER_EXCHANGEDB_Session *TALER_ARL_esession;
/** /**
* Handle to access the auditor's database. * Handle to access the auditor's database.
*/ */
extern struct TALER_AUDITORDB_Plugin *adb; extern struct TALER_AUDITORDB_Plugin *TALER_ARL_adb;
/** /**
* Our session with the #adb. * Our session with the #TALER_ARL_adb.
*/ */
extern struct TALER_AUDITORDB_Session *asession; extern struct TALER_AUDITORDB_Session *TALER_ARL_asession;
/** /**
* Master public key of the exchange to audit. * Master public key of the exchange to audit.
*/ */
extern struct TALER_MasterPublicKeyP master_pub; extern struct TALER_MasterPublicKeyP TALER_ARL_master_pub;
/** /**
* At what time did the auditor process start? * At what time did the auditor process start?
@ -87,7 +87,7 @@ extern struct GNUNET_TIME_Absolute start_time;
* @return human-readable string representing the time * @return human-readable string representing the time
*/ */
json_t * json_t *
json_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO at); TALER_ARL_TALER_ARL_json_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO at);
/** /**
@ -97,17 +97,17 @@ json_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO at);
* @return human-readable string representing the time * @return human-readable string representing the time
*/ */
json_t * json_t *
json_from_time_abs (struct GNUNET_TIME_Absolute at); TALER_ARL_json_from_time_abs (struct GNUNET_TIME_Absolute at);
/** /**
* Add @a object to the report @a array. Fail hard if this fails. * Add @a object to the TALER_ARL_report @a array. Fail hard if this fails.
* *
* @param array report array to append @a object to * @param array TALER_ARL_report array to append @a object to
* @param object object to append, should be check that it is not NULL * @param object object to append, should be check that it is not NULL
*/ */
void void
report (json_t *array, TALER_ARL_report (json_t *array,
json_t *object); json_t *object);
@ -117,10 +117,10 @@ report (json_t *array,
* @param dh hash of the denomination public key to look up * @param dh hash of the denomination public key to look up
* @param[out] issue set to detailed information about @a denom_pub, NULL if not found, must * @param[out] issue set to detailed information about @a denom_pub, NULL if not found, must
* NOT be freed by caller * NOT be freed by caller
* @return transaction status code * @return TALER_ARL_transaction status code
*/ */
enum GNUNET_DB_QueryStatus enum GNUNET_DB_QueryStatus
get_denomination_info_by_hash ( TALER_ARL_get_denomination_info_by_hash (
const struct GNUNET_HashCode *dh, const struct GNUNET_HashCode *dh,
const struct TALER_DenominationKeyValidityPS **issue); const struct TALER_DenominationKeyValidityPS **issue);
@ -132,14 +132,15 @@ get_denomination_info_by_hash (
* @param[out] issue set to detailed information about @a denom_pub, NULL if not found, must * @param[out] issue set to detailed information about @a denom_pub, NULL if not found, must
* NOT be freed by caller * NOT be freed by caller
* @param[out] dh set to the hash of @a denom_pub, may be NULL * @param[out] dh set to the hash of @a denom_pub, may be NULL
* @return transaction status code * @return TALER_ARL_transaction status code
*/ */
enum GNUNET_DB_QueryStatus enum GNUNET_DB_QueryStatus
get_denomination_info ( TALER_ARL_get_denomination_info (
const struct TALER_DenominationPublicKey *denom_pub, const struct TALER_DenominationPublicKey *denom_pub,
const struct TALER_DenominationKeyValidityPS **issue, const struct TALER_DenominationKeyValidityPS **issue,
struct GNUNET_HashCode *dh); struct GNUNET_HashCode *dh);
/** /**
* Type of an analysis function. Each analysis function runs in * Type of an analysis function. Each analysis function runs in
* its own transaction scope and must thus be internally consistent. * its own transaction scope and must thus be internally consistent.
@ -148,22 +149,7 @@ get_denomination_info (
* @return transaction status code * @return transaction status code
*/ */
typedef enum GNUNET_DB_QueryStatus typedef enum GNUNET_DB_QueryStatus
(*Analysis)(void *cls); (*TALER_ARL_Analysis)(void *cls);
/**
* Perform the given @a analysis within a transaction scope.
* Commit on success.
*
* @param analysis analysis to run
* @param analysis_cls closure for @a analysis
* @return #GNUNET_OK if @a analysis succeessfully committed,
* #GNUNET_NO if we had an error on commit (retry may help)
* #GNUNET_SYSERR on hard errors
*/
int
transact (Analysis analysis,
void *analysis_cls);
/** /**
@ -174,15 +160,26 @@ transact (Analysis analysis,
* @return #GNUNET_OK on success * @return #GNUNET_OK on success
*/ */
int int
setup_sessions_and_run (Analysis ana, TALER_ARL_setup_sessions_and_run (TALER_ARL_Analysis ana,
void *ana_cls); void *ana_cls);
/**
* Setup global variables based on configuration.
*
* @param c configuration to use
* @return #GNUNET_OK on success
*/
int int
setup_globals (const struct GNUNET_CONFIGURATION_Handle *c); TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle *c);
/**
* Generate the report and close connectios to the database.
*
* @param report the report to output, may be NULL for no report
*/
void void
finish_report (json_t *report); TALER_ARL_done (json_t *report);
#endif #endif

View File

@ -14,7 +14,7 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/ */
/** /**
* @file auditor/taler-auditor-aggregation.c * @file auditor/taler-helper-auditor-aggregation.c
* @brief audits an exchange's aggregations. * @brief audits an exchange's aggregations.
* @author Christian Grothoff * @author Christian Grothoff
*/ */
@ -133,8 +133,10 @@ static struct TALER_Amount total_bad_sig_loss;
static void static void
report_amount_arithmetic_inconsistency (const char *operation, report_amount_arithmetic_inconsistency (const char *operation,
uint64_t rowid, uint64_t rowid,
const struct TALER_Amount *exchange, const struct
const struct TALER_Amount *auditor, TALER_Amount *exchange,
const struct
TALER_Amount *auditor,
int profitable) int profitable)
{ {
struct TALER_Amount delta; struct TALER_Amount delta;
@ -158,7 +160,7 @@ report_amount_arithmetic_inconsistency (const char *operation,
auditor, auditor,
exchange)); exchange));
} }
report (report_amount_arithmetic_inconsistencies, TALER_ARL_report (report_amount_arithmetic_inconsistencies,
json_pack ("{s:s, s:I, s:o, s:o, s:I}", json_pack ("{s:s, s:I, s:o, s:o, s:I}",
"operation", operation, "operation", operation,
"rowid", (json_int_t) rowid, "rowid", (json_int_t) rowid,
@ -194,9 +196,12 @@ report_amount_arithmetic_inconsistency (const char *operation,
static void static void
report_coin_arithmetic_inconsistency (const char *operation, report_coin_arithmetic_inconsistency (const char *operation,
const struct const struct
TALER_CoinSpendPublicKeyP *coin_pub, TALER_CoinSpendPublicKeyP *
const struct TALER_Amount *exchange, coin_pub,
const struct TALER_Amount *auditor, const struct
TALER_Amount *exchange,
const struct
TALER_Amount *auditor,
int profitable) int profitable)
{ {
struct TALER_Amount delta; struct TALER_Amount delta;
@ -220,10 +225,11 @@ report_coin_arithmetic_inconsistency (const char *operation,
auditor, auditor,
exchange)); exchange));
} }
report (report_coin_inconsistencies, TALER_ARL_report (report_coin_inconsistencies,
json_pack ("{s:s, s:o, s:o, s:o, s:I}", json_pack ("{s:s, s:o, s:o, s:o, s:I}",
"operation", operation, "operation", operation,
"coin_pub", GNUNET_JSON_from_data_auto (coin_pub), "coin_pub", GNUNET_JSON_from_data_auto (
coin_pub),
"exchange", TALER_JSON_from_amount (exchange), "exchange", TALER_JSON_from_amount (exchange),
"auditor", TALER_JSON_from_amount (auditor), "auditor", TALER_JSON_from_amount (auditor),
"profitable", (json_int_t) profitable)); "profitable", (json_int_t) profitable));
@ -252,7 +258,7 @@ report_row_inconsistency (const char *table,
uint64_t rowid, uint64_t rowid,
const char *diagnostic) const char *diagnostic)
{ {
report (report_row_inconsistencies, TALER_ARL_report (report_row_inconsistencies,
json_pack ("{s:s, s:I, s:s}", json_pack ("{s:s, s:I, s:s}",
"table", table, "table", table,
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
@ -368,7 +374,7 @@ struct WireCheckContext
* the amounts for the aggregation table and checks that the total * the amounts for the aggregation table and checks that the total
* claimed coin value is within the value of the coin's denomination. * claimed coin value is within the value of the coin's denomination.
* *
* @param coin_pub public key of the coin (for reporting) * @param coin_pub public key of the coin (for TALER_ARL_reporting)
* @param h_contract_terms hash of the proposal for which we calculate the amount * @param h_contract_terms hash of the proposal for which we calculate the amount
* @param merchant_pub public key of the merchant (who is allowed to issue refunds) * @param merchant_pub public key of the merchant (who is allowed to issue refunds)
* @param issue denomination information about the coin * @param issue denomination information about the coin
@ -379,17 +385,24 @@ struct WireCheckContext
*/ */
static int static int
check_transaction_history_for_deposit (const struct check_transaction_history_for_deposit (const struct
TALER_CoinSpendPublicKeyP *coin_pub, TALER_CoinSpendPublicKeyP *
coin_pub,
const struct const struct
GNUNET_HashCode *h_contract_terms, GNUNET_HashCode *
h_contract_terms,
const struct const struct
TALER_MerchantPublicKeyP *merchant_pub, TALER_MerchantPublicKeyP *
merchant_pub,
const struct const struct
TALER_DenominationKeyValidityPS *issue, TALER_DenominationKeyValidityPS
*issue,
const struct const struct
TALER_EXCHANGEDB_TransactionList *tl_head, TALER_EXCHANGEDB_TransactionList
struct TALER_Amount *merchant_gain, *tl_head,
struct TALER_Amount *deposit_gain) struct TALER_Amount *
merchant_gain,
struct TALER_Amount *
deposit_gain)
{ {
struct TALER_Amount expenditures; struct TALER_Amount expenditures;
struct TALER_Amount refunds; struct TALER_Amount refunds;
@ -406,16 +419,16 @@ check_transaction_history_for_deposit (const struct
GNUNET_assert (NULL != tl_head); GNUNET_assert (NULL != tl_head);
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&expenditures)); &expenditures));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&refunds)); &refunds));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
merchant_gain)); merchant_gain));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&merchant_loss)); &merchant_loss));
/* Go over transaction history to compute totals; note that we do not /* Go over transaction history to compute totals; note that we do not
know the order, so instead of subtracting we compute positive know the order, so instead of subtracting we compute positive
@ -762,8 +775,8 @@ wire_transfer_information_cb (
} }
/* Obtain coin's transaction history */ /* Obtain coin's transaction history */
qs = edb->get_coin_transactions (edb->cls, qs = TALER_ARL_edb->get_coin_transactions (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
coin_pub, coin_pub,
GNUNET_YES, GNUNET_YES,
&tl); &tl);
@ -776,8 +789,8 @@ wire_transfer_information_cb (
"no transaction history for coin claimed in aggregation"); "no transaction history for coin claimed in aggregation");
return; return;
} }
qs = edb->get_known_coin (edb->cls, qs = TALER_ARL_edb->get_known_coin (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
coin_pub, coin_pub,
&coin); &coin);
if (qs < 0) if (qs < 0)
@ -790,12 +803,12 @@ wire_transfer_information_cb (
return; return;
} }
qs = get_denomination_info_by_hash (&coin.denom_pub_hash, qs = TALER_ARL_get_denomination_info_by_hash (&coin.denom_pub_hash,
&issue); &issue);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{ {
GNUNET_CRYPTO_rsa_signature_free (coin.denom_sig.rsa_signature); GNUNET_CRYPTO_rsa_signature_free (coin.denom_sig.rsa_signature);
edb->free_coin_transaction_list (edb->cls, TALER_ARL_edb->free_coin_transaction_list (TALER_ARL_edb->cls,
tl); tl);
if (0 == qs) if (0 == qs)
report_row_inconsistency ("aggregation", report_row_inconsistency ("aggregation",
@ -809,7 +822,7 @@ wire_transfer_information_cb (
TALER_test_coin_valid (&coin, TALER_test_coin_valid (&coin,
denom_pub)) denom_pub))
{ {
report (report_bad_sig_losses, TALER_ARL_report (report_bad_sig_losses,
json_pack ("{s:s, s:I, s:o, s:o}", json_pack ("{s:s, s:I, s:o, s:o}",
"operation", "wire", "operation", "wire",
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
@ -821,7 +834,7 @@ wire_transfer_information_cb (
&total_bad_sig_loss, &total_bad_sig_loss,
coin_value)); coin_value));
GNUNET_CRYPTO_rsa_signature_free (coin.denom_sig.rsa_signature); GNUNET_CRYPTO_rsa_signature_free (coin.denom_sig.rsa_signature);
edb->free_coin_transaction_list (edb->cls, TALER_ARL_edb->free_coin_transaction_list (TALER_ARL_edb->cls,
tl); tl);
wcc->qs = GNUNET_DB_STATUS_HARD_ERROR; wcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
report_row_inconsistency ("deposit", report_row_inconsistency ("deposit",
@ -841,7 +854,8 @@ wire_transfer_information_cb (
issue, issue,
tl, tl,
&computed_value, &computed_value,
&total_deposit_without_refunds)) &
total_deposit_without_refunds))
{ {
wcc->qs = GNUNET_DB_STATUS_HARD_ERROR; wcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
report_row_inconsistency ("coin history", report_row_inconsistency ("coin history",
@ -858,7 +872,8 @@ wire_transfer_information_cb (
deposit_fee)) deposit_fee))
{ {
wcc->qs = GNUNET_DB_STATUS_HARD_ERROR; wcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
report_amount_arithmetic_inconsistency ("aggregation (fee structure)", report_amount_arithmetic_inconsistency (
"aggregation (fee structure)",
rowid, rowid,
coin_value, coin_value,
deposit_fee, deposit_fee,
@ -873,13 +888,15 @@ wire_transfer_information_cb (
"Expected coin contribution of %s to aggregate\n", "Expected coin contribution of %s to aggregate\n",
TALER_amount2s (&coin_value_without_fee)); TALER_amount2s (&coin_value_without_fee));
wcc->qs = GNUNET_DB_STATUS_HARD_ERROR; wcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
report_amount_arithmetic_inconsistency ("aggregation (contribution)", report_amount_arithmetic_inconsistency (
"aggregation (contribution)",
rowid, rowid,
&coin_value_without_fee, &coin_value_without_fee,
&total_deposit_without_refunds, &
total_deposit_without_refunds,
-1); -1);
} }
edb->free_coin_transaction_list (edb->cls, TALER_ARL_edb->free_coin_transaction_list (TALER_ARL_edb->cls,
tl); tl);
/* Check other details of wire transfer match */ /* Check other details of wire transfer match */
@ -949,8 +966,8 @@ get_wire_fee (struct AggregationContext *ac,
/* Lookup fee in exchange database */ /* Lookup fee in exchange database */
wfi = GNUNET_new (struct WireFeeInfo); wfi = GNUNET_new (struct WireFeeInfo);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
edb->get_wire_fee (edb->cls, TALER_ARL_edb->get_wire_fee (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
method, method,
timestamp, timestamp,
&wfi->start_date, &wfi->start_date,
@ -985,7 +1002,7 @@ get_wire_fee (struct AggregationContext *ac,
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MASTER_WIRE_FEES, GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MASTER_WIRE_FEES,
&wf.purpose, &wf.purpose,
&master_sig.eddsa_signature, &master_sig.eddsa_signature,
&master_pub.eddsa_pub)) &TALER_ARL_master_pub.eddsa_pub))
{ {
report_row_inconsistency ("wire-fee", report_row_inconsistency ("wire-fee",
timestamp.abs_value_us, timestamp.abs_value_us,
@ -1012,20 +1029,24 @@ get_wire_fee (struct AggregationContext *ac,
if ( (NULL != wfi->prev) && if ( (NULL != wfi->prev) &&
(wfi->prev->end_date.abs_value_us > wfi->start_date.abs_value_us) ) (wfi->prev->end_date.abs_value_us > wfi->start_date.abs_value_us) )
{ {
report (report_fee_time_inconsistencies, TALER_ARL_report (report_fee_time_inconsistencies,
json_pack ("{s:s, s:s, s:o}", json_pack ("{s:s, s:s, s:o}",
"type", method, "type", method,
"diagnostic", "start date before previous end date", "diagnostic",
"time", json_from_time_abs (wfi->start_date))); "start date before previous end date",
"time", TALER_ARL_json_from_time_abs (
wfi->start_date)));
} }
if ( (NULL != wfi->next) && if ( (NULL != wfi->next) &&
(wfi->next->start_date.abs_value_us >= wfi->end_date.abs_value_us) ) (wfi->next->start_date.abs_value_us >= wfi->end_date.abs_value_us) )
{ {
report (report_fee_time_inconsistencies, TALER_ARL_report (report_fee_time_inconsistencies,
json_pack ("{s:s, s:s, s:o}", json_pack ("{s:s, s:s, s:o}",
"type", method, "type", method,
"diagnostic", "end date date after next start date", "diagnostic",
"time", json_from_time_abs (wfi->end_date))); "end date date after next start date",
"time", TALER_ARL_json_from_time_abs (
wfi->end_date)));
} }
return &wfi->wire_fee; return &wfi->wire_fee;
} }
@ -1089,8 +1110,8 @@ check_wire_out_cb (void *cls,
GNUNET_free (method); GNUNET_free (method);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
qs = edb->lookup_wire_transfer (edb->cls, qs = TALER_ARL_edb->lookup_wire_transfer (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
wtid, wtid,
&wire_transfer_information_cb, &wire_transfer_information_cb,
&wcc); &wcc);
@ -1133,7 +1154,8 @@ check_wire_out_cb (void *cls,
&wcc.total_deposits, &wcc.total_deposits,
wire_fee)) wire_fee))
{ {
report_amount_arithmetic_inconsistency ("wire out (fee structure)", report_amount_arithmetic_inconsistency (
"wire out (fee structure)",
rowid, rowid,
&wcc.total_deposits, &wcc.total_deposits,
wire_fee, wire_fee,
@ -1147,7 +1169,7 @@ check_wire_out_cb (void *cls,
/* Round down to amount supported by wire method */ /* Round down to amount supported by wire method */
GNUNET_break (GNUNET_SYSERR != GNUNET_break (GNUNET_SYSERR !=
TALER_amount_round_down (&final_amount, TALER_amount_round_down (&final_amount,
&currency_round_unit)); &TALER_ARL_currency_round_unit));
/* Calculate the exchange's gain as the fees plus rounding differences! */ /* Calculate the exchange's gain as the fees plus rounding differences! */
if (GNUNET_SYSERR == if (GNUNET_SYSERR ==
@ -1203,7 +1225,7 @@ check_wire_out_cb (void *cls,
&delta)); &delta));
} }
report (report_wire_out_inconsistencies, TALER_ARL_report (report_wire_out_inconsistencies,
json_pack ("{s:O, s:I, s:o, s:o}", json_pack ("{s:O, s:I, s:o, s:o}",
"destination_account", wire, "destination_account", wire,
"rowid", (json_int_t) rowid, "rowid", (json_int_t) rowid,
@ -1238,9 +1260,9 @@ analyze_aggregations (void *cls)
(void) cls; (void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Analyzing aggregations\n"); "Analyzing aggregations\n");
qsp = adb->get_auditor_progress_aggregation (adb->cls, qsp = TALER_ARL_adb->get_auditor_progress_aggregation (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&ppa); &ppa);
if (0 > qsp) if (0 > qsp)
{ {
@ -1264,9 +1286,9 @@ analyze_aggregations (void *cls)
memset (&ac, memset (&ac,
0, 0,
sizeof (ac)); sizeof (ac));
qsx = adb->get_wire_fee_summary (adb->cls, qsx = TALER_ARL_adb->get_wire_fee_summary (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&total_aggregation_fee_income); &total_aggregation_fee_income);
if (0 > qsx) if (0 > qsx)
{ {
@ -1274,9 +1296,10 @@ analyze_aggregations (void *cls)
return qsx; return qsx;
} }
ac.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; ac.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
qs = edb->select_wire_out_above_serial_id (edb->cls, qs = TALER_ARL_edb->select_wire_out_above_serial_id (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
ppa.last_wire_out_serial_id, ppa.
last_wire_out_serial_id,
&check_wire_out_cb, &check_wire_out_cb,
&ac); &ac);
if (0 > qs) if (0 > qs)
@ -1302,29 +1325,33 @@ analyze_aggregations (void *cls)
return ac.qs; return ac.qs;
} }
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsx) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsx)
ac.qs = adb->insert_wire_fee_summary (adb->cls, ac.qs = TALER_ARL_adb->insert_wire_fee_summary (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&total_aggregation_fee_income); &
total_aggregation_fee_income);
else else
ac.qs = adb->update_wire_fee_summary (adb->cls, ac.qs = TALER_ARL_adb->update_wire_fee_summary (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&total_aggregation_fee_income); &
total_aggregation_fee_income);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != ac.qs) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != ac.qs)
{ {
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == ac.qs); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == ac.qs);
return ac.qs; return ac.qs;
} }
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp)
qs = adb->update_auditor_progress_aggregation (adb->cls, qs = TALER_ARL_adb->update_auditor_progress_aggregation (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &
TALER_ARL_master_pub,
&ppa); &ppa);
else else
qs = adb->insert_auditor_progress_aggregation (adb->cls, qs = TALER_ARL_adb->insert_auditor_progress_aggregation (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &
TALER_ARL_master_pub,
&ppa); &ppa);
if (0 >= qs) if (0 >= qs)
{ {
@ -1346,24 +1373,24 @@ analyze_aggregations (void *cls)
* *
* @param cls closure * @param cls closure
* @param args remaining command-line arguments * @param args remaining command-line arguments
* @param cfgfile name of the configuration file used (for saving, can be NULL!) * @param TALER_ARL_cfgfile name of the configuration file used (for saving, can be NULL!)
* @param c configuration * @param c configuration
*/ */
static void static void
run (void *cls, run (void *cls,
char *const *args, char *const *args,
const char *cfgfile, const char *TALER_ARL_cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c) const struct GNUNET_CONFIGURATION_Handle *c)
{ {
json_t *report; json_t *report;
(void) cls; (void) cls;
(void) args; (void) args;
(void) cfgfile; (void) TALER_ARL_cfgfile;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Launching auditor\n"); "Launching auditor\n");
if (GNUNET_OK != if (GNUNET_OK !=
setup_globals (c)) TALER_ARL_init (c))
{ {
global_ret = 1; global_ret = 1;
return; return;
@ -1371,28 +1398,28 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting audit\n"); "Starting audit\n");
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_aggregation_fee_income)); &total_aggregation_fee_income));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_wire_out_delta_plus)); &total_wire_out_delta_plus));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_wire_out_delta_minus)); &total_wire_out_delta_minus));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_arithmetic_delta_plus)); &total_arithmetic_delta_plus));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_arithmetic_delta_minus)); &total_arithmetic_delta_minus));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_coin_delta_plus)); &total_coin_delta_plus));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_coin_delta_minus)); &total_coin_delta_minus));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_bad_sig_loss)); &total_bad_sig_loss));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_row_inconsistencies = json_array ())); (report_row_inconsistencies = json_array ()));
@ -1401,12 +1428,13 @@ run (void *cls,
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_coin_inconsistencies = json_array ())); (report_coin_inconsistencies = json_array ()));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_amount_arithmetic_inconsistencies = json_array ())); (report_amount_arithmetic_inconsistencies =
json_array ()));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_bad_sig_losses = json_array ())); (report_bad_sig_losses = json_array ()));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_fee_time_inconsistencies = json_array ())); (report_fee_time_inconsistencies = json_array ()));
setup_sessions_and_run (&analyze_aggregations, TALER_ARL_setup_sessions_and_run (&analyze_aggregations,
NULL); NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Audit complete\n"); "Audit complete\n");
@ -1418,9 +1446,11 @@ run (void *cls,
"wire_out_inconsistencies", "wire_out_inconsistencies",
report_wire_out_inconsistencies, report_wire_out_inconsistencies,
"total_wire_out_delta_plus", "total_wire_out_delta_plus",
TALER_JSON_from_amount (&total_wire_out_delta_plus), TALER_JSON_from_amount (
&total_wire_out_delta_plus),
"total_wire_out_delta_minus", "total_wire_out_delta_minus",
TALER_JSON_from_amount (&total_wire_out_delta_minus), TALER_JSON_from_amount (
&total_wire_out_delta_minus),
/* Tested in test-auditor.sh #4/#5/#6/#7/#13 */ /* Tested in test-auditor.sh #4/#5/#6/#7/#13 */
"bad_sig_losses", "bad_sig_losses",
report_bad_sig_losses, report_bad_sig_losses,
@ -1436,27 +1466,34 @@ run (void *cls,
"total_coin_delta_plus", "total_coin_delta_plus",
TALER_JSON_from_amount (&total_coin_delta_plus), TALER_JSON_from_amount (&total_coin_delta_plus),
"total_coin_delta_minus", "total_coin_delta_minus",
TALER_JSON_from_amount (&total_coin_delta_minus), TALER_JSON_from_amount (
&total_coin_delta_minus),
"amount_arithmetic_inconsistencies", "amount_arithmetic_inconsistencies",
report_amount_arithmetic_inconsistencies, report_amount_arithmetic_inconsistencies,
/* block #3 */ /* block #3 */
"total_arithmetic_delta_plus", "total_arithmetic_delta_plus",
TALER_JSON_from_amount (&total_arithmetic_delta_plus), TALER_JSON_from_amount (
&total_arithmetic_delta_plus),
"total_arithmetic_delta_minus", "total_arithmetic_delta_minus",
TALER_JSON_from_amount (&total_arithmetic_delta_minus), TALER_JSON_from_amount (
&total_arithmetic_delta_minus),
"total_aggregation_fee_income", "total_aggregation_fee_income",
TALER_JSON_from_amount (&total_aggregation_fee_income), TALER_JSON_from_amount (
&total_aggregation_fee_income),
"start_ppa_wire_out_serial_id", "start_ppa_wire_out_serial_id",
(json_int_t) ppa_start.last_wire_out_serial_id, (json_int_t) ppa_start.last_wire_out_serial_id,
"end_ppa_wire_out_serial_id", "end_ppa_wire_out_serial_id",
(json_int_t) ppa.last_wire_out_serial_id, (json_int_t) ppa.last_wire_out_serial_id,
/* block #4 */ /* block #4 */
"auditor_start_time", json_from_time_abs (start_time), "auditor_start_time",
"auditor_end_time", json_from_time_abs ( TALER_ARL_json_from_time_abs (
start_time),
"auditor_end_time",
TALER_ARL_json_from_time_abs (
GNUNET_TIME_absolute_get ()) GNUNET_TIME_absolute_get ())
); );
GNUNET_break (NULL != report); GNUNET_break (NULL != report);
finish_report (report); TALER_ARL_done (report);
} }
@ -1477,11 +1514,11 @@ main (int argc,
"exchange-key", "exchange-key",
"KEY", "KEY",
"public key of the exchange (Crockford base32 encoded)", "public key of the exchange (Crockford base32 encoded)",
&master_pub), &TALER_ARL_master_pub),
GNUNET_GETOPT_option_flag ('r', GNUNET_GETOPT_option_flag ('r',
"restart", "TALER_ARL_restart",
"restart audit from the beginning (required on first run)", "TALER_ARL_restart audit from the beginning (required on first run)",
&restart), &TALER_ARL_restart),
GNUNET_GETOPT_option_timetravel ('T', GNUNET_GETOPT_option_timetravel ('T',
"timetravel"), "timetravel"),
GNUNET_GETOPT_OPTION_END GNUNET_GETOPT_OPTION_END

View File

@ -14,25 +14,10 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/ */
/** /**
* @file auditor/taler-auditor.c * @file auditor/taler-helper-auditor0coins.c
* @brief audits an exchange database. * @brief audits coins in an exchange database.
* @author Christian Grothoff * @author Christian Grothoff
* *
* NOTE:
* - This auditor does not verify that 'reserves_in' actually matches
* the wire transfers from the bank. This needs to be checked separately!
* - Similarly, we do not check that the outgoing wire transfers match those
* given in the 'wire_out' table. This needs to be checked separately!
*
* TODO:
* - reorganize: different passes are combined in one tool and one
* file here, we should split this up!
* - likely should do an iteration over known_coins instead of checking
* those signatures again and again
* - might want to bite the bullet and do asynchronous signature
* verification to improve parallelism / speed -- we'll need to scale
* this eventually anyway!
*
* UNDECIDED: * UNDECIDED:
* - do we care about checking the 'done' flag in deposit_cb? * - do we care about checking the 'done' flag in deposit_cb?
*/ */
@ -76,19 +61,19 @@ static struct TALER_AUDITORDB_ProgressPointCoin ppc;
static struct TALER_AUDITORDB_ProgressPointCoin ppc_start; static struct TALER_AUDITORDB_ProgressPointCoin ppc_start;
/** /**
* Array of reports about denomination keys with an * Array of TALER_ARL_reports about denomination keys with an
* emergency (more value deposited than withdrawn) * emergency (more value deposited than withdrawn)
*/ */
static json_t *report_emergencies; static json_t *report_emergencies;
/** /**
* Array of reports about denomination keys with an * Array of TALER_ARL_reports about denomination keys with an
* emergency (more coins deposited than withdrawn) * emergency (more coins deposited than withdrawn)
*/ */
static json_t *report_emergencies_by_count; static json_t *report_emergencies_by_count;
/** /**
* Array of reports about row inconsitencies. * Array of TALER_ARL_reports about row inconsitencies.
*/ */
static json_t *report_row_inconsistencies; static json_t *report_row_inconsistencies;
@ -164,7 +149,7 @@ static struct TALER_Amount total_melt_fee_income;
static struct TALER_Amount total_refund_fee_income; static struct TALER_Amount total_refund_fee_income;
/** /**
* Array of reports about coin operations with bad signatures. * Array of TALER_ARL_reports about coin operations with bad signatures.
*/ */
static json_t *report_bad_sig_losses; static json_t *report_bad_sig_losses;
@ -200,11 +185,12 @@ static struct TALER_Amount total_refresh_hanging;
* @param loss actual losses already (actualized before denomination was revoked) * @param loss actual losses already (actualized before denomination was revoked)
*/ */
static void static void
report_emergency_by_amount (const struct TALER_DenominationKeyValidityPS *issue, report_emergency_by_amount (const struct
TALER_DenominationKeyValidityPS *issue,
const struct TALER_Amount *risk, const struct TALER_Amount *risk,
const struct TALER_Amount *loss) const struct TALER_Amount *loss)
{ {
report (report_emergencies, TALER_ARL_report (report_emergencies,
json_pack ("{s:o, s:o, s:o, s:o, s:o, s:o}", json_pack ("{s:o, s:o, s:o, s:o, s:o, s:o}",
"denompub_hash", "denompub_hash",
GNUNET_JSON_from_data_auto (&issue->denom_hash), GNUNET_JSON_from_data_auto (&issue->denom_hash),
@ -213,9 +199,11 @@ report_emergency_by_amount (const struct TALER_DenominationKeyValidityPS *issue,
"denom_loss", "denom_loss",
TALER_JSON_from_amount (loss), TALER_JSON_from_amount (loss),
"start", "start",
json_from_time_abs_nbo (issue->start), TALER_ARL_TALER_ARL_json_from_time_abs_nbo (
issue->start),
"deposit_end", "deposit_end",
json_from_time_abs_nbo (issue->expire_deposit), TALER_ARL_TALER_ARL_json_from_time_abs_nbo (
issue->expire_deposit),
"value", "value",
TALER_JSON_from_amount_nbo (&issue->value))); TALER_JSON_from_amount_nbo (&issue->value)));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
@ -244,14 +232,15 @@ report_emergency_by_amount (const struct TALER_DenominationKeyValidityPS *issue,
* @param risk amount that is at risk * @param risk amount that is at risk
*/ */
static void static void
report_emergency_by_count (const struct TALER_DenominationKeyValidityPS *issue, report_emergency_by_count (const struct
TALER_DenominationKeyValidityPS *issue,
uint64_t num_issued, uint64_t num_issued,
uint64_t num_known, uint64_t num_known,
const struct TALER_Amount *risk) const struct TALER_Amount *risk)
{ {
struct TALER_Amount denom_value; struct TALER_Amount denom_value;
report (report_emergencies_by_count, TALER_ARL_report (report_emergencies_by_count,
json_pack ("{s:o, s:I, s:I, s:o, s:o, s:o, s:o}", json_pack ("{s:o, s:I, s:I, s:o, s:o, s:o, s:o}",
"denompub_hash", "denompub_hash",
GNUNET_JSON_from_data_auto (&issue->denom_hash), GNUNET_JSON_from_data_auto (&issue->denom_hash),
@ -262,9 +251,11 @@ report_emergency_by_count (const struct TALER_DenominationKeyValidityPS *issue,
"denom_risk", "denom_risk",
TALER_JSON_from_amount (risk), TALER_JSON_from_amount (risk),
"start", "start",
json_from_time_abs_nbo (issue->start), TALER_ARL_TALER_ARL_json_from_time_abs_nbo (
issue->start),
"deposit_end", "deposit_end",
json_from_time_abs_nbo (issue->expire_deposit), TALER_ARL_TALER_ARL_json_from_time_abs_nbo (
issue->expire_deposit),
"value", "value",
TALER_JSON_from_amount_nbo (&issue->value))); TALER_JSON_from_amount_nbo (&issue->value)));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
@ -275,7 +266,8 @@ report_emergency_by_count (const struct TALER_DenominationKeyValidityPS *issue,
&issue->value); &issue->value);
for (uint64_t i = num_issued; i<num_known; i++) for (uint64_t i = num_issued; i<num_known; i++)
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_add (&reported_emergency_loss_by_count, TALER_amount_add (
&reported_emergency_loss_by_count,
&reported_emergency_loss_by_count, &reported_emergency_loss_by_count,
&denom_value)); &denom_value));
@ -298,8 +290,10 @@ report_emergency_by_count (const struct TALER_DenominationKeyValidityPS *issue,
static void static void
report_amount_arithmetic_inconsistency (const char *operation, report_amount_arithmetic_inconsistency (const char *operation,
uint64_t rowid, uint64_t rowid,
const struct TALER_Amount *exchange, const struct
const struct TALER_Amount *auditor, TALER_Amount *exchange,
const struct
TALER_Amount *auditor,
int profitable) int profitable)
{ {
struct TALER_Amount delta; struct TALER_Amount delta;
@ -323,7 +317,7 @@ report_amount_arithmetic_inconsistency (const char *operation,
auditor, auditor,
exchange)); exchange));
} }
report (report_amount_arithmetic_inconsistencies, TALER_ARL_report (report_amount_arithmetic_inconsistencies,
json_pack ("{s:s, s:I, s:o, s:o, s:I}", json_pack ("{s:s, s:I, s:o, s:o, s:I}",
"operation", operation, "operation", operation,
"rowid", (json_int_t) rowid, "rowid", (json_int_t) rowid,
@ -355,7 +349,7 @@ report_row_inconsistency (const char *table,
uint64_t rowid, uint64_t rowid,
const char *diagnostic) const char *diagnostic)
{ {
report (report_row_inconsistencies, TALER_ARL_report (report_row_inconsistencies,
json_pack ("{s:s, s:I, s:s}", json_pack ("{s:s, s:I, s:s}",
"table", table, "table", table,
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
@ -416,7 +410,7 @@ struct DenominationSummary
int in_db; int in_db;
/** /**
* Should we report an emergency for this denomination? * Should we TALER_ARL_report an emergency for this denomination?
*/ */
int report_emergency; int report_emergency;
@ -466,8 +460,8 @@ init_denomination (const struct GNUNET_HashCode *denom_hash,
struct TALER_MasterSignatureP msig; struct TALER_MasterSignatureP msig;
uint64_t rowid; uint64_t rowid;
qs = adb->get_denomination_balance (adb->cls, qs = TALER_ARL_adb->get_denomination_balance (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
denom_hash, denom_hash,
&ds->denom_balance, &ds->denom_balance,
&ds->denom_loss, &ds->denom_loss,
@ -488,8 +482,8 @@ init_denomination (const struct GNUNET_HashCode *denom_hash,
TALER_amount2s (&ds->denom_balance)); TALER_amount2s (&ds->denom_balance));
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
} }
qs = edb->get_denomination_revocation (edb->cls, qs = TALER_ARL_edb->get_denomination_revocation (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
denom_hash, denom_hash,
&msig, &msig,
&rowid); &rowid);
@ -512,7 +506,7 @@ init_denomination (const struct GNUNET_HashCode *denom_hash,
TALER_SIGNATURE_MASTER_DENOMINATION_KEY_REVOKED, TALER_SIGNATURE_MASTER_DENOMINATION_KEY_REVOKED,
&rm.purpose, &rm.purpose,
&msig.eddsa_signature, &msig.eddsa_signature,
&master_pub.eddsa_pub)) &TALER_ARL_master_pub.eddsa_pub))
{ {
report_row_inconsistency ("denomination revocation table", report_row_inconsistency ("denomination revocation table",
rowid, rowid,
@ -524,16 +518,16 @@ init_denomination (const struct GNUNET_HashCode *denom_hash,
} }
} }
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&ds->denom_balance)); &ds->denom_balance));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&ds->denom_loss)); &ds->denom_loss));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&ds->denom_risk)); &ds->denom_risk));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&ds->denom_recoup)); &ds->denom_recoup));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting balance for denomination `%s' is %s\n", "Starting balance for denomination `%s' is %s\n",
@ -582,7 +576,7 @@ get_denomination_summary (struct CoinContext *cc,
/** /**
* Write information about the current knowledge about a denomination key * Write information about the current knowledge about a denomination key
* back to the database and update our global reporting data about the * back to the database and update our global TALER_ARL_reporting data about the
* denomination. Also remove and free the memory of @a value. * denomination. Also remove and free the memory of @a value.
* *
* @param cls the `struct CoinContext` * @param cls the `struct CoinContext`
@ -613,8 +607,8 @@ sync_denomination (void *cls,
/* Denominationkey has expired, book remaining balance of /* Denominationkey has expired, book remaining balance of
outstanding coins as revenue; and reduce cc->risk exposure. */ outstanding coins as revenue; and reduce cc->risk exposure. */
if (ds->in_db) if (ds->in_db)
qs = adb->del_denomination_balance (adb->cls, qs = TALER_ARL_adb->del_denomination_balance (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
denom_hash); denom_hash);
else else
qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
@ -646,9 +640,11 @@ sync_denomination (void *cls,
GNUNET_h2s (denom_hash), GNUNET_h2s (denom_hash),
TALER_amount2s (&ds->denom_balance)); TALER_amount2s (&ds->denom_balance));
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
(qs = adb->insert_historic_denom_revenue (adb->cls, (qs = TALER_ARL_adb->insert_historic_denom_revenue (
asession, TALER_ARL_adb->cls,
&master_pub, TALER_ARL_asession,
&
TALER_ARL_master_pub,
denom_hash, denom_hash,
expire_deposit, expire_deposit,
&ds->denom_balance, &ds->denom_balance,
@ -669,8 +665,8 @@ sync_denomination (void *cls,
GNUNET_h2s (denom_hash), GNUNET_h2s (denom_hash),
TALER_amount2s (&ds->denom_balance), TALER_amount2s (&ds->denom_balance),
(unsigned long long) ds->num_issued); (unsigned long long) ds->num_issued);
cnt = edb->count_known_coins (edb->cls, cnt = TALER_ARL_edb->count_known_coins (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
denom_hash); denom_hash);
if (0 > cnt) if (0 > cnt)
{ {
@ -696,8 +692,8 @@ sync_denomination (void *cls,
} }
if (ds->in_db) if (ds->in_db)
qs = adb->update_denomination_balance (adb->cls, qs = TALER_ARL_adb->update_denomination_balance (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
denom_hash, denom_hash,
&ds->denom_balance, &ds->denom_balance,
&ds->denom_loss, &ds->denom_loss,
@ -705,8 +701,8 @@ sync_denomination (void *cls,
&ds->denom_recoup, &ds->denom_recoup,
ds->num_issued); ds->num_issued);
else else
qs = adb->insert_denomination_balance (adb->cls, qs = TALER_ARL_adb->insert_denomination_balance (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
denom_hash, denom_hash,
&ds->denom_balance, &ds->denom_balance,
&ds->denom_loss, &ds->denom_loss,
@ -774,7 +770,7 @@ withdraw_cb (void *cls,
GNUNET_assert (rowid >= ppc.last_withdraw_serial_id); /* should be monotonically increasing */ GNUNET_assert (rowid >= ppc.last_withdraw_serial_id); /* should be monotonically increasing */
ppc.last_withdraw_serial_id = rowid + 1; ppc.last_withdraw_serial_id = rowid + 1;
qs = get_denomination_info (denom_pub, qs = TALER_ARL_get_denomination_info (denom_pub,
&issue, &issue,
&dh); &dh);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
@ -902,7 +898,7 @@ reveal_data_cb (void *cls,
/** /**
* Check that the @a coin_pub is a known coin with a proper * Check that the @a coin_pub is a known coin with a proper
* signature for denominatinon @a denom_pub. If not, report * signature for denominatinon @a denom_pub. If not, TALER_ARL_report
* a loss of @a loss_potential. * a loss of @a loss_potential.
* *
* @param coin_pub public key of a coin * @param coin_pub public key of a coin
@ -923,8 +919,8 @@ check_known_coin (const struct TALER_CoinSpendPublicKeyP *coin_pub,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Checking denomination signature on %s\n", "Checking denomination signature on %s\n",
TALER_B2S (coin_pub)); TALER_B2S (coin_pub));
qs = edb->get_known_coin (edb->cls, qs = TALER_ARL_edb->get_known_coin (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
coin_pub, coin_pub,
&ci); &ci);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
@ -936,12 +932,14 @@ check_known_coin (const struct TALER_CoinSpendPublicKeyP *coin_pub,
TALER_test_coin_valid (&ci, TALER_test_coin_valid (&ci,
denom_pub)) denom_pub))
{ {
report (report_bad_sig_losses, TALER_ARL_report (report_bad_sig_losses,
json_pack ("{s:s, s:I, s:o, s:o}", json_pack ("{s:s, s:I, s:o, s:o}",
"operation", "known-coin", "operation", "known-coin",
"row", (json_int_t) -1, "row", (json_int_t) -1,
"loss", TALER_JSON_from_amount (loss_potential), "loss", TALER_JSON_from_amount (
"key_pub", GNUNET_JSON_from_data_auto (coin_pub))); loss_potential),
"key_pub", GNUNET_JSON_from_data_auto (
coin_pub)));
GNUNET_break (GNUNET_OK == GNUNET_break (GNUNET_OK ==
TALER_amount_add (&total_bad_sig_loss, TALER_amount_add (&total_bad_sig_loss,
&total_bad_sig_loss, &total_bad_sig_loss,
@ -992,7 +990,7 @@ refresh_session_cb (void *cls,
GNUNET_assert (rowid >= ppc.last_melt_serial_id); /* should be monotonically increasing */ GNUNET_assert (rowid >= ppc.last_melt_serial_id); /* should be monotonically increasing */
ppc.last_melt_serial_id = rowid + 1; ppc.last_melt_serial_id = rowid + 1;
qs = get_denomination_info (denom_pub, qs = TALER_ARL_get_denomination_info (denom_pub,
&issue, &issue,
NULL); NULL);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
@ -1032,12 +1030,14 @@ refresh_session_cb (void *cls,
&coin_sig->eddsa_signature, &coin_sig->eddsa_signature,
&coin_pub->eddsa_pub)) &coin_pub->eddsa_pub))
{ {
report (report_bad_sig_losses, TALER_ARL_report (report_bad_sig_losses,
json_pack ("{s:s, s:I, s:o, s:o}", json_pack ("{s:s, s:I, s:o, s:o}",
"operation", "melt", "operation", "melt",
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
"loss", TALER_JSON_from_amount (amount_with_fee), "loss", TALER_JSON_from_amount (
"key_pub", GNUNET_JSON_from_data_auto (coin_pub))); amount_with_fee),
"key_pub", GNUNET_JSON_from_data_auto (
coin_pub)));
GNUNET_break (GNUNET_OK == GNUNET_break (GNUNET_OK ==
TALER_amount_add (&total_bad_sig_loss, TALER_amount_add (&total_bad_sig_loss,
&total_bad_sig_loss, &total_bad_sig_loss,
@ -1061,8 +1061,8 @@ refresh_session_cb (void *cls,
memset (&reveal_ctx, memset (&reveal_ctx,
0, 0,
sizeof (reveal_ctx)); sizeof (reveal_ctx));
qs = edb->get_refresh_reveal (edb->cls, qs = TALER_ARL_edb->get_refresh_reveal (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
rc, rc,
&reveal_data_cb, &reveal_data_cb,
&reveal_ctx); &reveal_ctx);
@ -1077,12 +1077,14 @@ refresh_session_cb (void *cls,
{ {
/* This can happen if /refresh/reveal was not yet called or only /* This can happen if /refresh/reveal was not yet called or only
with invalid data, even if the exchange is correctly with invalid data, even if the exchange is correctly
operating. We still report it. */ operating. We still TALER_ARL_report it. */
report (report_refreshs_hanging, TALER_ARL_report (report_refreshs_hanging,
json_pack ("{s:I, s:o, s:o}", json_pack ("{s:I, s:o, s:o}",
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
"amount", TALER_JSON_from_amount (amount_with_fee), "amount", TALER_JSON_from_amount (
"coin_pub", GNUNET_JSON_from_data_auto (coin_pub))); amount_with_fee),
"coin_pub", GNUNET_JSON_from_data_auto (
coin_pub)));
GNUNET_break (GNUNET_OK == GNUNET_break (GNUNET_OK ==
TALER_amount_add (&total_refresh_hanging, TALER_amount_add (&total_refresh_hanging,
&total_refresh_hanging, &total_refresh_hanging,
@ -1100,7 +1102,7 @@ refresh_session_cb (void *cls,
for (unsigned int i = 0; i<reveal_ctx.num_freshcoins; i++) for (unsigned int i = 0; i<reveal_ctx.num_freshcoins; i++)
{ {
/* lookup new coin denomination key */ /* lookup new coin denomination key */
qs = get_denomination_info (&reveal_ctx.new_dps[i], qs = TALER_ARL_get_denomination_info (&reveal_ctx.new_dps[i],
&new_issues[i], &new_issues[i],
NULL); NULL);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
@ -1369,7 +1371,7 @@ deposit_cb (void *cls,
GNUNET_assert (rowid >= ppc.last_deposit_serial_id); /* should be monotonically increasing */ GNUNET_assert (rowid >= ppc.last_deposit_serial_id); /* should be monotonically increasing */
ppc.last_deposit_serial_id = rowid + 1; ppc.last_deposit_serial_id = rowid + 1;
qs = get_denomination_info (denom_pub, qs = TALER_ARL_get_denomination_info (denom_pub,
&issue, &issue,
NULL); NULL);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
@ -1404,12 +1406,14 @@ deposit_cb (void *cls,
TALER_JSON_merchant_wire_signature_hash (receiver_wire_account, TALER_JSON_merchant_wire_signature_hash (receiver_wire_account,
&dr.h_wire)) &dr.h_wire))
{ {
report (report_bad_sig_losses, TALER_ARL_report (report_bad_sig_losses,
json_pack ("{s:s, s:I, s:o, s:o}", json_pack ("{s:s, s:I, s:o, s:o}",
"operation", "deposit", "operation", "deposit",
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
"loss", TALER_JSON_from_amount (amount_with_fee), "loss", TALER_JSON_from_amount (
"key_pub", GNUNET_JSON_from_data_auto (coin_pub))); amount_with_fee),
"key_pub", GNUNET_JSON_from_data_auto (
coin_pub)));
GNUNET_break (GNUNET_OK == GNUNET_break (GNUNET_OK ==
TALER_amount_add (&total_bad_sig_loss, TALER_amount_add (&total_bad_sig_loss,
&total_bad_sig_loss, &total_bad_sig_loss,
@ -1429,12 +1433,14 @@ deposit_cb (void *cls,
&coin_sig->eddsa_signature, &coin_sig->eddsa_signature,
&coin_pub->eddsa_pub)) &coin_pub->eddsa_pub))
{ {
report (report_bad_sig_losses, TALER_ARL_report (report_bad_sig_losses,
json_pack ("{s:s, s:I, s:o, s:o}", json_pack ("{s:s, s:I, s:o, s:o}",
"operation", "deposit", "operation", "deposit",
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
"loss", TALER_JSON_from_amount (amount_with_fee), "loss", TALER_JSON_from_amount (
"key_pub", GNUNET_JSON_from_data_auto (coin_pub))); amount_with_fee),
"key_pub", GNUNET_JSON_from_data_auto (
coin_pub)));
GNUNET_break (GNUNET_OK == GNUNET_break (GNUNET_OK ==
TALER_amount_add (&total_bad_sig_loss, TALER_amount_add (&total_bad_sig_loss,
&total_bad_sig_loss, &total_bad_sig_loss,
@ -1560,7 +1566,7 @@ refund_cb (void *cls,
GNUNET_assert (rowid >= ppc.last_refund_serial_id); /* should be monotonically increasing */ GNUNET_assert (rowid >= ppc.last_refund_serial_id); /* should be monotonically increasing */
ppc.last_refund_serial_id = rowid + 1; ppc.last_refund_serial_id = rowid + 1;
qs = get_denomination_info (denom_pub, qs = TALER_ARL_get_denomination_info (denom_pub,
&issue, &issue,
NULL); NULL);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
@ -1592,12 +1598,14 @@ refund_cb (void *cls,
&merchant_sig->eddsa_sig, &merchant_sig->eddsa_sig,
&merchant_pub->eddsa_pub)) &merchant_pub->eddsa_pub))
{ {
report (report_bad_sig_losses, TALER_ARL_report (report_bad_sig_losses,
json_pack ("{s:s, s:I, s:o, s:o}", json_pack ("{s:s, s:I, s:o, s:o}",
"operation", "refund", "operation", "refund",
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
"loss", TALER_JSON_from_amount (amount_with_fee), "loss", TALER_JSON_from_amount (
"key_pub", GNUNET_JSON_from_data_auto (merchant_pub))); amount_with_fee),
"key_pub", GNUNET_JSON_from_data_auto (
merchant_pub)));
GNUNET_break (GNUNET_OK == GNUNET_break (GNUNET_OK ==
TALER_amount_add (&total_bad_sig_loss, TALER_amount_add (&total_bad_sig_loss,
&total_bad_sig_loss, &total_bad_sig_loss,
@ -1723,7 +1731,7 @@ check_recoup (struct CoinContext *cc,
TALER_test_coin_valid (coin, TALER_test_coin_valid (coin,
denom_pub)) denom_pub))
{ {
report (report_bad_sig_losses, TALER_ARL_report (report_bad_sig_losses,
json_pack ("{s:s, s:I, s:o, s:o}", json_pack ("{s:s, s:I, s:o, s:o}",
"operation", "recoup", "operation", "recoup",
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
@ -1735,7 +1743,7 @@ check_recoup (struct CoinContext *cc,
&total_bad_sig_loss, &total_bad_sig_loss,
amount)); amount));
} }
qs = get_denomination_info (denom_pub, qs = TALER_ARL_get_denomination_info (denom_pub,
&issue, &issue,
&pr.h_denom_pub); &pr.h_denom_pub);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
@ -1763,7 +1771,7 @@ check_recoup (struct CoinContext *cc,
&coin_sig->eddsa_signature, &coin_sig->eddsa_signature,
&coin->coin_pub.eddsa_pub)) &coin->coin_pub.eddsa_pub))
{ {
report (report_bad_sig_losses, TALER_ARL_report (report_bad_sig_losses,
json_pack ("{s:s, s:I, s:o, s:o}", json_pack ("{s:s, s:I, s:o, s:o}",
"operation", "recoup", "operation", "recoup",
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
@ -1782,9 +1790,10 @@ check_recoup (struct CoinContext *cc,
if (GNUNET_NO == ds->was_revoked) if (GNUNET_NO == ds->was_revoked)
{ {
/* Woopsie, we allowed recoup on non-revoked denomination!? */ /* Woopsie, we allowed recoup on non-revoked denomination!? */
report (report_bad_sig_losses, TALER_ARL_report (report_bad_sig_losses,
json_pack ("{s:s, s:I, s:o, s:o}", json_pack ("{s:s, s:I, s:o, s:o}",
"operation", "recoup (denomination not revoked)", "operation",
"recoup (denomination not revoked)",
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
"loss", TALER_JSON_from_amount (amount), "loss", TALER_JSON_from_amount (amount),
"coin_pub", GNUNET_JSON_from_data_auto ( "coin_pub", GNUNET_JSON_from_data_auto (
@ -1898,9 +1907,9 @@ analyze_coins (void *cls)
(void) cls; (void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Analyzing coins\n"); "Analyzing coins\n");
qsp = adb->get_auditor_progress_coin (adb->cls, qsp = TALER_ARL_adb->get_auditor_progress_coin (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&ppc); &ppc);
if (0 > qsp) if (0 > qsp)
{ {
@ -1928,9 +1937,9 @@ analyze_coins (void *cls)
cc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; cc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
cc.denom_summaries = GNUNET_CONTAINER_multihashmap_create (256, cc.denom_summaries = GNUNET_CONTAINER_multihashmap_create (256,
GNUNET_NO); GNUNET_NO);
qsx = adb->get_balance_summary (adb->cls, qsx = TALER_ARL_adb->get_balance_summary (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&total_escrow_balance, &total_escrow_balance,
&total_deposit_fee_income, &total_deposit_fee_income,
&total_melt_fee_income, &total_melt_fee_income,
@ -1946,8 +1955,9 @@ analyze_coins (void *cls)
/* process withdrawals */ /* process withdrawals */
if (0 > if (0 >
(qs = edb->select_withdrawals_above_serial_id (edb->cls, (qs = TALER_ARL_edb->select_withdrawals_above_serial_id (
esession, TALER_ARL_edb->cls,
TALER_ARL_esession,
ppc. ppc.
last_withdraw_serial_id, last_withdraw_serial_id,
&withdraw_cb, &withdraw_cb,
@ -1961,9 +1971,10 @@ analyze_coins (void *cls)
/* process refunds */ /* process refunds */
if (0 > if (0 >
(qs = edb->select_refunds_above_serial_id (edb->cls, (qs = TALER_ARL_edb->select_refunds_above_serial_id (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
ppc.last_refund_serial_id, ppc.
last_refund_serial_id,
&refund_cb, &refund_cb,
&cc))) &cc)))
{ {
@ -1975,9 +1986,10 @@ analyze_coins (void *cls)
/* process refreshs */ /* process refreshs */
if (0 > if (0 >
(qs = edb->select_refreshes_above_serial_id (edb->cls, (qs = TALER_ARL_edb->select_refreshes_above_serial_id (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
ppc.last_melt_serial_id, ppc.
last_melt_serial_id,
&refresh_session_cb, &refresh_session_cb,
&cc))) &cc)))
{ {
@ -1989,9 +2001,10 @@ analyze_coins (void *cls)
/* process deposits */ /* process deposits */
if (0 > if (0 >
(qs = edb->select_deposits_above_serial_id (edb->cls, (qs = TALER_ARL_edb->select_deposits_above_serial_id (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
ppc.last_deposit_serial_id, ppc.
last_deposit_serial_id,
&deposit_cb, &deposit_cb,
&cc))) &cc)))
{ {
@ -2003,9 +2016,10 @@ analyze_coins (void *cls)
/* process recoups */ /* process recoups */
if (0 > if (0 >
(qs = edb->select_recoup_above_serial_id (edb->cls, (qs = TALER_ARL_edb->select_recoup_above_serial_id (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
ppc.last_recoup_serial_id, ppc.
last_recoup_serial_id,
&recoup_cb, &recoup_cb,
&cc))) &cc)))
{ {
@ -2015,11 +2029,13 @@ analyze_coins (void *cls)
if (0 > cc.qs) if (0 > cc.qs)
return cc.qs; return cc.qs;
if (0 > if (0 >
(qs = edb->select_recoup_refresh_above_serial_id (edb->cls, (qs = TALER_ARL_edb->select_recoup_refresh_above_serial_id (
esession, TALER_ARL_edb->cls,
TALER_ARL_esession,
ppc. ppc.
last_recoup_refresh_serial_id, last_recoup_refresh_serial_id,
&recoup_refresh_cb, &
recoup_refresh_cb,
&cc))) &cc)))
{ {
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@ -2040,9 +2056,9 @@ analyze_coins (void *cls)
return cc.qs; return cc.qs;
} }
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsx) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsx)
qs = adb->update_balance_summary (adb->cls, qs = TALER_ARL_adb->update_balance_summary (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&total_escrow_balance, &total_escrow_balance,
&total_deposit_fee_income, &total_deposit_fee_income,
&total_melt_fee_income, &total_melt_fee_income,
@ -2051,9 +2067,9 @@ analyze_coins (void *cls)
&total_recoup_loss, &total_recoup_loss,
&total_irregular_recoups); &total_irregular_recoups);
else else
qs = adb->insert_balance_summary (adb->cls, qs = TALER_ARL_adb->insert_balance_summary (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&total_escrow_balance, &total_escrow_balance,
&total_deposit_fee_income, &total_deposit_fee_income,
&total_melt_fee_income, &total_melt_fee_income,
@ -2068,14 +2084,14 @@ analyze_coins (void *cls)
} }
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp)
qs = adb->update_auditor_progress_coin (adb->cls, qs = TALER_ARL_adb->update_auditor_progress_coin (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&ppc); &ppc);
else else
qs = adb->insert_auditor_progress_coin (adb->cls, qs = TALER_ARL_adb->insert_auditor_progress_coin (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&ppc); &ppc);
if (0 >= qs) if (0 >= qs)
{ {
@ -2100,24 +2116,24 @@ analyze_coins (void *cls)
* *
* @param cls closure * @param cls closure
* @param args remaining command-line arguments * @param args remaining command-line arguments
* @param cfgfile name of the configuration file used (for saving, can be NULL!) * @param TALER_ARL_cfgfile name of the configuration file used (for saving, can be NULL!)
* @param c configuration * @param c configuration
*/ */
static void static void
run (void *cls, run (void *cls,
char *const *args, char *const *args,
const char *cfgfile, const char *TALER_ARL_cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c) const struct GNUNET_CONFIGURATION_Handle *c)
{ {
json_t *report; json_t *report;
(void) cls; (void) cls;
(void) args; (void) args;
(void) cfgfile; (void) TALER_ARL_cfgfile;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Launching auditor\n"); "Launching auditor\n");
if (GNUNET_OK != if (GNUNET_OK !=
setup_globals (c)) TALER_ARL_init (c))
{ {
global_ret = 1; global_ret = 1;
return; return;
@ -2125,49 +2141,52 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting audit\n"); "Starting audit\n");
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&reported_emergency_loss)); &reported_emergency_loss));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&reported_emergency_risk_by_amount)); &
reported_emergency_risk_by_amount));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&reported_emergency_risk_by_count)); &
reported_emergency_risk_by_count));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&reported_emergency_loss_by_count)); &
reported_emergency_loss_by_count));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_escrow_balance)); &total_escrow_balance));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_risk)); &total_risk));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_recoup_loss)); &total_recoup_loss));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_irregular_recoups)); &total_irregular_recoups));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_deposit_fee_income)); &total_deposit_fee_income));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_melt_fee_income)); &total_melt_fee_income));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_refund_fee_income)); &total_refund_fee_income));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_arithmetic_delta_plus)); &total_arithmetic_delta_plus));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_arithmetic_delta_minus)); &total_arithmetic_delta_minus));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_bad_sig_loss)); &total_bad_sig_loss));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_refresh_hanging)); &total_refresh_hanging));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_emergencies = json_array ())); (report_emergencies = json_array ()));
@ -2176,13 +2195,14 @@ run (void *cls,
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_row_inconsistencies = json_array ())); (report_row_inconsistencies = json_array ()));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_amount_arithmetic_inconsistencies = json_array ())); (report_amount_arithmetic_inconsistencies =
json_array ()));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_bad_sig_losses = json_array ())); (report_bad_sig_losses = json_array ()));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_refreshs_hanging = json_array ())); (report_refreshs_hanging = json_array ()));
if (GNUNET_OK != if (GNUNET_OK !=
setup_sessions_and_run (&analyze_coins, TALER_ARL_setup_sessions_and_run (&analyze_coins,
NULL)) NULL))
{ {
global_ret = 1; global_ret = 1;
@ -2203,11 +2223,13 @@ run (void *cls,
"total_active_risk", "total_active_risk",
TALER_JSON_from_amount (&total_risk), TALER_JSON_from_amount (&total_risk),
"total_deposit_fee_income", "total_deposit_fee_income",
TALER_JSON_from_amount (&total_deposit_fee_income), TALER_JSON_from_amount (
&total_deposit_fee_income),
"total_melt_fee_income", "total_melt_fee_income",
TALER_JSON_from_amount (&total_melt_fee_income), TALER_JSON_from_amount (&total_melt_fee_income),
"total_refund_fee_income", "total_refund_fee_income",
TALER_JSON_from_amount (&total_refund_fee_income), TALER_JSON_from_amount (
&total_refund_fee_income),
/* Block #2 */ /* Block #2 */
/* Tested in test-auditor.sh #18 */ /* Tested in test-auditor.sh #18 */
"emergencies", "emergencies",
@ -2229,9 +2251,11 @@ run (void *cls,
"amount_arithmetic_inconsistencies", "amount_arithmetic_inconsistencies",
report_amount_arithmetic_inconsistencies, report_amount_arithmetic_inconsistencies,
"total_arithmetic_delta_plus", "total_arithmetic_delta_plus",
TALER_JSON_from_amount (&total_arithmetic_delta_plus), TALER_JSON_from_amount (
&total_arithmetic_delta_plus),
"total_arithmetic_delta_minus", "total_arithmetic_delta_minus",
TALER_JSON_from_amount (&total_arithmetic_delta_minus), TALER_JSON_from_amount (
&total_arithmetic_delta_minus),
/* Tested in test-auditor.sh #12 */ /* Tested in test-auditor.sh #12 */
"total_refresh_hanging", "total_refresh_hanging",
TALER_JSON_from_amount (&total_refresh_hanging), TALER_JSON_from_amount (&total_refresh_hanging),
@ -2250,7 +2274,8 @@ run (void *cls,
&reported_emergency_risk_by_count), &reported_emergency_risk_by_count),
/* Tested in test-auditor.sh #18 */ /* Tested in test-auditor.sh #18 */
"emergencies_loss", "emergencies_loss",
TALER_JSON_from_amount (&reported_emergency_loss), TALER_JSON_from_amount (
&reported_emergency_loss),
/* Tested in test-auditor.sh #18 */ /* Tested in test-auditor.sh #18 */
"emergencies_loss_by_count", "emergencies_loss_by_count",
TALER_JSON_from_amount ( TALER_JSON_from_amount (
@ -2268,7 +2293,8 @@ run (void *cls,
(json_int_t) ppc_start.last_recoup_serial_id, (json_int_t) ppc_start.last_recoup_serial_id,
/* Block #6 */ /* Block #6 */
"start_ppc_recoup_refresh_serial_id", "start_ppc_recoup_refresh_serial_id",
(json_int_t) ppc_start.last_recoup_refresh_serial_id, (json_int_t) ppc_start.
last_recoup_refresh_serial_id,
"end_ppc_withdraw_serial_id", "end_ppc_withdraw_serial_id",
(json_int_t) ppc.last_withdraw_serial_id, (json_int_t) ppc.last_withdraw_serial_id,
"end_ppc_deposit_serial_id", "end_ppc_deposit_serial_id",
@ -2283,15 +2309,17 @@ run (void *cls,
"end_ppc_recoup_refresh_serial_id", "end_ppc_recoup_refresh_serial_id",
(json_int_t) ppc.last_recoup_refresh_serial_id, (json_int_t) ppc.last_recoup_refresh_serial_id,
"auditor_start_time", json_string ( "auditor_start_time", json_string (
GNUNET_STRINGS_absolute_time_to_string (start_time)), GNUNET_STRINGS_absolute_time_to_string (
start_time)),
"auditor_end_time", json_string ( "auditor_end_time", json_string (
GNUNET_STRINGS_absolute_time_to_string ( GNUNET_STRINGS_absolute_time_to_string (
GNUNET_TIME_absolute_get ())), GNUNET_TIME_absolute_get ())),
"total_irregular_recoups", "total_irregular_recoups",
TALER_JSON_from_amount (&total_irregular_recoups) TALER_JSON_from_amount (
&total_irregular_recoups)
); );
GNUNET_break (NULL != report); GNUNET_break (NULL != report);
finish_report (report); TALER_ARL_done (report);
} }
@ -2312,11 +2340,11 @@ main (int argc,
"exchange-key", "exchange-key",
"KEY", "KEY",
"public key of the exchange (Crockford base32 encoded)", "public key of the exchange (Crockford base32 encoded)",
&master_pub), &TALER_ARL_master_pub),
GNUNET_GETOPT_option_flag ('r', GNUNET_GETOPT_option_flag ('r',
"restart", "TALER_ARL_restart",
"restart audit from the beginning (required on first run)", "TALER_ARL_restart audit from the beginning (required on first run)",
&restart), &TALER_ARL_restart),
GNUNET_GETOPT_option_timetravel ('T', GNUNET_GETOPT_option_timetravel ('T',
"timetravel"), "timetravel"),
GNUNET_GETOPT_OPTION_END GNUNET_GETOPT_OPTION_END

View File

@ -34,7 +34,7 @@
static int global_ret; static int global_ret;
/** /**
* Array of reports about missing deposit confirmations. * Array of TALER_ARL_reports about missing deposit confirmations.
*/ */
static json_t *report_deposit_confirmation_inconsistencies; static json_t *report_deposit_confirmation_inconsistencies;
@ -58,7 +58,7 @@ struct DepositConfirmationContext
{ {
/** /**
* How many deposit confirmations did we NOT find in the #edb? * How many deposit confirmations did we NOT find in the #TALER_ARL_edb?
*/ */
unsigned long long missed_count; unsigned long long missed_count;
@ -89,8 +89,8 @@ struct DepositConfirmationContext
/** /**
* Given a deposit confirmation from #adb, check that it is also * Given a deposit confirmation from #TALER_ARL_adb, check that it is also
* in #edb. Update the deposit confirmation context accordingly. * in #TALER_ARL_edb. Update the deposit confirmation context accordingly.
* *
* @param cls our `struct DepositConfirmationContext` * @param cls our `struct DepositConfirmationContext`
* @param serial_id row of the @a dc in the database * @param serial_id row of the @a dc in the database
@ -115,8 +115,8 @@ test_dc (void *cls,
dep.h_wire = dc->h_wire; dep.h_wire = dc->h_wire;
dep.refund_deadline = dc->refund_deadline; dep.refund_deadline = dc->refund_deadline;
qs = edb->have_deposit (edb->cls, qs = TALER_ARL_edb->have_deposit (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
&dep, &dep,
GNUNET_NO /* do not check refund deadline */); GNUNET_NO /* do not check refund deadline */);
if (qs > 0) if (qs > 0)
@ -132,11 +132,11 @@ test_dc (void *cls,
dcc->qs = qs; dcc->qs = qs;
return; return;
} }
/* deposit confirmation missing! report! */ /* deposit confirmation missing! TALER_ARL_report! */
report (report_deposit_confirmation_inconsistencies, TALER_ARL_report (report_deposit_confirmation_inconsistencies,
json_pack ("{s:o, s:o, s:I, s:o}", json_pack ("{s:o, s:o, s:I, s:o}",
"timestamp", "timestamp",
json_from_time_abs (dc->timestamp), TALER_ARL_json_from_time_abs (dc->timestamp),
"amount", "amount",
TALER_JSON_from_amount (&dc->amount_without_fee), TALER_JSON_from_amount (&dc->amount_without_fee),
"rowid", "rowid",
@ -154,7 +154,7 @@ test_dc (void *cls,
/** /**
* Check that the deposit-confirmations that were reported to * Check that the deposit-confirmations that were TALER_ARL_reported to
* us by merchants are also in the exchange's database. * us by merchants are also in the exchange's database.
* *
* @param cls closure * @param cls closure
@ -173,9 +173,11 @@ analyze_deposit_confirmations (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Analyzing deposit confirmations\n"); "Analyzing deposit confirmations\n");
ppdc.last_deposit_confirmation_serial_id = 0; ppdc.last_deposit_confirmation_serial_id = 0;
qsp = adb->get_auditor_progress_deposit_confirmation (adb->cls, qsp = TALER_ARL_adb->get_auditor_progress_deposit_confirmation (
asession, TALER_ARL_adb->cls,
&master_pub, TALER_ARL_asession,
&
TALER_ARL_master_pub,
&ppdc); &ppdc);
if (0 > qsp) if (0 > qsp)
{ {
@ -197,15 +199,16 @@ analyze_deposit_confirmations (void *cls)
/* setup 'cc' */ /* setup 'cc' */
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&dcc.missed_amount)); &dcc.missed_amount));
dcc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; dcc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
dcc.missed_count = 0LLU; dcc.missed_count = 0LLU;
dcc.first_missed_coin_serial = UINT64_MAX; dcc.first_missed_coin_serial = UINT64_MAX;
qsx = adb->get_deposit_confirmations (adb->cls, qsx = TALER_ARL_adb->get_deposit_confirmations (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
ppdc.last_deposit_confirmation_serial_id, ppdc.
last_deposit_confirmation_serial_id,
&test_dc, &test_dc,
&dcc); &dcc);
if (0 > qsx) if (0 > qsx)
@ -229,14 +232,18 @@ analyze_deposit_confirmations (void *cls)
/* sync 'cc' back to disk */ /* sync 'cc' back to disk */
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp)
qs = adb->update_auditor_progress_deposit_confirmation (adb->cls, qs = TALER_ARL_adb->update_auditor_progress_deposit_confirmation (
asession, TALER_ARL_adb->cls,
&master_pub, TALER_ARL_asession,
&
TALER_ARL_master_pub,
&ppdc); &ppdc);
else else
qs = adb->insert_auditor_progress_deposit_confirmation (adb->cls, qs = TALER_ARL_adb->insert_auditor_progress_deposit_confirmation (
asession, TALER_ARL_adb->cls,
&master_pub, TALER_ARL_asession,
&
TALER_ARL_master_pub,
&ppdc); &ppdc);
if (0 >= qs) if (0 >= qs)
{ {
@ -260,24 +267,22 @@ analyze_deposit_confirmations (void *cls)
* *
* @param cls closure * @param cls closure
* @param args remaining command-line arguments * @param args remaining command-line arguments
* @param cfgfile name of the configuration file used (for saving, can be NULL!) * @param TALER_ARL_cfgfile name of the configuration file used (for saving, can be NULL!)
* @param c configuration * @param c configuration
*/ */
static void static void
run (void *cls, run (void *cls,
char *const *args, char *const *args,
const char *cfgfile, const char *TALER_ARL_cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c) const struct GNUNET_CONFIGURATION_Handle *c)
{ {
json_t *report;
(void) cls; (void) cls;
(void) args; (void) args;
(void) cfgfile; (void) TALER_ARL_cfgfile;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Launching auditor\n"); "Launching auditor\n");
if (GNUNET_OK != if (GNUNET_OK !=
setup_globals (c)) TALER_ARL_init (c))
{ {
global_ret = 1; global_ret = 1;
return; return;
@ -287,7 +292,7 @@ run (void *cls,
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_deposit_confirmation_inconsistencies = json_array ())); (report_deposit_confirmation_inconsistencies = json_array ()));
if (GNUNET_OK != if (GNUNET_OK !=
setup_sessions_and_run (&analyze_deposit_confirmations, TALER_ARL_setup_sessions_and_run (&analyze_deposit_confirmations,
NULL)) NULL))
{ {
global_ret = 1; global_ret = 1;
@ -295,6 +300,9 @@ run (void *cls,
} }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Audit complete\n"); "Audit complete\n");
{
json_t *report;
report = json_pack ("{s:o, s:o, s:I}", report = json_pack ("{s:o, s:o, s:I}",
"deposit_confirmation_inconsistencies", "deposit_confirmation_inconsistencies",
report_deposit_confirmation_inconsistencies, report_deposit_confirmation_inconsistencies,
@ -305,7 +313,8 @@ run (void *cls,
&total_missed_deposit_confirmations) &total_missed_deposit_confirmations)
); );
GNUNET_break (NULL != report); GNUNET_break (NULL != report);
finish_report (report); TALER_ARL_done (report);
}
} }
@ -326,11 +335,11 @@ main (int argc,
"exchange-key", "exchange-key",
"KEY", "KEY",
"public key of the exchange (Crockford base32 encoded)", "public key of the exchange (Crockford base32 encoded)",
&master_pub), &TALER_ARL_master_pub),
GNUNET_GETOPT_option_flag ('r', GNUNET_GETOPT_option_flag ('r',
"restart", "TALER_ARL_restart",
"restart audit from the beginning (required on first run)", "TALER_ARL_restart audit from the beginning (required on first run)",
&restart), &TALER_ARL_restart),
GNUNET_GETOPT_option_timetravel ('T', GNUNET_GETOPT_option_timetravel ('T',
"timetravel"), "timetravel"),
GNUNET_GETOPT_OPTION_END GNUNET_GETOPT_OPTION_END

View File

@ -14,7 +14,7 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/ */
/** /**
* @file auditor/taler-auditor-reserves.c * @file auditor/taler-helper-auditor-reserves.c
* @brief audits the reserves of an exchange database * @brief audits the reserves of an exchange database
* @author Christian Grothoff * @author Christian Grothoff
*/ */
@ -162,8 +162,10 @@ static struct TALER_Amount total_bad_sig_loss;
static void static void
report_amount_arithmetic_inconsistency (const char *operation, report_amount_arithmetic_inconsistency (const char *operation,
uint64_t rowid, uint64_t rowid,
const struct TALER_Amount *exchange, const struct
const struct TALER_Amount *auditor, TALER_Amount *exchange,
const struct
TALER_Amount *auditor,
int profitable) int profitable)
{ {
struct TALER_Amount delta; struct TALER_Amount delta;
@ -187,7 +189,7 @@ report_amount_arithmetic_inconsistency (const char *operation,
auditor, auditor,
exchange)); exchange));
} }
report (report_amount_arithmetic_inconsistencies, TALER_ARL_report (report_amount_arithmetic_inconsistencies,
json_pack ("{s:s, s:I, s:o, s:o, s:I}", json_pack ("{s:s, s:I, s:o, s:o, s:I}",
"operation", operation, "operation", operation,
"rowid", (json_int_t) rowid, "rowid", (json_int_t) rowid,
@ -219,7 +221,7 @@ report_row_inconsistency (const char *table,
uint64_t rowid, uint64_t rowid,
const char *diagnostic) const char *diagnostic)
{ {
report (report_row_inconsistencies, TALER_ARL_report (report_row_inconsistencies,
json_pack ("{s:s, s:I, s:s}", json_pack ("{s:s, s:I, s:s}",
"table", table, "table", table,
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
@ -306,10 +308,10 @@ load_auditor_reserve_summary (struct ReserveSummary *rs)
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
uint64_t rowid; uint64_t rowid;
qs = adb->get_reserve_info (adb->cls, qs = TALER_ARL_adb->get_reserve_info (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&rs->reserve_pub, &rs->reserve_pub,
&master_pub, &TALER_ARL_master_pub,
&rowid, &rowid,
&rs->a_balance, &rs->a_balance,
&rs->a_withdraw_fee_balance, &rs->a_withdraw_fee_balance,
@ -502,7 +504,7 @@ handle_reserve_out (void *cls,
ppr.last_reserve_out_serial_id = rowid + 1; ppr.last_reserve_out_serial_id = rowid + 1;
/* lookup denomination pub data (make sure denom_pub is valid, establish fees) */ /* lookup denomination pub data (make sure denom_pub is valid, establish fees) */
qs = get_denomination_info (denom_pub, qs = TALER_ARL_get_denomination_info (denom_pub,
&issue, &issue,
&wsrd.h_denomination_pub); &wsrd.h_denomination_pub);
if (0 > qs) if (0 > qs)
@ -535,12 +537,13 @@ handle_reserve_out (void *cls,
if ( (valid_start.abs_value_us > execution_date.abs_value_us) || if ( (valid_start.abs_value_us > execution_date.abs_value_us) ||
(expire_withdraw.abs_value_us < execution_date.abs_value_us) ) (expire_withdraw.abs_value_us < execution_date.abs_value_us) )
{ {
report (denomination_key_validity_withdraw_inconsistencies, TALER_ARL_report (denomination_key_validity_withdraw_inconsistencies,
json_pack ("{s:I, s:o, s:o, s:o}", json_pack ("{s:I, s:o, s:o, s:o}",
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
"execution_date", "execution_date",
json_from_time_abs (execution_date), TALER_ARL_json_from_time_abs (execution_date),
"reserve_pub", GNUNET_JSON_from_data_auto (reserve_pub), "reserve_pub", GNUNET_JSON_from_data_auto (
reserve_pub),
"denompub_h", GNUNET_JSON_from_data_auto ( "denompub_h", GNUNET_JSON_from_data_auto (
&wsrd.h_denomination_pub))); &wsrd.h_denomination_pub)));
} }
@ -559,12 +562,14 @@ handle_reserve_out (void *cls,
&reserve_sig->eddsa_signature, &reserve_sig->eddsa_signature,
&reserve_pub->eddsa_pub)) &reserve_pub->eddsa_pub))
{ {
report (report_bad_sig_losses, TALER_ARL_report (report_bad_sig_losses,
json_pack ("{s:s, s:I, s:o, s:o}", json_pack ("{s:s, s:I, s:o, s:o}",
"operation", "withdraw", "operation", "withdraw",
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
"loss", TALER_JSON_from_amount (amount_with_fee), "loss", TALER_JSON_from_amount (
"key_pub", GNUNET_JSON_from_data_auto (reserve_pub))); amount_with_fee),
"key_pub", GNUNET_JSON_from_data_auto (
reserve_pub)));
GNUNET_break (GNUNET_OK == GNUNET_break (GNUNET_OK ==
TALER_amount_add (&total_bad_sig_loss, TALER_amount_add (&total_bad_sig_loss,
&total_bad_sig_loss, &total_bad_sig_loss,
@ -682,7 +687,7 @@ handle_recoup_by_reserve (void *cls,
&coin_sig->eddsa_signature, &coin_sig->eddsa_signature,
&coin->coin_pub.eddsa_pub)) &coin->coin_pub.eddsa_pub))
{ {
report (report_bad_sig_losses, TALER_ARL_report (report_bad_sig_losses,
json_pack ("{s:s, s:I, s:o, s:o}", json_pack ("{s:s, s:I, s:o, s:o}",
"operation", "recoup", "operation", "recoup",
"row", (json_int_t) rowid, "row", (json_int_t) rowid,
@ -700,8 +705,8 @@ handle_recoup_by_reserve (void *cls,
&pr.h_denom_pub); &pr.h_denom_pub);
if (NULL == rev) if (NULL == rev)
{ {
qs = edb->get_denomination_revocation (edb->cls, qs = TALER_ARL_edb->get_denomination_revocation (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
&pr.h_denom_pub, &pr.h_denom_pub,
&msig, &msig,
&rev_rowid); &rev_rowid);
@ -735,7 +740,7 @@ handle_recoup_by_reserve (void *cls,
TALER_SIGNATURE_MASTER_DENOMINATION_KEY_REVOKED, TALER_SIGNATURE_MASTER_DENOMINATION_KEY_REVOKED,
&kr.purpose, &kr.purpose,
&msig.eddsa_signature, &msig.eddsa_signature,
&master_pub.eddsa_pub)) &TALER_ARL_master_pub.eddsa_pub))
{ {
rev = "master signature invalid"; rev = "master signature invalid";
} }
@ -757,12 +762,13 @@ handle_recoup_by_reserve (void *cls,
if ( (NULL != rev) && if ( (NULL != rev) &&
(0 == strcmp (rev, "master signature invalid")) ) (0 == strcmp (rev, "master signature invalid")) )
{ {
report (report_bad_sig_losses, TALER_ARL_report (report_bad_sig_losses,
json_pack ("{s:s, s:I, s:o, s:o}", json_pack ("{s:s, s:I, s:o, s:o}",
"operation", "recoup-master", "operation", "recoup-master",
"row", (json_int_t) rev_rowid, "row", (json_int_t) rev_rowid,
"loss", TALER_JSON_from_amount (amount), "loss", TALER_JSON_from_amount (amount),
"key_pub", GNUNET_JSON_from_data_auto (&master_pub))); "key_pub", GNUNET_JSON_from_data_auto (
&TALER_ARL_master_pub)));
GNUNET_break (GNUNET_OK == GNUNET_break (GNUNET_OK ==
TALER_amount_add (&total_bad_sig_loss, TALER_amount_add (&total_bad_sig_loss,
&total_bad_sig_loss, &total_bad_sig_loss,
@ -843,8 +849,8 @@ get_closing_fee (const char *receiver_account,
"Method is `%s'\n", "Method is `%s'\n",
method); method);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
edb->get_wire_fee (edb->cls, TALER_ARL_edb->get_wire_fee (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
method, method,
atime, atime,
&start_date, &start_date,
@ -950,7 +956,8 @@ handle_reserve_closed (void *cls,
else if (0 != TALER_amount_cmp (&expected_fee, else if (0 != TALER_amount_cmp (&expected_fee,
closing_fee)) closing_fee))
{ {
report_amount_arithmetic_inconsistency ("closing aggregation fee", report_amount_arithmetic_inconsistency (
"closing aggregation fee",
rowid, rowid,
closing_fee, closing_fee,
&expected_fee, &expected_fee,
@ -1006,8 +1013,8 @@ verify_reserve_balance (void *cls,
ret = GNUNET_OK; ret = GNUNET_OK;
reserve.pub = rs->reserve_pub; reserve.pub = rs->reserve_pub;
qs = edb->reserves_get (edb->cls, qs = TALER_ARL_edb->reserves_get (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
&reserve); &reserve);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{ {
@ -1053,7 +1060,8 @@ verify_reserve_balance (void *cls,
TALER_amount_add (&total_balance_insufficient_loss, TALER_amount_add (&total_balance_insufficient_loss,
&total_balance_insufficient_loss, &total_balance_insufficient_loss,
&loss)); &loss));
report (report_reserve_balance_insufficient_inconsistencies, TALER_ARL_report (
report_reserve_balance_insufficient_inconsistencies,
json_pack ("{s:o, s:o}", json_pack ("{s:o, s:o}",
"reserve_pub", "reserve_pub",
GNUNET_JSON_from_data_auto (&rs->reserve_pub), GNUNET_JSON_from_data_auto (&rs->reserve_pub),
@ -1091,7 +1099,8 @@ verify_reserve_balance (void *cls,
&total_balance_summary_delta_minus, &total_balance_summary_delta_minus,
&delta)); &delta));
} }
report (report_reserve_balance_summary_wrong_inconsistencies, TALER_ARL_report (
report_reserve_balance_summary_wrong_inconsistencies,
json_pack ("{s:o, s:o, s:o}", json_pack ("{s:o, s:o, s:o}",
"reserve_pub", "reserve_pub",
GNUNET_JSON_from_data_auto (&rs->reserve_pub), GNUNET_JSON_from_data_auto (&rs->reserve_pub),
@ -1120,14 +1129,16 @@ verify_reserve_balance (void *cls,
TALER_amount_add (&total_balance_reserve_not_closed, TALER_amount_add (&total_balance_reserve_not_closed,
&total_balance_reserve_not_closed, &total_balance_reserve_not_closed,
&nbalance)); &nbalance));
report (report_reserve_not_closed_inconsistencies, TALER_ARL_report (report_reserve_not_closed_inconsistencies,
json_pack ("{s:o, s:o, s:o}", json_pack ("{s:o, s:o, s:o}",
"reserve_pub", "reserve_pub",
GNUNET_JSON_from_data_auto (&rs->reserve_pub), GNUNET_JSON_from_data_auto (
&rs->reserve_pub),
"balance", "balance",
TALER_JSON_from_amount (&nbalance), TALER_JSON_from_amount (&nbalance),
"expiration_time", "expiration_time",
json_from_time_abs (rs->a_expiration_date))); TALER_ARL_json_from_time_abs (
rs->a_expiration_date)));
} }
} }
else else
@ -1136,14 +1147,16 @@ verify_reserve_balance (void *cls,
TALER_amount_add (&total_balance_reserve_not_closed, TALER_amount_add (&total_balance_reserve_not_closed,
&total_balance_reserve_not_closed, &total_balance_reserve_not_closed,
&nbalance)); &nbalance));
report (report_reserve_not_closed_inconsistencies, TALER_ARL_report (report_reserve_not_closed_inconsistencies,
json_pack ("{s:o, s:o, s:o, s:s}", json_pack ("{s:o, s:o, s:o, s:s}",
"reserve_pub", "reserve_pub",
GNUNET_JSON_from_data_auto (&rs->reserve_pub), GNUNET_JSON_from_data_auto (
&rs->reserve_pub),
"balance", "balance",
TALER_JSON_from_amount (&nbalance), TALER_JSON_from_amount (&nbalance),
"expiration_time", "expiration_time",
json_from_time_abs (rs->a_expiration_date), TALER_ARL_json_from_time_abs (
rs->a_expiration_date),
"diagnostic", "diagnostic",
"could not determine closing fee")); "could not determine closing fee"));
} }
@ -1191,10 +1204,10 @@ verify_reserve_balance (void *cls,
"Final balance of reserve `%s' is %s, dropping it\n", "Final balance of reserve `%s' is %s, dropping it\n",
TALER_B2S (&rs->reserve_pub), TALER_B2S (&rs->reserve_pub),
TALER_amount2s (&nbalance)); TALER_amount2s (&nbalance));
qs = adb->del_reserve_info (adb->cls, qs = TALER_ARL_adb->del_reserve_info (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&rs->reserve_pub, &rs->reserve_pub,
&master_pub); &TALER_ARL_master_pub);
if (0 >= qs) if (0 >= qs)
{ {
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@ -1220,18 +1233,18 @@ verify_reserve_balance (void *cls,
TALER_amount2s (&nbalance)); TALER_amount2s (&nbalance));
if (rs->had_ri) if (rs->had_ri)
qs = adb->update_reserve_info (adb->cls, qs = TALER_ARL_adb->update_reserve_info (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&rs->reserve_pub, &rs->reserve_pub,
&master_pub, &TALER_ARL_master_pub,
&nbalance, &nbalance,
&rs->a_withdraw_fee_balance, &rs->a_withdraw_fee_balance,
rs->a_expiration_date); rs->a_expiration_date);
else else
qs = adb->insert_reserve_info (adb->cls, qs = TALER_ARL_adb->insert_reserve_info (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&rs->reserve_pub, &rs->reserve_pub,
&master_pub, &TALER_ARL_master_pub,
&nbalance, &nbalance,
&rs->a_withdraw_fee_balance, &rs->a_withdraw_fee_balance,
rs->a_expiration_date, rs->a_expiration_date,
@ -1270,9 +1283,9 @@ analyze_reserves (void *cls)
(void) cls; (void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Analyzing reserves\n"); "Analyzing reserves\n");
qsp = adb->get_auditor_progress_reserve (adb->cls, qsp = TALER_ARL_adb->get_auditor_progress_reserve (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&ppr); &ppr);
if (0 > qsp) if (0 > qsp)
{ {
@ -1296,9 +1309,9 @@ analyze_reserves (void *cls)
(unsigned long long) ppr.last_reserve_close_serial_id); (unsigned long long) ppr.last_reserve_close_serial_id);
} }
rc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; rc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
qsx = adb->get_reserve_summary (adb->cls, qsx = TALER_ARL_adb->get_reserve_summary (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&total_escrow_balance, &total_escrow_balance,
&total_withdraw_fee_income); &total_withdraw_fee_income);
if (qsx < 0) if (qsx < 0)
@ -1311,9 +1324,10 @@ analyze_reserves (void *cls)
rc.revoked = GNUNET_CONTAINER_multihashmap_create (4, rc.revoked = GNUNET_CONTAINER_multihashmap_create (4,
GNUNET_NO); GNUNET_NO);
qs = edb->select_reserves_in_above_serial_id (edb->cls, qs = TALER_ARL_edb->select_reserves_in_above_serial_id (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
ppr.last_reserve_in_serial_id, ppr.
last_reserve_in_serial_id,
&handle_reserve_in, &handle_reserve_in,
&rc); &rc);
if (qs < 0) if (qs < 0)
@ -1321,9 +1335,10 @@ analyze_reserves (void *cls)
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs; return qs;
} }
qs = edb->select_withdrawals_above_serial_id (edb->cls, qs = TALER_ARL_edb->select_withdrawals_above_serial_id (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
ppr.last_reserve_out_serial_id, ppr.
last_reserve_out_serial_id,
&handle_reserve_out, &handle_reserve_out,
&rc); &rc);
if (qs < 0) if (qs < 0)
@ -1331,9 +1346,10 @@ analyze_reserves (void *cls)
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs; return qs;
} }
qs = edb->select_recoup_above_serial_id (edb->cls, qs = TALER_ARL_edb->select_recoup_above_serial_id (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
ppr.last_reserve_recoup_serial_id, ppr.
last_reserve_recoup_serial_id,
&handle_recoup_by_reserve, &handle_recoup_by_reserve,
&rc); &rc);
if (qs < 0) if (qs < 0)
@ -1341,11 +1357,12 @@ analyze_reserves (void *cls)
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs; return qs;
} }
qs = edb->select_reserve_closed_above_serial_id (edb->cls, qs = TALER_ARL_edb->select_reserve_closed_above_serial_id (TALER_ARL_edb->cls,
esession, TALER_ARL_esession,
ppr. ppr.
last_reserve_close_serial_id, last_reserve_close_serial_id,
&handle_reserve_closed, &
handle_reserve_closed,
&rc); &rc);
if (qs < 0) if (qs < 0)
{ {
@ -1366,17 +1383,17 @@ analyze_reserves (void *cls)
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsx) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsx)
{ {
qs = adb->insert_reserve_summary (adb->cls, qs = TALER_ARL_adb->insert_reserve_summary (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&total_escrow_balance, &total_escrow_balance,
&total_withdraw_fee_income); &total_withdraw_fee_income);
} }
else else
{ {
qs = adb->update_reserve_summary (adb->cls, qs = TALER_ARL_adb->update_reserve_summary (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&total_escrow_balance, &total_escrow_balance,
&total_withdraw_fee_income); &total_withdraw_fee_income);
} }
@ -1386,14 +1403,14 @@ analyze_reserves (void *cls)
return qs; return qs;
} }
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp)
qs = adb->update_auditor_progress_reserve (adb->cls, qs = TALER_ARL_adb->update_auditor_progress_reserve (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&ppr); &ppr);
else else
qs = adb->insert_auditor_progress_reserve (adb->cls, qs = TALER_ARL_adb->insert_auditor_progress_reserve (TALER_ARL_adb->cls,
asession, TALER_ARL_asession,
&master_pub, &TALER_ARL_master_pub,
&ppr); &ppr);
if (0 >= qs) if (0 >= qs)
{ {
@ -1417,36 +1434,34 @@ analyze_reserves (void *cls)
* *
* @param cls closure * @param cls closure
* @param args remaining command-line arguments * @param args remaining command-line arguments
* @param cfgfile name of the configuration file used (for saving, can be NULL!) * @param TALER_ARL_cfgfile name of the configuration file used (for saving, can be NULL!)
* @param c configuration * @param c configuration
*/ */
static void static void
run (void *cls, run (void *cls,
char *const *args, char *const *args,
const char *cfgfile, const char *TALER_ARL_cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c) const struct GNUNET_CONFIGURATION_Handle *c)
{ {
json_t *report;
(void) cls; (void) cls;
(void) args; (void) args;
(void) cfgfile; (void) TALER_ARL_cfgfile;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Launching auditor\n"); "Launching auditor\n");
if (GNUNET_OK != if (GNUNET_OK !=
setup_globals (cfg)) TALER_ARL_init (TALER_ARL_cfg))
{ {
global_ret = 1; global_ret = 1;
return; return;
} }
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (cfg, GNUNET_CONFIGURATION_get_value_time (TALER_ARL_cfg,
"exchangedb", "exchangTALER_ARL_edb",
"IDLE_RESERVE_EXPIRATION_TIME", "IDLE_RESERVE_EXPIRATION_TIME",
&idle_reserve_expiration_time)) &idle_reserve_expiration_time))
{ {
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"exchangedb", "exchangTALER_ARL_edb",
"IDLE_RESERVE_EXPIRATION_TIME"); "IDLE_RESERVE_EXPIRATION_TIME");
global_ret = 1; global_ret = 1;
return; return;
@ -1454,34 +1469,34 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting audit\n"); "Starting audit\n");
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_escrow_balance)); &total_escrow_balance));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_irregular_recoups)); &total_irregular_recoups));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_withdraw_fee_income)); &total_withdraw_fee_income));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_balance_insufficient_loss)); &total_balance_insufficient_loss));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_balance_summary_delta_plus)); &total_balance_summary_delta_plus));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_balance_summary_delta_minus)); &total_balance_summary_delta_minus));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_arithmetic_delta_plus)); &total_arithmetic_delta_plus));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_arithmetic_delta_minus)); &total_arithmetic_delta_minus));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_balance_reserve_not_closed)); &total_balance_reserve_not_closed));
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (currency, TALER_amount_get_zero (TALER_ARL_currency,
&total_bad_sig_loss)); &total_bad_sig_loss));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_row_inconsistencies = json_array ())); (report_row_inconsistencies = json_array ()));
@ -1489,24 +1504,31 @@ run (void *cls,
(denomination_key_validity_withdraw_inconsistencies = (denomination_key_validity_withdraw_inconsistencies =
json_array ())); json_array ()));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_reserve_balance_summary_wrong_inconsistencies = (report_reserve_balance_summary_wrong_inconsistencies
=
json_array ())); json_array ()));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_reserve_balance_insufficient_inconsistencies = (report_reserve_balance_insufficient_inconsistencies
=
json_array ())); json_array ()));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_reserve_not_closed_inconsistencies = json_array ())); (report_reserve_not_closed_inconsistencies =
json_array ()));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_amount_arithmetic_inconsistencies = json_array ())); (report_amount_arithmetic_inconsistencies =
json_array ()));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
(report_bad_sig_losses = json_array ())); (report_bad_sig_losses = json_array ()));
if (GNUNET_OK != if (GNUNET_OK !=
setup_sessions_and_run (&analyze_reserves, TALER_ARL_setup_sessions_and_run (&analyze_reserves,
NULL)) NULL))
{ {
global_ret = 1; global_ret = 1;
return; return;
} }
{
json_t *report;
report = json_pack ("{s:o, s:o, s:o, s:o, s:o," report = json_pack ("{s:o, s:o, s:o, s:o, s:o,"
" s:o, s:o, s:o, s:o, s:o," " s:o, s:o, s:o, s:o, s:o,"
" s:o, s:o, s:o, s:o, s:o," " s:o, s:o, s:o, s:o, s:o,"
@ -1518,7 +1540,8 @@ run (void *cls,
report_reserve_balance_insufficient_inconsistencies, report_reserve_balance_insufficient_inconsistencies,
/* Tested in test-auditor.sh #3 */ /* Tested in test-auditor.sh #3 */
"total_loss_balance_insufficient", "total_loss_balance_insufficient",
TALER_JSON_from_amount (&total_balance_insufficient_loss), TALER_JSON_from_amount (
&total_balance_insufficient_loss),
/* Tested in test-auditor.sh #3 */ /* Tested in test-auditor.sh #3 */
"reserve_balance_summary_wrong_inconsistencies", "reserve_balance_summary_wrong_inconsistencies",
report_reserve_balance_summary_wrong_inconsistencies, report_reserve_balance_summary_wrong_inconsistencies,
@ -1532,7 +1555,8 @@ run (void *cls,
"total_escrow_balance", "total_escrow_balance",
TALER_JSON_from_amount (&total_escrow_balance), TALER_JSON_from_amount (&total_escrow_balance),
"total_withdraw_fee_income", "total_withdraw_fee_income",
TALER_JSON_from_amount (&total_withdraw_fee_income), TALER_JSON_from_amount (
&total_withdraw_fee_income),
/* Tested in test-auditor.sh #21 */ /* Tested in test-auditor.sh #21 */
"reserve_not_closed_inconsistencies", "reserve_not_closed_inconsistencies",
report_reserve_not_closed_inconsistencies, report_reserve_not_closed_inconsistencies,
@ -1556,25 +1580,33 @@ run (void *cls,
"amount_arithmetic_inconsistencies", "amount_arithmetic_inconsistencies",
report_amount_arithmetic_inconsistencies, report_amount_arithmetic_inconsistencies,
"total_arithmetic_delta_plus", "total_arithmetic_delta_plus",
TALER_JSON_from_amount (&total_arithmetic_delta_plus), TALER_JSON_from_amount (
&total_arithmetic_delta_plus),
/* blocks #4 */ /* blocks #4 */
"total_arithmetic_delta_minus", "total_arithmetic_delta_minus",
TALER_JSON_from_amount (&total_arithmetic_delta_minus), TALER_JSON_from_amount (
&total_arithmetic_delta_minus),
"auditor_start_time", "auditor_start_time",
json_from_time_abs (start_time), TALER_ARL_json_from_time_abs (
start_time),
"auditor_end_time", "auditor_end_time",
json_from_time_abs (GNUNET_TIME_absolute_get ()), TALER_ARL_json_from_time_abs (
GNUNET_TIME_absolute_get ()),
"total_irregular_recoups", "total_irregular_recoups",
TALER_JSON_from_amount (&total_irregular_recoups), TALER_JSON_from_amount (
&total_irregular_recoups),
"start_ppr_reserve_in_serial_id", "start_ppr_reserve_in_serial_id",
(json_int_t) ppr_start.last_reserve_in_serial_id, (json_int_t) ppr_start.last_reserve_in_serial_id,
/* blocks #5 */ /* blocks #5 */
"start_ppr_reserve_out_serial_id", "start_ppr_reserve_out_serial_id",
(json_int_t) ppr_start.last_reserve_out_serial_id, (json_int_t) ppr_start.
last_reserve_out_serial_id,
"start_ppr_reserve_recoup_serial_id", "start_ppr_reserve_recoup_serial_id",
(json_int_t) ppr_start.last_reserve_recoup_serial_id, (json_int_t) ppr_start.
last_reserve_recoup_serial_id,
"start_ppr_reserve_close_serial_id", "start_ppr_reserve_close_serial_id",
(json_int_t) ppr_start.last_reserve_close_serial_id, (json_int_t) ppr_start.
last_reserve_close_serial_id,
"end_ppr_reserve_in_serial_id", "end_ppr_reserve_in_serial_id",
(json_int_t) ppr.last_reserve_in_serial_id, (json_int_t) ppr.last_reserve_in_serial_id,
"end_ppr_reserve_out_serial_id", "end_ppr_reserve_out_serial_id",
@ -1586,7 +1618,8 @@ run (void *cls,
(json_int_t) ppr.last_reserve_close_serial_id (json_int_t) ppr.last_reserve_close_serial_id
); );
GNUNET_break (NULL != report); GNUNET_break (NULL != report);
finish_report (report); TALER_ARL_done (report);
}
} }
@ -1607,11 +1640,11 @@ main (int argc,
"exchange-key", "exchange-key",
"KEY", "KEY",
"public key of the exchange (Crockford base32 encoded)", "public key of the exchange (Crockford base32 encoded)",
&master_pub), &TALER_ARL_master_pub),
GNUNET_GETOPT_option_flag ('r', GNUNET_GETOPT_option_flag ('r',
"restart", "TALER_ARL_restart",
"restart audit from the beginning (required on first run)", "TALER_ARL_restart audit from the beginning (required on first run)",
&restart), &TALER_ARL_restart),
GNUNET_GETOPT_option_timetravel ('T', GNUNET_GETOPT_option_timetravel ('T',
"timetravel"), "timetravel"),
GNUNET_GETOPT_OPTION_END GNUNET_GETOPT_OPTION_END

View File

@ -84,10 +84,10 @@ function audit_only () {
# Also do incremental run # Also do incremental run
$VALGRIND taler-auditor -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-inc.json 2> test-audit-inc.log || exit_fail "auditor failed" $VALGRIND taler-auditor -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-inc.json 2> test-audit-inc.log || exit_fail "auditor failed"
echo -n "." echo -n "."
$VALGRIND taler-wire-auditor -L DEBUG -r -c $CONF -m $MASTER_PUB > test-wire-audit.json 2> test-wire-audit.log || exit_fail "wire auditor failed" $VALGRIND taler-helper-auditor-wire -L DEBUG -r -c $CONF -m $MASTER_PUB > test-wire-audit.json 2> test-wire-audit.log || exit_fail "wire auditor failed"
# Also do incremental run # Also do incremental run
echo -n "." echo -n "."
$VALGRIND taler-wire-auditor -L DEBUG -c $CONF -m $MASTER_PUB > test-wire-audit-inc.json 2> test-wire-audit-inc.log || exit_fail "wire auditor failed" $VALGRIND taler-helper-auditor-wire -L DEBUG -c $CONF -m $MASTER_PUB > test-wire-audit-inc.json 2> test-wire-audit-inc.log || exit_fail "wire auditor failed"
echo " DONE" echo " DONE"
} }
@ -255,7 +255,7 @@ echo -n "Check for lag detection... "
# NOTE: This test is EXPECTED to fail for ~1h after # NOTE: This test is EXPECTED to fail for ~1h after
# re-generating the test database as we do not # re-generating the test database as we do not
# report lag of less than 1h (see GRACE_PERIOD in # report lag of less than 1h (see GRACE_PERIOD in
# taler-wire-auditor.c) # taler-helper-auditor-wire.c)
if [ $DATABASE_AGE -gt 3600 ] if [ $DATABASE_AGE -gt 3600 ]
then then
jq -e .lag_details[0] < test-wire-audit.json > /dev/null || exit_fail "Lag not detected in run without aggregator at age $DELTA" jq -e .lag_details[0] < test-wire-audit.json > /dev/null || exit_fail "Lag not detected in run without aggregator at age $DELTA"
@ -893,7 +893,7 @@ echo "===========15: deposit wire hash wrong================="
# NOTE: This test is EXPECTED to fail for ~1h after # NOTE: This test is EXPECTED to fail for ~1h after
# re-generating the test database as we do not # re-generating the test database as we do not
# report lag of less than 1h (see GRACE_PERIOD in # report lag of less than 1h (see GRACE_PERIOD in
# taler-wire-auditor.c) # taler-helper-auditor-wire.c)
if [ $DATABASE_AGE -gt 3600 ] if [ $DATABASE_AGE -gt 3600 ]
then then
@ -930,7 +930,7 @@ echo "===========16: incorrect wire_out amount================="
# NOTE: This test is EXPECTED to fail for ~1h after # NOTE: This test is EXPECTED to fail for ~1h after
# re-generating the test database as we do not # re-generating the test database as we do not
# report lag of less than 1h (see GRACE_PERIOD in # report lag of less than 1h (see GRACE_PERIOD in
# taler-wire-auditor.c) # taler-helper-auditor-wire.c)
if [ $DATABASE_AGE -gt 3600 ] if [ $DATABASE_AGE -gt 3600 ]
then then
@ -1023,7 +1023,7 @@ echo "===========17: incorrect wire_out timestamp================="
# NOTE: This test is EXPECTED to fail for ~1h after # NOTE: This test is EXPECTED to fail for ~1h after
# re-generating the test database as we do not # re-generating the test database as we do not
# report lag of less than 1h (see GRACE_PERIOD in # report lag of less than 1h (see GRACE_PERIOD in
# taler-wire-auditor.c) # taler-helper-auditor-wire.c)
if [ $DATABASE_AGE -gt 3600 ] if [ $DATABASE_AGE -gt 3600 ]
then then
@ -1115,7 +1115,7 @@ echo "===========19: reserve closure done properly ================="
# NOTE: This test is EXPECTED to fail for ~1h after # NOTE: This test is EXPECTED to fail for ~1h after
# re-generating the test database as we do not # re-generating the test database as we do not
# report lag of less than 1h (see GRACE_PERIOD in # report lag of less than 1h (see GRACE_PERIOD in
# taler-wire-auditor.c) # taler-helper-auditor-wire.c)
if [ $DATABASE_AGE -gt 3600 ] if [ $DATABASE_AGE -gt 3600 ]
then then
@ -1193,7 +1193,7 @@ echo "===========21: reserve closure missreported ================="
# NOTE: This test is EXPECTED to fail for ~1h after # NOTE: This test is EXPECTED to fail for ~1h after
# re-generating the test database as we do not # re-generating the test database as we do not
# report lag of less than 1h (see GRACE_PERIOD in # report lag of less than 1h (see GRACE_PERIOD in
# taler-wire-auditor.c) # taler-helper-auditor-wire.c)
if [ $DATABASE_AGE -gt 3600 ] if [ $DATABASE_AGE -gt 3600 ]
then then
@ -1279,7 +1279,7 @@ echo "===========23: wire out calculations ================="
# NOTE: This test is EXPECTED to fail for ~1h after # NOTE: This test is EXPECTED to fail for ~1h after
# re-generating the test database as we do not # re-generating the test database as we do not
# report lag of less than 1h (see GRACE_PERIOD in # report lag of less than 1h (see GRACE_PERIOD in
# taler-wire-auditor.c) # taler-helper-auditor-wire.c)
if [ $DATABASE_AGE -gt 3600 ] if [ $DATABASE_AGE -gt 3600 ]
then then
@ -1400,7 +1400,7 @@ echo "=========25: inconsistent coin history========="
# NOTE: This test is EXPECTED to fail for ~1h after # NOTE: This test is EXPECTED to fail for ~1h after
# re-generating the test database as we do not # re-generating the test database as we do not
# report lag of less than 1h (see GRACE_PERIOD in # report lag of less than 1h (see GRACE_PERIOD in
# taler-wire-auditor.c) # taler-helper-auditor-wire.c)
if [ $DATABASE_AGE -gt 3600 ] if [ $DATABASE_AGE -gt 3600 ]
then then
@ -1493,7 +1493,7 @@ echo "===========27: duplicate WTID detection ================="
# NOTE: This test is EXPECTED to fail for ~1h after # NOTE: This test is EXPECTED to fail for ~1h after
# re-generating the test database as we do not # re-generating the test database as we do not
# report lag of less than 1h (see GRACE_PERIOD in # report lag of less than 1h (see GRACE_PERIOD in
# taler-wire-auditor.c) # taler-helper-auditor-wire.c)
if [ $DATABASE_AGE -gt 3600 ] if [ $DATABASE_AGE -gt 3600 ]
then then