refactor wire auditor to properly handle multiple accounts

This commit is contained in:
Christian Grothoff 2019-08-24 22:49:35 +02:00
parent b5dd2bcdbb
commit 71ae493c7a
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
5 changed files with 712 additions and 403 deletions

View File

@ -4,6 +4,10 @@
# Which database backend do we use for the auditor?
DB = postgres
# Option specifying which amount is considered 'tiny'
# and thus doesn't need to be wire-transferred.
#TINY_AMOUNT = KUDOS:0.01
# Where do we store the auditor's private key?
AUDITOR_PRIV_FILE = ${TALER_DATA_HOME}/auditor/offline-keys/auditor.priv

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
[auditor]
DB = postgres
TINY_AMOUNT = TESTKUDOS:0.01
[auditordb-postgres]
CONFIG = postgres:///taler-auditor-test

View File

@ -177,6 +177,7 @@ postgres_drop_tables (void *cls,
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS auditor_progress_deposit_confirmation;"),
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS auditor_progress_coin;"),
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS wire_auditor_progress;"),
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS wire_auditor_account_progress;"),
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS deposit_confirmations CASCADE;"),
GNUNET_PQ_EXECUTE_STATEMENT_END
};
@ -283,15 +284,18 @@ postgres_create_tables (void *cls)
",last_payback_serial_id INT8 NOT NULL DEFAULT 0"
",last_payback_refresh_serial_id INT8 NOT NULL DEFAULT 0"
")"),
GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS wire_auditor_progress"
GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS wire_auditor_account_progress"
"(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
",account_name TEXT NOT NULL"
",last_wire_reserve_in_serial_id INT8 NOT NULL DEFAULT 0"
",last_wire_wire_out_serial_id INT8 NOT NULL DEFAULT 0"
",last_timestamp INT8 NOT NULL"
",wire_in_off BYTEA"
",wire_out_off BYTEA"
")"),
GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS wire_auditor_progress"
"(master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE"
",last_timestamp INT8 NOT NULL"
")"),
/* Table with all of the customer reserves and their respective
balances that the auditor is aware of.
"last_reserve_out_serial_id" marks the last withdrawal from
@ -686,39 +690,56 @@ postgres_prepare (PGconn *db_conn)
",last_payback_refresh_serial_id"
") VALUES ($1,$2,$3,$4,$5,$6,$7);",
7),
/* Used in #postgres_insert_wire_auditor_progress() */
GNUNET_PQ_make_prepare ("wire_auditor_progress_insert",
"INSERT INTO wire_auditor_progress "
/* Used in #postgres_insert_wire_auditor_account_progress() */
GNUNET_PQ_make_prepare ("wire_auditor_account_progress_insert",
"INSERT INTO wire_auditor_account_progress "
"(master_pub"
",account_name"
",last_wire_reserve_in_serial_id"
",last_wire_wire_out_serial_id"
",last_timestamp"
",wire_in_off"
",wire_out_off"
") VALUES ($1,$2,$3,$4,$5,$6,$7);",
7),
/* Used in #postgres_update_wire_auditor_progress() */
GNUNET_PQ_make_prepare ("wire_auditor_progress_update",
"UPDATE wire_auditor_progress SET "
") VALUES ($1,$2,$3,$4,$5,$6);",
6),
/* Used in #postgres_update_wire_auditor_account_progress() */
GNUNET_PQ_make_prepare ("wire_auditor_account_progress_update",
"UPDATE wire_auditor_account_progress SET "
" last_wire_reserve_in_serial_id=$1"
",last_wire_wire_out_serial_id=$2"
",last_timestamp=$3"
",wire_in_off=$4"
",wire_out_off=$5"
" WHERE master_pub=$6 AND account_name=$7",
7),
/* Used in #postgres_get_wire_auditor_progress() */
GNUNET_PQ_make_prepare ("wire_auditor_progress_select",
",wire_in_off=$3"
",wire_out_off=$4"
" WHERE master_pub=$5 AND account_name=$6",
6),
/* Used in #postgres_get_wire_auditor_account_progress() */
GNUNET_PQ_make_prepare ("wire_auditor_account_progress_select",
"SELECT"
" last_wire_reserve_in_serial_id"
",last_wire_wire_out_serial_id"
",last_timestamp"
",wire_in_off"
",wire_out_off"
" FROM wire_auditor_progress"
" FROM wire_auditor_account_progress"
" WHERE master_pub=$1 AND account_name=$2;",
2),
/* Used in #postgres_insert_wire_auditor_progress() */
GNUNET_PQ_make_prepare ("wire_auditor_progress_insert",
"INSERT INTO wire_auditor_progress "
"(master_pub"
",last_timestamp"
") VALUES ($1,$2);",
2),
/* Used in #postgres_update_wire_auditor_progress() */
GNUNET_PQ_make_prepare ("wire_auditor_progress_update",
"UPDATE wire_auditor_progress SET "
" last_timestamp=$1"
" WHERE master_pub=$2",
2),
/* Used in #postgres_get_wire_auditor_progress() */
GNUNET_PQ_make_prepare ("wire_auditor_progress_select",
"SELECT"
" last_timestamp"
" FROM wire_auditor_progress"
" WHERE master_pub=$1;",
1),
/* Used in #postgres_insert_reserve_info() */
GNUNET_PQ_make_prepare ("auditor_reserves_insert",
"INSERT INTO auditor_reserves "
@ -2105,15 +2126,14 @@ postgres_get_auditor_progress_coin (void *cls,
* @param session connection to use
* @param master_pub master key of the exchange
* @param account_name name of the wire account we are auditing
* @param pp where is the auditor in processing
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
postgres_insert_wire_auditor_progress (void *cls,
postgres_insert_wire_auditor_account_progress (void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
const char *account_name,
const struct TALER_AUDITORDB_WireProgressPoint *pp,
const struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
const void *in_wire_off,
const void *out_wire_off,
size_t wire_off_size)
@ -2123,7 +2143,6 @@ postgres_insert_wire_auditor_progress (void *cls,
GNUNET_PQ_query_param_string (account_name),
GNUNET_PQ_query_param_uint64 (&pp->last_reserve_in_serial_id),
GNUNET_PQ_query_param_uint64 (&pp->last_wire_out_serial_id),
TALER_PQ_query_param_absolute_time (&pp->last_timestamp),
GNUNET_PQ_query_param_fixed_size (in_wire_off,
wire_off_size),
GNUNET_PQ_query_param_fixed_size (out_wire_off,
@ -2132,7 +2151,7 @@ postgres_insert_wire_auditor_progress (void *cls,
};
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"wire_auditor_progress_insert",
"wire_auditor_account_progress_insert",
params);
}
@ -2145,15 +2164,14 @@ postgres_insert_wire_auditor_progress (void *cls,
* @param session connection to use
* @param master_pub master key of the exchange
* @param account_name name of the wire account we are auditing
* @param pp where is the auditor in processing
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
postgres_update_wire_auditor_progress (void *cls,
postgres_update_wire_auditor_account_progress (void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
const char *account_name,
const struct TALER_AUDITORDB_WireProgressPoint *pp,
const struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
const void *in_wire_off,
const void *out_wire_off,
size_t wire_off_size)
@ -2161,7 +2179,6 @@ postgres_update_wire_auditor_progress (void *cls,
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint64 (&pp->last_reserve_in_serial_id),
GNUNET_PQ_query_param_uint64 (&pp->last_wire_out_serial_id),
TALER_PQ_query_param_absolute_time (&pp->last_timestamp),
GNUNET_PQ_query_param_fixed_size (in_wire_off,
wire_off_size),
GNUNET_PQ_query_param_fixed_size (out_wire_off,
@ -2172,7 +2189,7 @@ postgres_update_wire_auditor_progress (void *cls,
};
return GNUNET_PQ_eval_prepared_non_select (session->conn,
"wire_auditor_progress_update",
"wire_auditor_account_progress_update",
params);
}
@ -2184,15 +2201,18 @@ postgres_update_wire_auditor_progress (void *cls,
* @param session connection to use
* @param master_pub master key of the exchange
* @param account_name name of the wire account we are auditing
* @param[out] pp set to where the auditor is in processing
* @param[out] pp where is the auditor in processing
* @param[out] in_wire_off how far are we in the incoming wire transaction history
* @param[out] out_wire_off how far are we in the outgoing wire transaction history
* @param[out] wire_off_size how many bytes do @a in_wire_off and @a out_wire_off take?
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
postgres_get_wire_auditor_progress (void *cls,
postgres_get_wire_auditor_account_progress (void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
const char *account_name,
struct TALER_AUDITORDB_WireProgressPoint *pp,
struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
void **in_wire_off,
void **out_wire_off,
size_t *wire_off_size)
@ -2209,8 +2229,6 @@ postgres_get_wire_auditor_progress (void *cls,
&pp->last_reserve_in_serial_id),
GNUNET_PQ_result_spec_uint64 ("last_wire_wire_out_serial_id",
&pp->last_wire_out_serial_id),
TALER_PQ_result_spec_absolute_time ("last_timestamp",
&pp->last_timestamp),
GNUNET_PQ_result_spec_variable_size ("wire_in_off",
in_wire_off,
wire_off_size),
@ -2221,7 +2239,7 @@ postgres_get_wire_auditor_progress (void *cls,
};
qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn,
"wire_auditor_progress_select",
"wire_auditor_account_progress_select",
params,
rs);
if (qs <= 0)
@ -2234,6 +2252,94 @@ postgres_get_wire_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),
TALER_PQ_query_param_absolute_time (&pp->last_timestamp),
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[] = {
TALER_PQ_query_param_absolute_time (&pp->last_timestamp),
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[] = {
TALER_PQ_result_spec_absolute_time ("last_timestamp",
&pp->last_timestamp),
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
* existing record for the reserve.
@ -3329,6 +3435,9 @@ libtaler_plugin_auditordb_postgres_init (void *cls)
plugin->update_auditor_progress_coin = &postgres_update_auditor_progress_coin;
plugin->insert_auditor_progress_coin = &postgres_insert_auditor_progress_coin;
plugin->get_wire_auditor_account_progress = &postgres_get_wire_auditor_account_progress;
plugin->update_wire_auditor_account_progress = &postgres_update_wire_auditor_account_progress;
plugin->insert_wire_auditor_account_progress = &postgres_insert_wire_auditor_account_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;

View File

@ -107,6 +107,21 @@ typedef int
* various tables and (auditor) transactions.
*/
struct TALER_AUDITORDB_WireProgressPoint
{
/**
* Time until which we have confirmed that all wire transactions
* that the exchange should do, have indeed been done.
*/
struct GNUNET_TIME_Absolute last_timestamp;
};
/**
* Structure for remembering the wire auditor's progress over the
* various tables and (auditor) transactions per wire account.
*/
struct TALER_AUDITORDB_WireAccountProgressPoint
{
/**
* serial ID of the last reserve_in transfer the wire auditor processed
@ -118,11 +133,6 @@ struct TALER_AUDITORDB_WireProgressPoint
*/
uint64_t last_wire_out_serial_id;
/**
* Time until which we have confirmed that all wire transactions
* that the exchange should do, have indeed been done.
*/
struct GNUNET_TIME_Absolute last_timestamp;
};
@ -801,11 +811,11 @@ struct TALER_AUDITORDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
(*insert_wire_auditor_progress)(void *cls,
(*insert_wire_auditor_account_progress)(void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
const char *account_name,
const struct TALER_AUDITORDB_WireProgressPoint *pp,
const struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
const void *in_wire_off,
const void *out_wire_off,
size_t wire_off_size);
@ -826,16 +836,75 @@ struct TALER_AUDITORDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
(*update_wire_auditor_progress)(void *cls,
(*update_wire_auditor_account_progress)(void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
const char *account_name,
const struct TALER_AUDITORDB_WireProgressPoint *pp,
const struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
const void *in_wire_off,
const void *out_wire_off,
size_t wire_off_size);
/**
* 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 account_name name of the wire account we are auditing
* @param[out] pp where is the auditor in processing
* @param[out] in_wire_off how far are we in the incoming wire transaction history
* @param[out] out_wire_off how far are we in the outgoing wire transaction history
* @param[out] wire_off_size how many bytes do @a in_wire_off and @a out_wire_off take?
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
(*get_wire_auditor_account_progress)(void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
const char *account_name,
struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
void **in_wire_off,
void **out_wire_off,
size_t *wire_off_size);
/**
* 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 account_name name of the wire account we are auditing
* @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 account_name name of the wire account we are auditing
* @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.
@ -845,20 +914,13 @@ struct TALER_AUDITORDB_Plugin
* @param master_pub master key of the exchange
* @param account_name name of the wire account we are auditing
* @param[out] pp set to where the auditor is in processing
* @param[out] in_wire_off how far are we in the incoming wire transaction history
* @param[out] out_wire_off how far are we in the outgoing wire transaction history
* @param[out] wire_off_size how many bytes do @a in_wire_off and @a out_wire_off take?
* @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,
const char *account_name,
struct TALER_AUDITORDB_WireProgressPoint *pp,
void **in_wire_off,
void **out_wire_off,
size_t *wire_off_size);
struct TALER_AUDITORDB_WireProgressPoint *pp);
/**