update auditordb API to support logic for taler-wire-auditor

This commit is contained in:
Christian Grothoff 2017-09-30 20:29:19 +02:00
parent 34db060b4c
commit 96e04d33e1
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
3 changed files with 231 additions and 52 deletions

View File

@ -78,9 +78,9 @@ static struct TALER_AUDITORDB_Session *asession;
static struct TALER_MasterPublicKeyP master_pub; static struct TALER_MasterPublicKeyP master_pub;
/** /**
* Last reserve_in serial ID seen. * Last reserve_in / reserve_out serial IDs seen.
*/ */
static struct TALER_AUDITORDB_ProgressPoint pp; static struct TALER_AUDITORDB_WireProgressPoint pp;
/* ***************************** Report logic **************************** */ /* ***************************** Report logic **************************** */
@ -192,10 +192,10 @@ incremental_processing (Analysis analysis,
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
enum GNUNET_DB_QueryStatus qsx; enum GNUNET_DB_QueryStatus qsx;
qsx = adb->get_auditor_progress (adb->cls, qsx = adb->get_wire_auditor_progress (adb->cls,
asession, asession,
&master_pub, &master_pub,
&pp); &pp);
if (0 > qsx) if (0 > qsx)
{ {
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx);
@ -209,14 +209,9 @@ incremental_processing (Analysis analysis,
else else
{ {
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Resuming audit at %llu/%llu/%llu/%llu/%llu/%llu/%llu\n"), _("Resuming audit at %llu/%llu\n"),
(unsigned long long) pp.last_reserve_in_serial_id, (unsigned long long) pp.last_reserve_in_serial_id,
(unsigned long long) pp.last_reserve_out_serial_id, (unsigned long long) pp.last_reserve_out_serial_id);
(unsigned long long) pp.last_withdraw_serial_id,
(unsigned long long) pp.last_deposit_serial_id,
(unsigned long long) pp.last_melt_serial_id,
(unsigned long long) pp.last_refund_serial_id,
(unsigned long long) pp.last_wire_out_serial_id);
} }
qs = analysis (analysis_cls); qs = analysis (analysis_cls);
if (0 > qs) if (0 > qs)
@ -230,15 +225,15 @@ incremental_processing (Analysis analysis,
return qs; return qs;
} }
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsx) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsx)
qs = adb->update_auditor_progress (adb->cls, qs = adb->update_wire_auditor_progress (adb->cls,
asession, asession,
&master_pub, &master_pub,
&pp); &pp);
else else
qs = adb->insert_auditor_progress (adb->cls, qs = adb->insert_wire_auditor_progress (adb->cls,
asession, asession,
&master_pub, &master_pub,
&pp); &pp);
if (0 >= qs) if (0 >= qs)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@ -247,14 +242,9 @@ incremental_processing (Analysis analysis,
return qs; return qs;
} }
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Concluded audit step at %llu/%llu/%llu/%llu/%llu/%llu/%llu\n\n"), _("Concluded audit step at %llu/%llu\n"),
(unsigned long long) pp.last_reserve_in_serial_id, (unsigned long long) pp.last_reserve_in_serial_id,
(unsigned long long) pp.last_reserve_out_serial_id, (unsigned long long) pp.last_reserve_out_serial_id);
(unsigned long long) pp.last_withdraw_serial_id,
(unsigned long long) pp.last_deposit_serial_id,
(unsigned long long) pp.last_melt_serial_id,
(unsigned long long) pp.last_refund_serial_id,
(unsigned long long) pp.last_wire_out_serial_id);
return qs; return qs;
} }

View File

@ -218,15 +218,17 @@ postgres_create_tables (void *cls)
larger (and process in monotonically increasing order). */ larger (and process in monotonically increasing order). */
GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_progress" GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_progress"
"(master_pub BYTEA PRIMARY KEY CHECK (LENGTH(master_pub)=32)" "(master_pub BYTEA PRIMARY KEY CHECK (LENGTH(master_pub)=32)"
",last_reserve_in_serial_id INT8 NOT NULL" ",last_reserve_in_serial_id INT8 NOT NULL DEFAULT 0"
",last_reserve_out_serial_id INT8 NOT NULL" ",last_reserve_out_serial_id INT8 NOT NULL DEFAULT 0"
",last_reserve_payback_serial_id INT8 NOT NULL" ",last_reserve_payback_serial_id INT8 NOT NULL DEFAULT 0"
",last_reserve_close_serial_id INT8 NOT NULL" ",last_reserve_close_serial_id INT8 NOT NULL DEFAULT 0"
",last_withdraw_serial_id INT8 NOT NULL" ",last_withdraw_serial_id INT8 NOT NULL DEFAULT 0"
",last_deposit_serial_id INT8 NOT NULL" ",last_deposit_serial_id INT8 NOT NULL DEFAULT 0"
",last_melt_serial_id INT8 NOT NULL" ",last_melt_serial_id INT8 NOT NULL DEFAULT 0"
",last_refund_serial_id INT8 NOT NULL" ",last_refund_serial_id INT8 NOT NULL DEFAULT 0"
",last_wire_out_serial_id INT8 NOT NULL" ",last_wire_out_serial_id INT8 NOT NULL DEFAULT 0"
",last_wire_reserve_in_serial_id INT8 NOT NULL DEFAULT 0"
",last_wire_reserve_out_serial_id INT8 NOT NULL DEFAULT 0"
")"), ")"),
/* Table with all of the customer reserves and their respective /* Table with all of the customer reserves and their respective
balances that the auditor is aware of. balances that the auditor is aware of.
@ -258,7 +260,7 @@ postgres_create_tables (void *cls)
",withdraw_fee_balance_val INT8 NOT NULL" ",withdraw_fee_balance_val INT8 NOT NULL"
",withdraw_fee_balance_frac INT4 NOT NULL" ",withdraw_fee_balance_frac INT4 NOT NULL"
",withdraw_fee_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",withdraw_fee_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
")"), ")"),
/* Table with the sum of the balances of all wire fees /* Table with the sum of the balances of all wire fees
(by exchange's master public key) */ (by exchange's master public key) */
GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_wire_fee_balance" GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_wire_fee_balance"
@ -276,7 +278,7 @@ postgres_create_tables (void *cls)
for this denom_pub that the auditor is aware of. */ for this denom_pub that the auditor is aware of. */
GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_denomination_pending" GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_denomination_pending"
"(denom_pub_hash BYTEA PRIMARY KEY" "(denom_pub_hash BYTEA PRIMARY KEY"
" REFERENCES auditor_denominations (denom_pub_hash) ON DELETE CASCADE" " REFERENCES auditor_denominations (denom_pub_hash) ON DELETE CASCADE"
",denom_balance_val INT8 NOT NULL" ",denom_balance_val INT8 NOT NULL"
",denom_balance_frac INT4 NOT NULL" ",denom_balance_frac INT4 NOT NULL"
",denom_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",denom_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
@ -508,6 +510,29 @@ postgres_prepare (PGconn *db_conn)
" FROM auditor_progress" " FROM auditor_progress"
" WHERE master_pub=$1;", " WHERE master_pub=$1;",
1), 1),
/* Used in #postgres_insert_wire_auditor_progress() */
GNUNET_PQ_make_prepare ("wire_auditor_progress_insert",
"INSERT INTO auditor_progress "
"(master_pub"
",last_wire_reserve_in_serial_id"
",last_wire_reserve_out_serial_id"
") VALUES ($1,$2,$3);",
3),
/* Used in #postgres_update_wire_auditor_progress() */
GNUNET_PQ_make_prepare ("wire_auditor_progress_update",
"UPDATE auditor_progress SET "
" last_wire_reserve_in_serial_id=$1"
",last_wire_reserve_out_serial_id=$2"
" WHERE master_pub=$3",
3),
/* Used in #postgres_get_wire_auditor_progress() */
GNUNET_PQ_make_prepare ("wire_auditor_progress_select",
"SELECT"
" last_wire_reserve_in_serial_id"
",last_wire_reserve_out_serial_id"
" FROM auditor_progress"
" WHERE master_pub=$1;",
1),
/* Used in #postgres_insert_reserve_info() */ /* Used in #postgres_insert_reserve_info() */
GNUNET_PQ_make_prepare ("auditor_reserves_insert", GNUNET_PQ_make_prepare ("auditor_reserves_insert",
"INSERT INTO auditor_reserves " "INSERT INTO auditor_reserves "
@ -626,7 +651,7 @@ postgres_prepare (PGconn *db_conn)
",denom_risk_frac" ",denom_risk_frac"
",denom_risk_curr" ",denom_risk_curr"
") VALUES ($1,$2,$3,$4,$5,$6,$7);", ") VALUES ($1,$2,$3,$4,$5,$6,$7);",
7), 7),
/* Used in #postgres_update_denomination_balance() */ /* Used in #postgres_update_denomination_balance() */
GNUNET_PQ_make_prepare ("auditor_denomination_pending_update", GNUNET_PQ_make_prepare ("auditor_denomination_pending_update",
"UPDATE auditor_denomination_pending SET" "UPDATE auditor_denomination_pending SET"
@ -637,7 +662,7 @@ postgres_prepare (PGconn *db_conn)
",denom_risk_frac=$5" ",denom_risk_frac=$5"
",denom_risk_curr=$6" ",denom_risk_curr=$6"
" WHERE denom_pub_hash=$7", " WHERE denom_pub_hash=$7",
7), 7),
/* Used in #postgres_get_denomination_balance() */ /* Used in #postgres_get_denomination_balance() */
GNUNET_PQ_make_prepare ("auditor_denomination_pending_select", GNUNET_PQ_make_prepare ("auditor_denomination_pending_select",
"SELECT" "SELECT"
@ -766,7 +791,7 @@ postgres_prepare (PGconn *db_conn)
",reserve_profits_frac" ",reserve_profits_frac"
",reserve_profits_curr" ",reserve_profits_curr"
") VALUES ($1,$2,$3,$4,$5,$6);", ") VALUES ($1,$2,$3,$4,$5,$6);",
6), 6),
/* Used in #postgres_select_historic_reserve_revenue() */ /* Used in #postgres_select_historic_reserve_revenue() */
GNUNET_PQ_make_prepare ("auditor_historic_reserve_summary_select", GNUNET_PQ_make_prepare ("auditor_historic_reserve_summary_select",
"SELECT" "SELECT"
@ -1063,7 +1088,7 @@ struct DenominationInfoContext
* Master public key that is being used. * Master public key that is being used.
*/ */
const struct TALER_MasterPublicKeyP *master_pub; const struct TALER_MasterPublicKeyP *master_pub;
/** /**
* Function to call for each denomination. * Function to call for each denomination.
*/ */
@ -1073,7 +1098,7 @@ struct DenominationInfoContext
* Closure for @e cb * Closure for @e cb
*/ */
void *cb_cls; void *cb_cls;
/** /**
* Query status to return. * Query status to return.
*/ */
@ -1161,7 +1186,7 @@ postgres_select_denomination_info (void *cls,
.cb_cls = cb_cls .cb_cls = cb_cls
}; };
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, qs = GNUNET_PQ_eval_prepared_multi_select (session->conn,
"auditor_denominations_select", "auditor_denominations_select",
params, params,
@ -1294,6 +1319,98 @@ postgres_get_auditor_progress (void *cls,
} }
/**
* Insert information about the auditor's progress with an exchange's
* data.
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to use
* @param master_pub master key of the exchange
* @param pp where is the auditor in processing
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
postgres_insert_wire_auditor_progress (void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_AUDITORDB_WireProgressPoint *pp)
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_uint64 (&pp->last_reserve_in_serial_id),
GNUNET_PQ_query_param_uint64 (&pp->last_reserve_out_serial_id),
GNUNET_PQ_query_param_end
};
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"wire_auditor_progress_insert",
params);
}
/**
* Update information about the progress of the auditor. There
* must be an existing record for the exchange.
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to use
* @param master_pub master key of the exchange
* @param pp where is the auditor in processing
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
postgres_update_wire_auditor_progress (void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_AUDITORDB_WireProgressPoint *pp)
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint64 (&pp->last_reserve_in_serial_id),
GNUNET_PQ_query_param_uint64 (&pp->last_reserve_out_serial_id),
GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_end
};
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"wire_auditor_progress_update",
params);
}
/**
* Get information about the progress of the auditor.
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to use
* @param master_pub master key of the exchange
* @param[out] pp set to where the auditor is in processing
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
postgres_get_wire_auditor_progress (void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
struct TALER_AUDITORDB_WireProgressPoint *pp)
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_uint64 ("last_reserve_in_serial_id",
&pp->last_reserve_in_serial_id),
GNUNET_PQ_result_spec_uint64 ("last_reserve_out_serial_id",
&pp->last_reserve_out_serial_id),
GNUNET_PQ_result_spec_end
};
return GNUNET_PQ_eval_prepared_singleton_select (session->conn,
"wire_auditor_progress_select",
params,
rs);
}
/** /**
* Insert information about a reserve. There must not be an * Insert information about a reserve. There must not be an
* existing record for the reserve. * existing record for the reserve.
@ -1730,7 +1847,7 @@ postgres_get_denomination_balance (void *cls,
TALER_PQ_result_spec_amount ("denom_risk", denom_risk), TALER_PQ_result_spec_amount ("denom_risk", denom_risk),
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end
}; };
return GNUNET_PQ_eval_prepared_singleton_select (session->conn, return GNUNET_PQ_eval_prepared_singleton_select (session->conn,
"auditor_denomination_pending_select", "auditor_denomination_pending_select",
params, params,
@ -2007,7 +2124,7 @@ postgres_select_historic_denom_revenue (void *cls,
.cb_cls = cb_cls .cb_cls = cb_cls
}; };
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, qs = GNUNET_PQ_eval_prepared_multi_select (session->conn,
"auditor_historic_denomination_revenue_select", "auditor_historic_denomination_revenue_select",
params, params,
@ -2066,7 +2183,7 @@ struct LossContext
*/ */
TALER_AUDITORDB_HistoricLossesDataCallback cb; TALER_AUDITORDB_HistoricLossesDataCallback cb;
/** /**
* Closure for @e cb. * Closure for @e cb.
*/ */
void *cb_cls; void *cb_cls;
@ -2093,7 +2210,7 @@ losses_cb (void *cls,
unsigned int num_results) unsigned int num_results)
{ {
struct LossContext *lctx = cls; struct LossContext *lctx = cls;
for (unsigned int i = 0; i < num_results; i++) for (unsigned int i = 0; i < num_results; i++)
{ {
struct GNUNET_HashCode denom_pub_hash; struct GNUNET_HashCode denom_pub_hash;
@ -2105,7 +2222,7 @@ losses_cb (void *cls,
TALER_PQ_result_spec_amount ("loss_balance", &loss_balance), TALER_PQ_result_spec_amount ("loss_balance", &loss_balance),
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end
}; };
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_PQ_extract_result (result, GNUNET_PQ_extract_result (result,
rs, rs,
@ -2247,7 +2364,7 @@ historic_reserve_revenue_cb (void *cls,
TALER_PQ_result_spec_amount ("reserve_profits", &reserve_profits), TALER_PQ_result_spec_amount ("reserve_profits", &reserve_profits),
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end
}; };
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_PQ_extract_result (result, GNUNET_PQ_extract_result (result,
rs, rs,
@ -2294,7 +2411,7 @@ postgres_select_historic_reserve_revenue (void *cls,
.cb = cb, .cb = cb,
.cb_cls = cb_cls .cb_cls = cb_cls
}; };
qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, qs = GNUNET_PQ_eval_prepared_multi_select (session->conn,
"auditor_historic_reserve_summary_select", "auditor_historic_reserve_summary_select",
params, params,
@ -2453,6 +2570,10 @@ libtaler_plugin_auditordb_postgres_init (void *cls)
plugin->update_auditor_progress = &postgres_update_auditor_progress; plugin->update_auditor_progress = &postgres_update_auditor_progress;
plugin->insert_auditor_progress = &postgres_insert_auditor_progress; plugin->insert_auditor_progress = &postgres_insert_auditor_progress;
plugin->get_wire_auditor_progress = &postgres_get_wire_auditor_progress;
plugin->update_wire_auditor_progress = &postgres_update_wire_auditor_progress;
plugin->insert_wire_auditor_progress = &postgres_insert_wire_auditor_progress;
plugin->del_reserve_info = &postgres_del_reserve_info; plugin->del_reserve_info = &postgres_del_reserve_info;
plugin->get_reserve_info = &postgres_get_reserve_info; plugin->get_reserve_info = &postgres_get_reserve_info;
plugin->update_reserve_info = &postgres_update_reserve_info; plugin->update_reserve_info = &postgres_update_reserve_info;

View File

@ -106,6 +106,24 @@ typedef int
const struct TALER_Amount *reserve_profits); const struct TALER_Amount *reserve_profits);
/**
* Structure for remembering the wire auditor's progress over the
* various tables and (auditor) transactions.
*/
struct TALER_AUDITORDB_WireProgressPoint
{
/**
* last_reserve_in_serial_id serial ID of the last reserve_in transfer the wire auditor processed
*/
uint64_t last_reserve_in_serial_id;
/**
* last_reserve_out_serial_id serial ID of the last reserve_out the wire auditor processed
*/
uint64_t last_reserve_out_serial_id;
};
/** /**
* Structure for remembering the auditor's progress over the * Structure for remembering the auditor's progress over the
* various tables and (auditor) transactions. * various tables and (auditor) transactions.
@ -351,6 +369,56 @@ struct TALER_AUDITORDB_Plugin
struct TALER_AUDITORDB_ProgressPoint *pp); struct TALER_AUDITORDB_ProgressPoint *pp);
/**
* Insert information about the wire auditor's progress with an exchange's
* data.
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to use
* @param master_pub master key of the exchange
* @param pp where is the auditor in processing
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
(*insert_wire_auditor_progress)(void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_AUDITORDB_WireProgressPoint *pp);
/**
* Update information about the progress of the wire auditor. There
* must be an existing record for the exchange.
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to use
* @param master_pub master key of the exchange
* @param pp where is the auditor in processing
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
(*update_wire_auditor_progress)(void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_AUDITORDB_WireProgressPoint *pp);
/**
* Get information about the progress of the wire auditor.
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to use
* @param master_pub master key of the exchange
* @param[out] pp set to where the auditor is in processing
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
(*get_wire_auditor_progress)(void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
struct TALER_AUDITORDB_WireProgressPoint *pp);
/** /**
* Insert information about a reserve. There must not be an * Insert information about a reserve. There must not be an
* existing record for the reserve. * existing record for the reserve.