diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/auditor/taler-auditor.c | 131 | ||||
-rw-r--r-- | src/auditordb/plugin_auditordb_postgres.c | 293 | ||||
-rw-r--r-- | src/auditordb/test_auditordb.c | 101 | ||||
-rw-r--r-- | src/include/taler_auditordb_plugin.h | 120 |
4 files changed, 128 insertions, 517 deletions
diff --git a/src/auditor/taler-auditor.c b/src/auditor/taler-auditor.c index 85eacfc65..3939f2801 100644 --- a/src/auditor/taler-auditor.c +++ b/src/auditor/taler-auditor.c @@ -27,8 +27,6 @@ * TODO: * - COMPLETE: implement misc. FIXMEs * - COMPLETE: deal with risk / expired denomination keys in #sync_denomination - * - SANITY: modify auditordb to track risk with balances and fees (and rename callback - * to clarify what it is) * - SANITY: rename operations to better describe what they do! * - 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 @@ -939,20 +937,20 @@ analyze_reserves (void *cls) pp.last_reserve_in_serial_id, &handle_reserve_in, &rc)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } if (GNUNET_OK != edb->select_reserves_out_above_serial_id (edb->cls, esession, pp.last_reserve_out_serial_id, &handle_reserve_out, &rc)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } /* TODO: iterate over table for reserve expiration refunds! (#4956) */ GNUNET_CONTAINER_multihashmap_iterate (rc.reserves, @@ -979,7 +977,11 @@ analyze_reserves (void *cls) &rc.total_balance, &rc.total_fee_balance); } - // FIXME: handle error in 'ret'! + if (GNUNET_OK != ret) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } report_reserve_balance (&rc.total_balance, &rc.total_fee_balance); return GNUNET_OK; @@ -1030,26 +1032,6 @@ struct DenominationSummary struct TALER_Amount denom_balance; /** - * Up to which point have we processed reserves_out? - */ - uint64_t last_reserve_out_serial_id; - - /** - * Up to which point have we processed deposits? - */ - uint64_t last_deposit_serial_id; - - /** - * Up to which point have we processed melts? - */ - uint64_t last_melt_serial_id; - - /** - * Up to which point have we processed refunds? - */ - uint64_t last_refund_serial_id; - - /** * #GNUNET_YES if this record already existed in the DB. * Used to decide between insert/update in * #sync_denomination(). @@ -1138,11 +1120,7 @@ init_denomination (const struct GNUNET_HashCode *denom_hash, ret = adb->get_denomination_balance (adb->cls, asession, denom_hash, - &ds->denom_balance, - &ds->last_reserve_out_serial_id, - &ds->last_deposit_serial_id, - &ds->last_melt_serial_id, - &ds->last_refund_serial_id); + &ds->denom_balance); if (GNUNET_OK == ret) { ds->in_db = GNUNET_YES; @@ -1214,27 +1192,33 @@ sync_denomination (void *cls, struct DenominationSummary *ds = value; int ret; + // FIXME: if expired, insert remaining balance historic denomination revenue, // DELETE denomination balance, and REDUCE cc->risk exposure! - - if (ds->in_db) - ret = adb->update_denomination_balance (adb->cls, - asession, - denom_hash, - &ds->denom_balance, - ds->last_reserve_out_serial_id, - ds->last_deposit_serial_id, - ds->last_melt_serial_id, - ds->last_refund_serial_id); + if (0) + { + ret = adb->del_denomination_balance (adb->cls, + asession, + denom_hash); + if (GNUNET_OK == ret) + { + // FIXME: reduce RISK + // FIXME: book denomination expiration profits! + } + } else - ret = adb->insert_denomination_balance (adb->cls, - asession, - denom_hash, - &ds->denom_balance, - ds->last_reserve_out_serial_id, - ds->last_deposit_serial_id, - ds->last_melt_serial_id, - ds->last_refund_serial_id); + { + if (ds->in_db) + ret = adb->update_denomination_balance (adb->cls, + asession, + denom_hash, + &ds->denom_balance); + else + ret = adb->insert_denomination_balance (adb->cls, + asession, + denom_hash, + &ds->denom_balance); + } if (GNUNET_OK != ret) { GNUNET_break (0); @@ -1883,7 +1867,6 @@ analyze_coins (void *cls) { struct CoinContext cc; int dret; - int rret; /* setup 'cc' */ cc.ret = GNUNET_OK; @@ -1895,7 +1878,8 @@ analyze_coins (void *cls) &cc.denom_balance, &cc.deposit_fee_balance, &cc.melt_fee_balance, - &cc.refund_fee_balance); + &cc.refund_fee_balance, + &cc.risk); if (GNUNET_SYSERR == dret) { GNUNET_break (0); @@ -1915,18 +1899,6 @@ analyze_coins (void *cls) GNUNET_assert (GNUNET_OK == TALER_amount_get_zero (currency, &cc.refund_fee_balance)); - } - rret = adb->get_risk_summary (adb->cls, - asession, - &master_pub, - &cc.risk); - if (GNUNET_SYSERR == dret) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - if (GNUNET_NO == dret) - { GNUNET_assert (GNUNET_OK == TALER_amount_get_zero (currency, &cc.risk)); @@ -1995,24 +1967,7 @@ analyze_coins (void *cls) &cc); GNUNET_CONTAINER_multihashmap_destroy (cc.coins); - if (GNUNET_YES == rret) - rret = adb->update_risk_summary (adb->cls, - asession, - &master_pub, - &cc.risk); - else - rret = adb->insert_risk_summary (adb->cls, - asession, - &master_pub, - &cc.risk); - if (GNUNET_OK != rret) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - // FIXME: FIX misnomer "denomination_summary", as this is no longer about denominations! - // FIXME: maybe combine with 'risk' above... if (GNUNET_YES == dret) dret = adb->update_denomination_summary (adb->cls, asession, @@ -2020,7 +1975,8 @@ analyze_coins (void *cls) &cc.denom_balance, &cc.deposit_fee_balance, &cc.melt_fee_balance, - &cc.refund_fee_balance); + &cc.refund_fee_balance, + &cc.risk); else dret = adb->insert_denomination_summary (adb->cls, asession, @@ -2028,7 +1984,8 @@ analyze_coins (void *cls) &cc.denom_balance, &cc.deposit_fee_balance, &cc.melt_fee_balance, - &cc.refund_fee_balance); + &cc.refund_fee_balance, + &cc.risk); if (GNUNET_OK != dret) { GNUNET_break (0); diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c index 15180a725..1ef067daf 100644 --- a/src/auditordb/plugin_auditordb_postgres.c +++ b/src/auditordb/plugin_auditordb_postgres.c @@ -330,10 +330,6 @@ postgres_create_tables (void *cls) ",denom_balance_val INT8 NOT NULL" ",denom_balance_frac INT4 NOT NULL" ",denom_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ",last_reserve_out_serial_id INT8 NOT NULL" - ",last_deposit_serial_id INT8 NOT NULL" - ",last_melt_serial_id INT8 NOT NULL" - ",last_refund_serial_id INT8 NOT NULL" ")"); /* Table with the sum of the outstanding coins from @@ -356,17 +352,6 @@ postgres_create_tables (void *cls) ",refund_fee_balance_val INT8 NOT NULL" ",refund_fee_balance_frac INT4 NOT NULL" ",refund_fee_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" - ")"); - - /* Table with the sum of the generated coins all denomination keys. - This represents the maximum additional total financial risk of - the exchange in case that all denomination keys are compromised - (and all of the deposits so far were done by the successful - attacker). So this is strictly an upper bound on the risk - exposure of the exchange. (Note that this risk is in addition to - the known total_liabilities.) */ - SQLEXEC ("CREATE TABLE IF NOT EXISTS total_risk" - "(master_pub BYTEA PRIMARY KEY CHECK (LENGTH(master_pub)=32)" ",risk_val INT8 NOT NULL" ",risk_frac INT4 NOT NULL" ",risk_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" @@ -694,12 +679,8 @@ postgres_prepare (PGconn *db_conn) ",denom_balance_val" ",denom_balance_frac" ",denom_balance_curr" - ",last_reserve_out_serial_id" - ",last_deposit_serial_id" - ",last_melt_serial_id" - ",last_refund_serial_id" - ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8);", - 11, NULL); + ") VALUES ($1,$2,$3,$4);", + 4, NULL); /* Used in #postgres_update_denomination_balance() */ PREPARE ("denomination_pending_update", @@ -707,12 +688,8 @@ postgres_prepare (PGconn *db_conn) " denom_balance_val=$1" ",denom_balance_frac=$2" ",denom_balance_curr=$3" - ",last_reserve_out_serial_id=$4" - ",last_deposit_serial_id=$5" - ",last_melt_serial_id=$6" - ",last_refund_serial_id=$7" - " WHERE denom_pub_hash=$8", - 8, NULL); + " WHERE denom_pub_hash=$4", + 4, NULL); /* Used in #postgres_get_denomination_balance() */ PREPARE ("denomination_pending_select", @@ -720,10 +697,6 @@ postgres_prepare (PGconn *db_conn) " denom_balance_val" ",denom_balance_frac" ",denom_balance_curr" - ",last_reserve_out_serial_id" - ",last_deposit_serial_id" - ",last_melt_serial_id" - ",last_refund_serial_id" " FROM denomination_pending" " WHERE denom_pub_hash=$1", 1, NULL); @@ -744,8 +717,11 @@ postgres_prepare (PGconn *db_conn) ",refund_fee_balance_val" ",refund_fee_balance_frac" ",refund_fee_balance_curr" - ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13);", - 13, NULL); + ",risk_val" + ",risk_frac" + ",risk_curr" + ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);", + 16, NULL); /* Used in #postgres_update_denomination_summary() */ PREPARE ("total_liabilities_update", @@ -762,8 +738,11 @@ postgres_prepare (PGconn *db_conn) ",refund_fee_balance_val=$10" ",refund_fee_balance_frac=$11" ",refund_fee_balance_curr=$12" - " WHERE master_pub=$13;", - 13, NULL); + ",risk_val=$13" + ",risk_frac=$14" + ",risk_curr=$15" + " WHERE master_pub=$16;", + 16, NULL); /* Used in #postgres_get_denomination_summary() */ PREPARE ("total_liabilities_select", @@ -780,40 +759,13 @@ postgres_prepare (PGconn *db_conn) ",refund_fee_balance_val" ",refund_fee_balance_frac" ",refund_fee_balance_curr" - " FROM total_liabilities" - " WHERE master_pub=$1;", - 1, NULL); - - /* Used in #postgres_insert_risk_summary() */ - PREPARE ("total_risk_insert", - "INSERT INTO total_risk" - "(master_pub" ",risk_val" ",risk_frac" ",risk_curr" - ") VALUES ($1,$2,$3,$4);", - 4, NULL); - - /* Used in #postgres_update_risk_summary() */ - PREPARE ("total_risk_update", - "UPDATE total_risk SET " - " risk_val=$1" - ",risk_frac=$2" - ",risk_curr=$3" - " WHERE master_pub=$4;", - 4, NULL); - - /* Used in #postgres_get_risk_summary() */ - PREPARE ("total_risk_select", - "SELECT" - " risk_val" - ",risk_frac" - ",risk_curr" - " FROM total_risk" + " FROM total_liabilities" " WHERE master_pub=$1;", 1, NULL); - /* Used in #postgres_insert_historic_denom_revenue() */ PREPARE ("historic_denomination_revenue_insert", "INSERT INTO historic_denomination_revenue" @@ -1859,35 +1811,19 @@ postgres_get_reserve_summary (void *cls, * @param session connection to use * @param denom_pub_hash hash of the denomination public key * @param denom_balance value of coins outstanding with this denomination key - * @param last_reserve_out_serial_id up to which point did we consider - * withdrawals for the above information - * @param last_deposit_serial_id up to which point did we consider - * deposits for the above information - * @param last_melt_serial_id up to which point did we consider - * melts for the above information - * @param last_refund_serial_id up to which point did we consider - * refunds for the above information * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure */ static int postgres_insert_denomination_balance (void *cls, struct TALER_AUDITORDB_Session *session, const struct GNUNET_HashCode *denom_pub_hash, - const struct TALER_Amount *denom_balance, - uint64_t last_reserve_out_serial_id, - uint64_t last_deposit_serial_id, - uint64_t last_melt_serial_id, - uint64_t last_refund_serial_id) + const struct TALER_Amount *denom_balance) { PGresult *result; int ret; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), TALER_PQ_query_param_amount (denom_balance), - GNUNET_PQ_query_param_uint64 (&last_reserve_out_serial_id), - GNUNET_PQ_query_param_uint64 (&last_deposit_serial_id), - GNUNET_PQ_query_param_uint64 (&last_melt_serial_id), - GNUNET_PQ_query_param_uint64 (&last_refund_serial_id), GNUNET_PQ_query_param_end }; @@ -1916,34 +1852,18 @@ postgres_insert_denomination_balance (void *cls, * @param session connection to use * @param denom_pub_hash hash of the denomination public key * @param denom_balance value of coins outstanding with this denomination key - * @param last_reserve_out_serial_id up to which point did we consider - * withdrawals for the above information - * @param last_deposit_serial_id up to which point did we consider - * deposits for the above information - * @param last_melt_serial_id up to which point did we consider - * melts for the above information - * @param last_refund_serial_id up to which point did we consider - * refunds for the above information * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure */ static int postgres_update_denomination_balance (void *cls, struct TALER_AUDITORDB_Session *session, const struct GNUNET_HashCode *denom_pub_hash, - const struct TALER_Amount *denom_balance, - uint64_t last_reserve_out_serial_id, - uint64_t last_deposit_serial_id, - uint64_t last_melt_serial_id, - uint64_t last_refund_serial_id) + const struct TALER_Amount *denom_balance) { PGresult *result; int ret; struct GNUNET_PQ_QueryParam params[] = { TALER_PQ_query_param_amount (denom_balance), - GNUNET_PQ_query_param_uint64 (&last_reserve_out_serial_id), - GNUNET_PQ_query_param_uint64 (&last_deposit_serial_id), - GNUNET_PQ_query_param_uint64 (&last_melt_serial_id), - GNUNET_PQ_query_param_uint64 (&last_refund_serial_id), GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), GNUNET_PQ_query_param_end }; @@ -1972,25 +1892,13 @@ postgres_update_denomination_balance (void *cls, * @param session connection to use * @param denom_pub_hash hash of the denomination public key * @param[out] denom_balance value of coins outstanding with this denomination key - * @param[out] last_reserve_out_serial_id up to which point did we consider - * withdrawals for the above information - * @param[out] last_deposit_serial_id up to which point did we consider - * deposits for the above information - * @param[out] last_melt_serial_id up to which point did we consider - * melts for the above information - * @param[out] last_refund_serial_id up to which point did we consider - * refunds for the above information * @return #GNUNET_OK on success; #GNUNET_NO if no record found, #GNUNET_SYSERR on failure */ static int postgres_get_denomination_balance (void *cls, struct TALER_AUDITORDB_Session *session, const struct GNUNET_HashCode *denom_pub_hash, - struct TALER_Amount *denom_balance, - uint64_t *last_reserve_out_serial_id, - uint64_t *last_deposit_serial_id, - uint64_t *last_melt_serial_id, - uint64_t *last_refund_serial_id) + struct TALER_Amount *denom_balance) { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), @@ -2021,11 +1929,6 @@ postgres_get_denomination_balance (void *cls, struct GNUNET_PQ_ResultSpec rs[] = { TALER_PQ_result_spec_amount ("denom_balance", denom_balance), - GNUNET_PQ_result_spec_uint64 ("last_reserve_out_serial_id", last_reserve_out_serial_id), - GNUNET_PQ_result_spec_uint64 ("last_deposit_serial_id", last_deposit_serial_id), - GNUNET_PQ_result_spec_uint64 ("last_melt_serial_id", last_melt_serial_id), - GNUNET_PQ_result_spec_uint64 ("last_refund_serial_id", last_refund_serial_id), - GNUNET_PQ_result_spec_end }; if (GNUNET_OK != @@ -2051,6 +1954,7 @@ postgres_get_denomination_balance (void *cls, * @param deposit_fee_balance total deposit fees collected for this DK * @param melt_fee_balance total melt fees collected for this DK * @param refund_fee_balance total refund fees collected for this DK + * @param risk maximum risk exposure of the exchange * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure */ static int @@ -2060,7 +1964,8 @@ postgres_insert_denomination_summary (void *cls, const struct TALER_Amount *denom_balance, const struct TALER_Amount *deposit_fee_balance, const struct TALER_Amount *melt_fee_balance, - const struct TALER_Amount *refund_fee_balance) + const struct TALER_Amount *refund_fee_balance, + const struct TALER_Amount *risk) { PGresult *result; int ret; @@ -2070,6 +1975,7 @@ postgres_insert_denomination_summary (void *cls, TALER_PQ_query_param_amount (deposit_fee_balance), TALER_PQ_query_param_amount (melt_fee_balance), TALER_PQ_query_param_amount (refund_fee_balance), + TALER_PQ_query_param_amount (risk), GNUNET_PQ_query_param_end }; @@ -2113,6 +2019,7 @@ postgres_insert_denomination_summary (void *cls, * @param deposit_fee_balance total deposit fees collected for this DK * @param melt_fee_balance total melt fees collected for this DK * @param refund_fee_balance total refund fees collected for this DK + * @param risk maximum risk exposure of the exchange * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure */ static int @@ -2122,7 +2029,8 @@ postgres_update_denomination_summary (void *cls, const struct TALER_Amount *denom_balance, const struct TALER_Amount *deposit_fee_balance, const struct TALER_Amount *melt_fee_balance, - const struct TALER_Amount *refund_fee_balance) + const struct TALER_Amount *refund_fee_balance, + const struct TALER_Amount *risk) { PGresult *result; int ret; @@ -2131,6 +2039,7 @@ postgres_update_denomination_summary (void *cls, TALER_PQ_query_param_amount (deposit_fee_balance), TALER_PQ_query_param_amount (melt_fee_balance), TALER_PQ_query_param_amount (refund_fee_balance), + TALER_PQ_query_param_amount (risk), GNUNET_PQ_query_param_auto_from_type (master_pub), GNUNET_PQ_query_param_end }; @@ -2162,6 +2071,7 @@ postgres_update_denomination_summary (void *cls, * @param[out] deposit_fee_balance total deposit fees collected for this DK * @param[out] melt_fee_balance total melt fees collected for this DK * @param[out] refund_fee_balance total refund fees collected for this DK + * @param[out] risk maximum risk exposure of the exchange * @return #GNUNET_OK on success; #GNUNET_NO if there is no entry * for this @a master_pub; #GNUNET_SYSERR on failure */ @@ -2172,7 +2082,8 @@ postgres_get_denomination_summary (void *cls, struct TALER_Amount *denom_balance, struct TALER_Amount *deposit_fee_balance, struct TALER_Amount *melt_fee_balance, - struct TALER_Amount *refund_fee_balance) + struct TALER_Amount *refund_fee_balance, + struct TALER_Amount *risk) { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (master_pub), @@ -2206,149 +2117,7 @@ postgres_get_denomination_summary (void *cls, TALER_PQ_result_spec_amount ("deposit_fee_balance", deposit_fee_balance), TALER_PQ_result_spec_amount ("melt_fee_balance", melt_fee_balance), TALER_PQ_result_spec_amount ("refund_fee_balance", refund_fee_balance), - - GNUNET_PQ_result_spec_end - }; - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, rs, 0)) - { - GNUNET_break (0); - PQclear (result); - return GNUNET_SYSERR; - } - PQclear (result); - return GNUNET_OK; -} - - -/** - * Insert information about an exchange's risk exposure. There - * must not 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 risk maximum risk exposure of the exchange - * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure - */ -static int -postgres_insert_risk_summary (void *cls, - struct TALER_AUDITORDB_Session *session, - const struct TALER_MasterPublicKeyP *master_pub, - const struct TALER_Amount *risk) -{ - PGresult *result; - int ret; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (master_pub), - TALER_PQ_query_param_amount (risk), - GNUNET_PQ_query_param_end - }; - - result = GNUNET_PQ_exec_prepared (session->conn, - "total_risk_insert", - params); - if (PGRES_COMMAND_OK != PQresultStatus (result)) - { - ret = GNUNET_SYSERR; - BREAK_DB_ERR (result); - } - else - { - ret = GNUNET_OK; - } - PQclear (result); - return ret; -} - - -/** - * Update information about an exchange's risk exposure. 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 risk maximum risk exposure of the exchange - * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure - */ -static int -postgres_update_risk_summary (void *cls, - struct TALER_AUDITORDB_Session *session, - const struct TALER_MasterPublicKeyP *master_pub, - const struct TALER_Amount *risk) -{ - PGresult *result; - int ret; - struct GNUNET_PQ_QueryParam params[] = { - TALER_PQ_query_param_amount (risk), - GNUNET_PQ_query_param_auto_from_type (master_pub), - GNUNET_PQ_query_param_end - }; - - result = GNUNET_PQ_exec_prepared (session->conn, - "total_risk_update", - params); - if (PGRES_COMMAND_OK != PQresultStatus (result)) - { - ret = GNUNET_SYSERR; - BREAK_DB_ERR (result); - } - else - { - ret = GNUNET_OK; - } - PQclear (result); - return ret; -} - - -/** - * Get information about an exchange's risk exposure. - * - * @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] risk maximum risk exposure of the exchange - * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure; - * #GNUNET_NO if we have no records for the @a master_pub - */ -static int -postgres_get_risk_summary (void *cls, - struct TALER_AUDITORDB_Session *session, - const struct TALER_MasterPublicKeyP *master_pub, - struct TALER_Amount *risk) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (master_pub), - GNUNET_PQ_query_param_end - }; - PGresult *result; - - result = GNUNET_PQ_exec_prepared (session->conn, - "total_risk_select", - params); - if (PGRES_TUPLES_OK != - PQresultStatus (result)) - { - BREAK_DB_ERR (result); - PQclear (result); - return GNUNET_SYSERR; - } - - int nrows = PQntuples (result); - if (0 == nrows) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "postgres_get_risk_summary() returned 0 matching rows\n"); - PQclear (result); - return GNUNET_NO; - } - GNUNET_assert (1 == nrows); - - struct GNUNET_PQ_ResultSpec rs[] = { TALER_PQ_result_spec_amount ("risk", risk), - GNUNET_PQ_result_spec_end }; if (GNUNET_OK != @@ -3003,10 +2772,6 @@ libtaler_plugin_auditordb_postgres_init (void *cls) plugin->update_denomination_summary = &postgres_update_denomination_summary; plugin->insert_denomination_summary = &postgres_insert_denomination_summary; - plugin->get_risk_summary = &postgres_get_risk_summary; - plugin->update_risk_summary = &postgres_update_risk_summary; - plugin->insert_risk_summary = &postgres_insert_risk_summary; - plugin->select_historic_denom_revenue = &postgres_select_historic_denom_revenue; plugin->insert_historic_denom_revenue = &postgres_insert_historic_denom_revenue; diff --git a/src/auditordb/test_auditordb.c b/src/auditordb/test_auditordb.c index 5aaabb5a2..2681a386b 100644 --- a/src/auditordb/test_auditordb.c +++ b/src/auditordb/test_auditordb.c @@ -358,6 +358,7 @@ run (void *cls) struct TALER_Amount denom_balance, deposit_fee_balance, melt_fee_balance, refund_fee_balance; struct TALER_Amount denom_balance2, deposit_fee_balance2, melt_fee_balance2, refund_fee_balance2; + struct TALER_Amount rbalance, rbalance2; GNUNET_assert (GNUNET_OK == TALER_string_to_amount (CURRENCY ":12.345678", @@ -371,16 +372,15 @@ run (void *cls) GNUNET_assert (GNUNET_OK == TALER_string_to_amount (CURRENCY ":45.678901", &refund_fee_balance)); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":13.57986", + &rbalance)); FAILIF (GNUNET_OK != plugin->insert_denomination_balance (plugin->cls, session, &denom_pub_hash, - &denom_balance, - pp.last_reserve_out_serial_id, - pp.last_deposit_serial_id, - pp.last_melt_serial_id, - pp.last_refund_serial_id)); + &denom_balance)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test: update_denomination_balance\n"); @@ -394,12 +394,7 @@ run (void *cls) plugin->update_denomination_balance (plugin->cls, session, &denom_pub_hash, - &denom_balance, - pp.last_reserve_out_serial_id, - pp.last_deposit_serial_id, - pp.last_melt_serial_id, - pp.last_refund_serial_id)); - + &denom_balance)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test: get_denomination_balance\n"); @@ -407,17 +402,10 @@ run (void *cls) plugin->get_denomination_balance (plugin->cls, session, &denom_pub_hash, - &denom_balance2, - &pp2.last_reserve_out_serial_id, - &pp2.last_deposit_serial_id, - &pp2.last_melt_serial_id, - &pp2.last_refund_serial_id)); + &denom_balance2)); + + FAILIF (0 != memcmp (&denom_balance2, &denom_balance, sizeof (denom_balance))); - FAILIF (0 != memcmp (&denom_balance2, &denom_balance, sizeof (denom_balance)) - || pp2.last_reserve_out_serial_id != pp.last_reserve_out_serial_id - || pp2.last_deposit_serial_id != pp.last_deposit_serial_id - || pp2.last_melt_serial_id != pp.last_melt_serial_id - || pp2.last_refund_serial_id != pp.last_refund_serial_id); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test: insert_denomination_summary\n"); @@ -429,7 +417,8 @@ run (void *cls) &refund_fee_balance, &melt_fee_balance, &deposit_fee_balance, - &denom_balance)); + &denom_balance, + &rbalance)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test: update_denomination_summary\n"); @@ -441,7 +430,8 @@ run (void *cls) &denom_balance, &deposit_fee_balance, &melt_fee_balance, - &refund_fee_balance)); + &refund_fee_balance, + &rbalance)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test: get_denomination_summary\n"); @@ -450,6 +440,7 @@ run (void *cls) ZR_BLK (&deposit_fee_balance2); ZR_BLK (&melt_fee_balance2); ZR_BLK (&refund_fee_balance2); + ZR_BLK (&rbalance2); FAILIF (GNUNET_OK != plugin->get_denomination_summary (plugin->cls, @@ -458,51 +449,15 @@ run (void *cls) &denom_balance2, &deposit_fee_balance2, &melt_fee_balance2, - &refund_fee_balance2)); + &refund_fee_balance2, + &rbalance2)); FAILIF (0 != memcmp (&denom_balance2, &denom_balance, sizeof (denom_balance)) || 0 != memcmp (&deposit_fee_balance2, &deposit_fee_balance, sizeof (deposit_fee_balance)) || 0 != memcmp (&melt_fee_balance2, &melt_fee_balance, sizeof (melt_fee_balance)) || 0 != memcmp (&refund_fee_balance2, &refund_fee_balance, sizeof (refund_fee_balance))); + FAILIF (0 != memcmp (&rbalance2, &rbalance, sizeof (rbalance))); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Test: insert_risk_summary\n"); - - struct TALER_Amount balance, balance2; - - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (CURRENCY ":13.57986", - &balance)); - - FAILIF (GNUNET_OK != - plugin->insert_risk_summary (plugin->cls, - session, - &master_pub, - &balance)); - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Test: update_risk_summary\n"); - - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (CURRENCY ":57.310986", - &balance)); - - FAILIF (GNUNET_OK != - plugin->update_risk_summary (plugin->cls, - session, - &master_pub, - &balance)); - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Test: get_risk_summary\n"); - - FAILIF (GNUNET_OK != - plugin->get_risk_summary (plugin->cls, - session, - &master_pub, - &balance2)); - - FAILIF (0 != memcmp (&balance2, &balance, sizeof (balance))); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test: insert_historic_denom_revenue\n"); @@ -513,7 +468,7 @@ run (void *cls) &master_pub, &denom_pub_hash, past, - &balance, + &rbalance, &deposit_fee_balance, &melt_fee_balance, &refund_fee_balance)); @@ -524,7 +479,7 @@ run (void *cls) &master_pub, &rnd_hash, now, - &balance, + &rbalance, &deposit_fee_balance, &melt_fee_balance, &refund_fee_balance)); @@ -552,7 +507,7 @@ run (void *cls) && 0 != memcmp (&revenue_timestamp2, &now, sizeof (now))) || (0 != memcmp (denom_pub_hash2, &denom_pub_hash, sizeof (denom_pub_hash)) && 0 != memcmp (denom_pub_hash2, &rnd_hash, sizeof (rnd_hash))) - || 0 != memcmp (revenue_balance2, &balance, sizeof (balance)) + || 0 != memcmp (revenue_balance2, &rbalance, sizeof (rbalance)) || 0 != memcmp (deposit_fee_balance2, &deposit_fee_balance, sizeof (deposit_fee_balance)) || 0 != memcmp (melt_fee_balance2, &melt_fee_balance, sizeof (melt_fee_balance)) || 0 != memcmp (refund_fee_balance2, &refund_fee_balance, sizeof (refund_fee_balance))) @@ -581,7 +536,7 @@ run (void *cls) &master_pub, &denom_pub_hash, past, - &balance)); + &rbalance)); FAILIF (GNUNET_OK != plugin->insert_historic_losses (plugin->cls, @@ -589,7 +544,7 @@ run (void *cls) &master_pub, &rnd_hash, past, - &balance)); + &rbalance)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test: select_historic_losses\n"); @@ -611,7 +566,7 @@ run (void *cls) && 0 != memcmp (&loss_timestamp2, &now, sizeof (now))) || (0 != memcmp (denom_pub_hash2, &denom_pub_hash, sizeof (denom_pub_hash)) && 0 != memcmp (denom_pub_hash2, &rnd_hash, sizeof (rnd_hash))) - || 0 != memcmp (loss_balance2, &balance, sizeof (balance))) + || 0 != memcmp (loss_balance2, &rbalance, sizeof (rbalance))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "select_historic_denom_revenue_result: result does not match\n"); @@ -695,20 +650,20 @@ run (void *cls) plugin->insert_predicted_result (plugin->cls, session, &master_pub, - &balance)); + &rbalance)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test: update_predicted_result\n"); GNUNET_assert (GNUNET_OK == TALER_string_to_amount (CURRENCY ":78.901234", - &balance)); + &rbalance)); FAILIF (GNUNET_OK != plugin->update_predicted_result (plugin->cls, session, &master_pub, - &balance)); + &rbalance)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test: get_predicted_balance\n"); @@ -717,9 +672,9 @@ run (void *cls) plugin->get_predicted_balance (plugin->cls, session, &master_pub, - &balance2)); + &rbalance2)); - FAILIF (0 != memcmp (&balance2, &balance, sizeof (balance))); + FAILIF (0 != memcmp (&rbalance2, &rbalance, sizeof (rbalance))); result = 0; diff --git a/src/include/taler_auditordb_plugin.h b/src/include/taler_auditordb_plugin.h index a2aefcc8c..1a29e5ae5 100644 --- a/src/include/taler_auditordb_plugin.h +++ b/src/include/taler_auditordb_plugin.h @@ -523,25 +523,14 @@ struct TALER_AUDITORDB_Plugin * @param session connection to use * @param denom_pub_hash hash of the denomination public key * @param denom_balance value of coins outstanding (or issued?) with this denomination key - * @param last_reserve_out_serial_id up to which point did we consider - * withdrawals for the above information - * @param last_deposit_serial_id up to which point did we consider - * deposits for the above information - * @param last_melt_serial_id up to which point did we consider - * melts for the above information - * @param last_refund_serial_id up to which point did we consider - * refunds for the above information * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure */ int (*insert_denomination_balance)(void *cls, struct TALER_AUDITORDB_Session *session, const struct GNUNET_HashCode *denom_pub_hash, - const struct TALER_Amount *denom_balance, - uint64_t last_reserve_out_serial_id, - uint64_t last_deposit_serial_id, - uint64_t last_melt_serial_id, - uint64_t last_refund_serial_id); + const struct TALER_Amount *denom_balance); + /** @@ -552,25 +541,13 @@ struct TALER_AUDITORDB_Plugin * @param session connection to use * @param denom_pub_hash hash of the denomination public key * @param denom_balance value of coins outstanding (or issued?) with this denomination key - * @param last_reserve_out_serial_id up to which point did we consider - * withdrawals for the above information - * @param last_deposit_serial_id up to which point did we consider - * deposits for the above information - * @param last_melt_serial_id up to which point did we consider - * melts for the above information - * @param last_refund_serial_id up to which point did we consider - * refunds for the above information * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure */ int (*update_denomination_balance)(void *cls, struct TALER_AUDITORDB_Session *session, const struct GNUNET_HashCode *denom_pub_hash, - const struct TALER_Amount *denom_balance, - uint64_t last_reserve_out_serial_id, - uint64_t last_deposit_serial_id, - uint64_t last_melt_serial_id, - uint64_t last_refund_serial_id); + const struct TALER_Amount *denom_balance); /** @@ -580,25 +557,27 @@ struct TALER_AUDITORDB_Plugin * @param session connection to use * @param denom_pub_hash hash of the denomination public key * @param[out] denom_balance value of coins outstanding (or issued?) with this denomination key - * @param[out] last_reserve_out_serial_id up to which point did we consider - * withdrawals for the above information - * @param[out] last_deposit_serial_id up to which point did we consider - * deposits for the above information - * @param[out] last_melt_serial_id up to which point did we consider - * melts for the above information - * @param[out] last_refund_serial_id up to which point did we consider - * refunds for the above information * @return #GNUNET_OK on success; #GNUNET_NO if no record found, #GNUNET_SYSERR on failure */ int (*get_denomination_balance)(void *cls, struct TALER_AUDITORDB_Session *session, const struct GNUNET_HashCode *denom_pub_hash, - struct TALER_Amount *denom_balance, - uint64_t *last_reserve_out_serial_id, - uint64_t *last_deposit_serial_id, - uint64_t *last_melt_serial_id, - uint64_t *last_refund_serial_id); + struct TALER_Amount *denom_balance); + + + /** + * Delete information about a denomination key's balances. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param session connection to use + * @param denom_pub_hash hash of the denomination public key + * @return #GNUNET_OK on success; #GNUNET_NO if no record found, #GNUNET_SYSERR on failure + */ + int + (*del_denomination_balance)(void *cls, + struct TALER_AUDITORDB_Session *session, + const struct GNUNET_HashCode *denom_pub_hash); /** @@ -612,6 +591,7 @@ struct TALER_AUDITORDB_Plugin * @param deposit_fee_balance total deposit fees collected for this DK * @param melt_fee_balance total melt fees collected for this DK * @param refund_fee_balance total refund fees collected for this DK + * @param risk maximum risk exposure of the exchange * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure */ int @@ -621,7 +601,8 @@ struct TALER_AUDITORDB_Plugin const struct TALER_Amount *denom_balance, const struct TALER_Amount *deposit_fee_balance, const struct TALER_Amount *melt_fee_balance, - const struct TALER_Amount *refund_fee_balance); + const struct TALER_Amount *refund_fee_balance, + const struct TALER_Amount *risk); /** @@ -635,6 +616,7 @@ struct TALER_AUDITORDB_Plugin * @param deposit_fee_balance total deposit fees collected for this DK * @param melt_fee_balance total melt fees collected for this DK * @param refund_fee_balance total refund fees collected for this DK + * @param risk maximum risk exposure of the exchange * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure */ int @@ -644,7 +626,8 @@ struct TALER_AUDITORDB_Plugin const struct TALER_Amount *denom_balance, const struct TALER_Amount *deposit_fee_balance, const struct TALER_Amount *melt_fee_balance, - const struct TALER_Amount *refund_fee_balance); + const struct TALER_Amount *refund_fee_balance, + const struct TALER_Amount *risk); /** @@ -657,6 +640,7 @@ struct TALER_AUDITORDB_Plugin * @param[out] deposit_fee_balance total deposit fees collected for this DK * @param[out] melt_fee_balance total melt fees collected for this DK * @param[out] refund_fee_balance total refund fees collected for this DK + * @param[out] risk maximum risk exposure of the exchange * @return #GNUNET_OK on success; #GNUNET_NO if there is no entry * for this @a master_pub; #GNUNET_SYSERR on failure */ @@ -667,58 +651,8 @@ struct TALER_AUDITORDB_Plugin struct TALER_Amount *denom_balance, struct TALER_Amount *deposit_fee_balance, struct TALER_Amount *melt_fee_balance, - struct TALER_Amount *refund_fee_balance); - - - /** - * Insert information about an exchange's risk exposure. There - * must not 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 risk maximum risk exposure of the exchange - * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure - */ - int - (*insert_risk_summary)(void *cls, - struct TALER_AUDITORDB_Session *session, - const struct TALER_MasterPublicKeyP *master_pub, - const struct TALER_Amount *risk); - - - /** - * Update information about an exchange's risk exposure. 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 risk maximum risk exposure of the exchange - * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure - */ - int - (*update_risk_summary)(void *cls, - struct TALER_AUDITORDB_Session *session, - const struct TALER_MasterPublicKeyP *master_pub, - const struct TALER_Amount *risk); - - - /** - * Get information about an exchange's risk exposure. - * - * @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] risk maximum risk exposure of the exchange - * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure; - * #GNUNET_NO if we have no records for the @a master_pub - */ - int - (*get_risk_summary)(void *cls, - struct TALER_AUDITORDB_Session *session, - const struct TALER_MasterPublicKeyP *master_pub, - struct TALER_Amount *risk); + struct TALER_Amount *refund_fee_balance, + struct TALER_Amount *risk); /** |