alpha-renaming to better describe what functions/tables do

This commit is contained in:
Christian Grothoff 2017-03-19 01:09:00 +01:00
parent e4a4a7e193
commit b42ce7e80a
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
4 changed files with 102 additions and 110 deletions

View File

@ -26,16 +26,10 @@
* *
* TODO: * TODO:
* - FIXME: do proper transaction history check in #check_transaction_history() * - FIXME: do proper transaction history check in #check_transaction_history()
* - SANITY: rename functions/operations to better describe what they do!
* - OPTIMIZE/SIMPLIFY: modify auditordb to return DK when we inquire about deposit/refresh/refund, * - OPTIMIZE/SIMPLIFY: modify auditordb to return DK when we inquire about deposit/refresh/refund,
* so we can avoid the costly #get_coin_summary with the transaction history building * so we can avoid the costly #get_coin_summary with the transaction history building
* (at least during #analyze_coins); the logic may be partially useful in * (at least during #analyze_coins); the logic may be partially useful in
* #analyze_merchants (but we won't need the cache!) * #analyze_merchants (but we won't need the cache!)
* - MAJOR: check that aggregation records exist for deposits past payment deadline
* (or that there was a full refund and thus there is no aggregation)
* Conceptual issue: how do we deal with deposits that we already checked
* in the past? => Need a very separate check / pass for this!
* - BEAUTIFY: write reporting logic to output nice report beyond GNUNET_log()
*/ */
#include "platform.h" #include "platform.h"
#include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_util_lib.h>
@ -1147,7 +1141,7 @@ init_denomination (const struct GNUNET_HashCode *denom_hash,
* @return NULL on error * @return NULL on error
*/ */
static struct DenominationSummary * static struct DenominationSummary *
get_denomination_summary (struct CoinContext *cc, get_balance_summary (struct CoinContext *cc,
const struct TALER_EXCHANGEDB_DenominationKeyInformationP *dki, const struct TALER_EXCHANGEDB_DenominationKeyInformationP *dki,
const struct GNUNET_HashCode *dh) const struct GNUNET_HashCode *dh)
{ {
@ -1446,7 +1440,7 @@ withdraw_cb (void *cls,
GNUNET_break (0); GNUNET_break (0);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
ds = get_denomination_summary (cc, ds = get_balance_summary (cc,
dki, dki,
&dh); &dh);
TALER_amount_ntoh (&value, TALER_amount_ntoh (&value,
@ -1625,7 +1619,7 @@ refresh_session_cb (void *cls,
struct DenominationSummary *dsi; struct DenominationSummary *dsi;
struct TALER_Amount value; struct TALER_Amount value;
dsi = get_denomination_summary (cc, dsi = get_balance_summary (cc,
new_dki[i], new_dki[i],
&new_dki[i]->properties.denom_hash); &new_dki[i]->properties.denom_hash);
TALER_amount_ntoh (&value, TALER_amount_ntoh (&value,
@ -1650,7 +1644,7 @@ refresh_session_cb (void *cls,
} }
/* update old coin's denomination balance */ /* update old coin's denomination balance */
dso = get_denomination_summary (cc, dso = get_balance_summary (cc,
dki, dki,
&dki->properties.denom_hash); &dki->properties.denom_hash);
if (GNUNET_OK != if (GNUNET_OK !=
@ -1766,7 +1760,7 @@ deposit_cb (void *cls,
} }
/* update old coin's denomination balance */ /* update old coin's denomination balance */
ds = get_denomination_summary (cc, ds = get_balance_summary (cc,
dki, dki,
&dki->properties.denom_hash); &dki->properties.denom_hash);
if (GNUNET_OK != if (GNUNET_OK !=
@ -1880,7 +1874,7 @@ refund_cb (void *cls,
} }
/* update coin's denomination balance */ /* update coin's denomination balance */
ds = get_denomination_summary (cc, ds = get_balance_summary (cc,
dki, dki,
&dki->properties.denom_hash); &dki->properties.denom_hash);
if (GNUNET_OK != if (GNUNET_OK !=
@ -1920,8 +1914,7 @@ analyze_coins (void *cls)
/* setup 'cc' */ /* setup 'cc' */
cc.ret = GNUNET_OK; cc.ret = GNUNET_OK;
// SANITY: FIX misnomer "denomination_summary", as this is no longer exactly about denominations! dret = adb->get_balance_summary (adb->cls,
dret = adb->get_denomination_summary (adb->cls,
asession, asession,
&master_pub, &master_pub,
&cc.denom_balance, &cc.denom_balance,
@ -2016,9 +2009,8 @@ analyze_coins (void *cls)
&cc); &cc);
GNUNET_CONTAINER_multihashmap_destroy (cc.coins); GNUNET_CONTAINER_multihashmap_destroy (cc.coins);
// SANITY: FIX misnomer "denomination_summary", as this is no longer about denominations!
if (GNUNET_YES == dret) if (GNUNET_YES == dret)
dret = adb->update_denomination_summary (adb->cls, dret = adb->update_balance_summary (adb->cls,
asession, asession,
&master_pub, &master_pub,
&cc.denom_balance, &cc.denom_balance,
@ -2027,7 +2019,7 @@ analyze_coins (void *cls)
&cc.refund_fee_balance, &cc.refund_fee_balance,
&cc.risk); &cc.risk);
else else
dret = adb->insert_denomination_summary (adb->cls, dret = adb->insert_balance_summary (adb->cls,
asession, asession,
&master_pub, &master_pub,
&cc.denom_balance, &cc.denom_balance,
@ -2082,7 +2074,7 @@ struct WirePlugin
/** /**
* Closure for callbacks during #analyze_merchants(). * Closure for callbacks during #analyze_merchants().
*/ */
struct MerchantContext struct AggregationContext
{ {
/** /**
@ -2101,18 +2093,18 @@ struct MerchantContext
/** /**
* Find the relevant wire plugin. * Find the relevant wire plugin.
* *
* @param mc context to search * @param ac context to search
* @param type type of the wire plugin to load * @param type type of the wire plugin to load
* @return NULL on error * @return NULL on error
*/ */
static struct TALER_WIRE_Plugin * static struct TALER_WIRE_Plugin *
get_wire_plugin (struct MerchantContext *mc, get_wire_plugin (struct AggregationContext *ac,
const char *type) const char *type)
{ {
struct WirePlugin *wp; struct WirePlugin *wp;
struct TALER_WIRE_Plugin *plugin; struct TALER_WIRE_Plugin *plugin;
for (wp = mc->wire_head; NULL != wp; wp = wp->next) for (wp = ac->wire_head; NULL != wp; wp = wp->next)
if (0 == strcmp (type, if (0 == strcmp (type,
wp->type)) wp->type))
return wp->plugin; return wp->plugin;
@ -2128,8 +2120,8 @@ get_wire_plugin (struct MerchantContext *mc,
wp = GNUNET_new (struct WirePlugin); wp = GNUNET_new (struct WirePlugin);
wp->type = GNUNET_strdup (type); wp->type = GNUNET_strdup (type);
wp->plugin = plugin; wp->plugin = plugin;
GNUNET_CONTAINER_DLL_insert (mc->wire_head, GNUNET_CONTAINER_DLL_insert (ac->wire_head,
mc->wire_tail, ac->wire_tail,
wp); wp);
return plugin; return plugin;
} }
@ -2144,7 +2136,7 @@ struct WireCheckContext
/** /**
* Corresponding merchant context. * Corresponding merchant context.
*/ */
struct MerchantContext *mc; struct AggregationContext *ac;
/** /**
* Total deposits claimed by all transactions that were aggregated * Total deposits claimed by all transactions that were aggregated
@ -2467,7 +2459,7 @@ wire_transfer_information_cb (void *cls,
* Check that a wire transfer made by the exchange is valid * Check that a wire transfer made by the exchange is valid
* (has matching deposits). * (has matching deposits).
* *
* @param cls a `struct MerchantContext` * @param cls a `struct AggregationContext`
* @param rowid identifier of the respective row in the database * @param rowid identifier of the respective row in the database
* @param date timestamp of the wire transfer (roughly) * @param date timestamp of the wire transfer (roughly)
* @param wtid wire transfer subject * @param wtid wire transfer subject
@ -2482,12 +2474,12 @@ check_wire_out_cb (void *cls,
const json_t *wire, const json_t *wire,
const struct TALER_Amount *amount) const struct TALER_Amount *amount)
{ {
struct MerchantContext *mc = cls; struct AggregationContext *ac = cls;
struct WireCheckContext wcc; struct WireCheckContext wcc;
json_t *method; json_t *method;
struct TALER_WIRE_Plugin *plugin; struct TALER_WIRE_Plugin *plugin;
wcc.mc = mc; wcc.ac = ac;
method = json_object_get (wire, method = json_object_get (wire,
"type"); "type");
if ( (NULL == method) || if ( (NULL == method) ||
@ -2516,7 +2508,7 @@ check_wire_out_cb (void *cls,
rowid, rowid,
"audit of associated transactions failed"); "audit of associated transactions failed");
} }
plugin = get_wire_plugin (mc, plugin = get_wire_plugin (ac,
wcc.method); wcc.method);
if (NULL == plugin) if (NULL == plugin)
{ {
@ -2552,29 +2544,29 @@ check_wire_out_cb (void *cls,
* @param int #GNUNET_OK on success, #GNUNET_SYSERR on hard errors * @param int #GNUNET_OK on success, #GNUNET_SYSERR on hard errors
*/ */
static int static int
analyze_merchants (void *cls) analyze_aggregations (void *cls)
{ {
struct MerchantContext mc; struct AggregationContext ac;
struct WirePlugin *wc; struct WirePlugin *wc;
int ret; int ret;
ret = GNUNET_OK; ret = GNUNET_OK;
mc.wire_head = NULL; ac.wire_head = NULL;
mc.wire_tail = NULL; ac.wire_tail = NULL;
if (GNUNET_SYSERR == if (GNUNET_SYSERR ==
edb->select_wire_out_above_serial_id (edb->cls, edb->select_wire_out_above_serial_id (edb->cls,
esession, esession,
pp.last_wire_out_serial_id, pp.last_wire_out_serial_id,
&check_wire_out_cb, &check_wire_out_cb,
&mc)) &ac))
{ {
GNUNET_break (0); GNUNET_break (0);
ret = GNUNET_SYSERR; ret = GNUNET_SYSERR;
} }
while (NULL != (wc = mc.wire_head)) while (NULL != (wc = ac.wire_head))
{ {
GNUNET_CONTAINER_DLL_remove (mc.wire_head, GNUNET_CONTAINER_DLL_remove (ac.wire_head,
mc.wire_tail, ac.wire_tail,
wc); wc);
TALER_WIRE_plugin_unload (wc->plugin); TALER_WIRE_plugin_unload (wc->plugin);
GNUNET_free (wc->type); GNUNET_free (wc->type);
@ -2760,7 +2752,7 @@ setup_sessions_and_run ()
NULL); NULL);
transact (&analyze_coins, transact (&analyze_coins,
NULL); NULL);
transact (&analyze_merchants, transact (&analyze_aggregations,
NULL); NULL);
} }

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER This file is part of TALER
Copyright (C) 2014-2016 GNUnet e.V. Copyright (C) 2014-2017 GNUnet e.V.
TALER is free software; you can redistribute it and/or modify it under the TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software terms of the GNU General Public License as published by the Free Software
@ -336,10 +336,10 @@ postgres_create_tables (void *cls)
/* Table with the sum of the outstanding coins from /* Table with the sum of the outstanding coins from
"denomination_pending" (denom_pubs must belong to the "denomination_pending" (denom_pubs must belong to the
respective's exchange's master public key); it represents the respective's exchange's master public key); it represents the
total_liabilities of the exchange at this point (modulo balance_summary of the exchange at this point (modulo
unexpected historic_loss-style events where denomination keys are unexpected historic_loss-style events where denomination keys are
compromised) */ compromised) */
SQLEXEC ("CREATE TABLE IF NOT EXISTS total_liabilities" SQLEXEC ("CREATE TABLE IF NOT EXISTS balance_summary"
"(master_pub BYTEA PRIMARY KEY CHECK (LENGTH(master_pub)=32)" "(master_pub BYTEA PRIMARY KEY CHECK (LENGTH(master_pub)=32)"
",denom_balance_val INT8 NOT NULL" ",denom_balance_val INT8 NOT NULL"
",denom_balance_frac INT4 NOT NULL" ",denom_balance_frac INT4 NOT NULL"
@ -697,9 +697,9 @@ postgres_prepare (PGconn *db_conn)
" WHERE denom_pub_hash=$1", " WHERE denom_pub_hash=$1",
1, NULL); 1, NULL);
/* Used in #postgres_insert_denomination_summary() */ /* Used in #postgres_insert_balance_summary() */
PREPARE ("total_liabilities_insert", PREPARE ("balance_summary_insert",
"INSERT INTO total_liabilities " "INSERT INTO balance_summary "
"(master_pub" "(master_pub"
",denom_balance_val" ",denom_balance_val"
",denom_balance_frac" ",denom_balance_frac"
@ -719,9 +719,9 @@ postgres_prepare (PGconn *db_conn)
") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);", ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);",
16, NULL); 16, NULL);
/* Used in #postgres_update_denomination_summary() */ /* Used in #postgres_update_balance_summary() */
PREPARE ("total_liabilities_update", PREPARE ("balance_summary_update",
"UPDATE total_liabilities SET" "UPDATE balance_summary SET"
" denom_balance_val=$1" " denom_balance_val=$1"
",denom_balance_frac=$2" ",denom_balance_frac=$2"
",denom_balance_curr=$3" ",denom_balance_curr=$3"
@ -740,8 +740,8 @@ postgres_prepare (PGconn *db_conn)
" WHERE master_pub=$16;", " WHERE master_pub=$16;",
16, NULL); 16, NULL);
/* Used in #postgres_get_denomination_summary() */ /* Used in #postgres_get_balance_summary() */
PREPARE ("total_liabilities_select", PREPARE ("balance_summary_select",
"SELECT" "SELECT"
" denom_balance_val" " denom_balance_val"
",denom_balance_frac" ",denom_balance_frac"
@ -758,7 +758,7 @@ postgres_prepare (PGconn *db_conn)
",risk_val" ",risk_val"
",risk_frac" ",risk_frac"
",risk_curr" ",risk_curr"
" FROM total_liabilities" " FROM balance_summary"
" WHERE master_pub=$1;", " WHERE master_pub=$1;",
1, NULL); 1, NULL);
@ -1921,7 +1921,7 @@ postgres_get_denomination_balance (void *cls,
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
*/ */
static int static int
postgres_insert_denomination_summary (void *cls, postgres_insert_balance_summary (void *cls,
struct TALER_AUDITORDB_Session *session, struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub, const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_Amount *denom_balance, const struct TALER_Amount *denom_balance,
@ -1955,7 +1955,7 @@ postgres_insert_denomination_summary (void *cls,
refund_fee_balance)); refund_fee_balance));
result = GNUNET_PQ_exec_prepared (session->conn, result = GNUNET_PQ_exec_prepared (session->conn,
"total_liabilities_insert", "balance_summary_insert",
params); params);
if (PGRES_COMMAND_OK != PQresultStatus (result)) if (PGRES_COMMAND_OK != PQresultStatus (result))
{ {
@ -1986,7 +1986,7 @@ postgres_insert_denomination_summary (void *cls,
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
*/ */
static int static int
postgres_update_denomination_summary (void *cls, postgres_update_balance_summary (void *cls,
struct TALER_AUDITORDB_Session *session, struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub, const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_Amount *denom_balance, const struct TALER_Amount *denom_balance,
@ -2008,7 +2008,7 @@ postgres_update_denomination_summary (void *cls,
}; };
result = GNUNET_PQ_exec_prepared (session->conn, result = GNUNET_PQ_exec_prepared (session->conn,
"total_liabilities_update", "balance_summary_update",
params); params);
if (PGRES_COMMAND_OK != PQresultStatus (result)) if (PGRES_COMMAND_OK != PQresultStatus (result))
{ {
@ -2039,7 +2039,7 @@ postgres_update_denomination_summary (void *cls,
* for this @a master_pub; #GNUNET_SYSERR on failure * for this @a master_pub; #GNUNET_SYSERR on failure
*/ */
static int static int
postgres_get_denomination_summary (void *cls, postgres_get_balance_summary (void *cls,
struct TALER_AUDITORDB_Session *session, struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub, const struct TALER_MasterPublicKeyP *master_pub,
struct TALER_Amount *denom_balance, struct TALER_Amount *denom_balance,
@ -2055,7 +2055,7 @@ postgres_get_denomination_summary (void *cls,
PGresult *result; PGresult *result;
result = GNUNET_PQ_exec_prepared (session->conn, result = GNUNET_PQ_exec_prepared (session->conn,
"total_liabilities_select", "balance_summary_select",
params); params);
if (PGRES_TUPLES_OK != if (PGRES_TUPLES_OK !=
PQresultStatus (result)) PQresultStatus (result))
@ -2069,7 +2069,7 @@ postgres_get_denomination_summary (void *cls,
if (0 == nrows) if (0 == nrows)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"postgres_get_denomination_summary() returned 0 matching rows\n"); "postgres_get_balance_summary() returned 0 matching rows\n");
PQclear (result); PQclear (result);
return GNUNET_NO; return GNUNET_NO;
} }
@ -2701,9 +2701,9 @@ libtaler_plugin_auditordb_postgres_init (void *cls)
plugin->update_denomination_balance = &postgres_update_denomination_balance; plugin->update_denomination_balance = &postgres_update_denomination_balance;
plugin->insert_denomination_balance = &postgres_insert_denomination_balance; plugin->insert_denomination_balance = &postgres_insert_denomination_balance;
plugin->get_denomination_summary = &postgres_get_denomination_summary; plugin->get_balance_summary = &postgres_get_balance_summary;
plugin->update_denomination_summary = &postgres_update_denomination_summary; plugin->update_balance_summary = &postgres_update_balance_summary;
plugin->insert_denomination_summary = &postgres_insert_denomination_summary; plugin->insert_balance_summary = &postgres_insert_balance_summary;
plugin->select_historic_denom_revenue = &postgres_select_historic_denom_revenue; plugin->select_historic_denom_revenue = &postgres_select_historic_denom_revenue;
plugin->insert_historic_denom_revenue = &postgres_insert_historic_denom_revenue; plugin->insert_historic_denom_revenue = &postgres_insert_historic_denom_revenue;

View File

@ -401,10 +401,10 @@ run (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: insert_denomination_summary\n"); "Test: insert_balance_summary\n");
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->insert_denomination_summary (plugin->cls, plugin->insert_balance_summary (plugin->cls,
session, session,
&master_pub, &master_pub,
&refund_fee_balance, &refund_fee_balance,
@ -414,10 +414,10 @@ run (void *cls)
&rbalance)); &rbalance));
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: update_denomination_summary\n"); "Test: update_balance_summary\n");
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->update_denomination_summary (plugin->cls, plugin->update_balance_summary (plugin->cls,
session, session,
&master_pub, &master_pub,
&denom_balance, &denom_balance,
@ -427,7 +427,7 @@ run (void *cls)
&rbalance)); &rbalance));
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: get_denomination_summary\n"); "Test: get_balance_summary\n");
ZR_BLK (&denom_balance2); ZR_BLK (&denom_balance2);
ZR_BLK (&deposit_fee_balance2); ZR_BLK (&deposit_fee_balance2);
@ -436,7 +436,7 @@ run (void *cls)
ZR_BLK (&rbalance2); ZR_BLK (&rbalance2);
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->get_denomination_summary (plugin->cls, plugin->get_balance_summary (plugin->cls,
session, session,
&master_pub, &master_pub,
&denom_balance2, &denom_balance2,

View File

@ -571,7 +571,7 @@ struct TALER_AUDITORDB_Plugin
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
*/ */
int int
(*insert_denomination_summary)(void *cls, (*insert_balance_summary)(void *cls,
struct TALER_AUDITORDB_Session *session, struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub, const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_Amount *denom_balance, const struct TALER_Amount *denom_balance,
@ -596,7 +596,7 @@ struct TALER_AUDITORDB_Plugin
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
*/ */
int int
(*update_denomination_summary)(void *cls, (*update_balance_summary)(void *cls,
struct TALER_AUDITORDB_Session *session, struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub, const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_Amount *denom_balance, const struct TALER_Amount *denom_balance,
@ -621,7 +621,7 @@ struct TALER_AUDITORDB_Plugin
* for this @a master_pub; #GNUNET_SYSERR on failure * for this @a master_pub; #GNUNET_SYSERR on failure
*/ */
int int
(*get_denomination_summary)(void *cls, (*get_balance_summary)(void *cls,
struct TALER_AUDITORDB_Session *session, struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub, const struct TALER_MasterPublicKeyP *master_pub,
struct TALER_Amount *denom_balance, struct TALER_Amount *denom_balance,