track number of coins issued per denomination in auditor (not yet used)

This commit is contained in:
Christian Grothoff 2018-10-28 11:30:02 +01:00
parent fb0d7110e8
commit bd40aad7dc
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
4 changed files with 76 additions and 43 deletions

View File

@ -2753,6 +2753,12 @@ struct DenominationSummary
*/
struct TALER_Amount denom_risk;
/**
* How many coins (not their amount!) of this denomination
* did the exchange issue overall?
*/
uint64_t num_issued;
/**
* Denomination key information for this denomination.
*/
@ -2805,10 +2811,11 @@ init_denomination (const struct GNUNET_HashCode *denom_hash,
enum GNUNET_DB_QueryStatus qs;
qs = adb->get_denomination_balance (adb->cls,
asession,
denom_hash,
&ds->denom_balance,
&ds->denom_risk);
asession,
denom_hash,
&ds->denom_balance,
&ds->denom_risk,
&ds->num_issued);
if (0 > qs)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@ -2964,13 +2971,15 @@ sync_denomination (void *cls,
asession,
denom_hash,
&ds->denom_balance,
&ds->denom_risk);
&ds->denom_risk,
ds->num_issued);
else
qs = adb->insert_denomination_balance (adb->cls,
asession,
denom_hash,
&ds->denom_balance,
&ds->denom_risk);
&ds->denom_risk,
ds->num_issued);
}
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
@ -3051,6 +3060,7 @@ withdraw_cb (void *cls,
"Issued coin in denomination `%s' of total value %s\n",
GNUNET_h2s (&dh),
TALER_amount2s (&value));
ds->num_issued++;
if (GNUNET_OK !=
TALER_amount_add (&ds->denom_balance,
&ds->denom_balance,
@ -3367,6 +3377,7 @@ refresh_session_cb (void *cls,
"Created fresh coin in denomination `%s' of value %s\n",
GNUNET_h2s (&new_dkis[i]->properties.denom_hash),
TALER_amount2s (&value));
dsi->num_issued++;
if (GNUNET_OK !=
TALER_amount_add (&dsi->denom_balance,
&dsi->denom_balance,

View File

@ -308,18 +308,18 @@ postgres_create_tables (void *cls)
",wire_fee_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
")"),
/* Table with all of the outstanding denomination coins that the
exchange is aware of. "last_deposit_serial_id" marks the
deposit_serial_id from "deposits" about this denomination key
that the auditor is aware of; "last_melt_serial_id" marks the
last melt from "refresh_sessions" that the auditor is aware
of; "refund_serial_id" tells us the last entry in "refunds"
for this denom_pub that the auditor is aware of. */
exchange is aware of and what the respective balances are
(outstanding as well as issued overall which implies the
maximum value at risk). We also count the number of coins
issued (withdraw, refresh-reveal) and the number of coins seen
at the exchange (refresh-commit, deposit), not just the amounts. */
GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS auditor_denomination_pending"
"(denom_pub_hash BYTEA PRIMARY KEY"
" REFERENCES auditor_denominations (denom_pub_hash) ON DELETE CASCADE"
",denom_balance_val INT8 NOT NULL"
",denom_balance_frac INT4 NOT NULL"
",denom_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",num_issued INT8 NOT NULL"
",denom_risk_val INT8 NOT NULL"
",denom_risk_frac INT4 NOT NULL"
",denom_risk_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
@ -818,28 +818,31 @@ postgres_prepare (PGconn *db_conn)
",denom_balance_val"
",denom_balance_frac"
",denom_balance_curr"
",num_issued"
",denom_risk_val"
",denom_risk_frac"
",denom_risk_curr"
") VALUES ($1,$2,$3,$4,$5,$6,$7);",
7),
") VALUES ($1,$2,$3,$4,$5,$6,$7,$8);",
8),
/* Used in #postgres_update_denomination_balance() */
GNUNET_PQ_make_prepare ("auditor_denomination_pending_update",
"UPDATE auditor_denomination_pending SET"
" denom_balance_val=$1"
",denom_balance_frac=$2"
",denom_balance_curr=$3"
",denom_risk_val=$4"
",denom_risk_frac=$5"
",denom_risk_curr=$6"
" WHERE denom_pub_hash=$7",
7),
",num_issued=$4"
",denom_risk_val=$5"
",denom_risk_frac=$6"
",denom_risk_curr=$7"
" WHERE denom_pub_hash=$8",
8),
/* Used in #postgres_get_denomination_balance() */
GNUNET_PQ_make_prepare ("auditor_denomination_pending_select",
"SELECT"
" denom_balance_val"
",denom_balance_frac"
",denom_balance_curr"
",num_issued"
",denom_risk_val"
",denom_risk_frac"
",denom_risk_curr"
@ -2458,6 +2461,7 @@ postgres_get_wire_fee_summary (void *cls,
* @param denom_pub_hash hash of the denomination public key
* @param denom_balance value of coins outstanding with this denomination key
* @param denom_risk value of coins issued with this denomination key
* @param num_issued how many coins of this denomination did the exchange blind-sign
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
@ -2465,11 +2469,13 @@ postgres_insert_denomination_balance (void *cls,
struct TALER_AUDITORDB_Session *session,
const struct GNUNET_HashCode *denom_pub_hash,
const struct TALER_Amount *denom_balance,
const struct TALER_Amount *denom_risk)
const struct TALER_Amount *denom_risk,
uint64_t num_issued)
{
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 (&num_issued),
TALER_PQ_query_param_amount (denom_risk),
GNUNET_PQ_query_param_end
};
@ -2489,6 +2495,7 @@ postgres_insert_denomination_balance (void *cls,
* @param denom_pub_hash hash of the denomination public key
* @param denom_balance value of coins outstanding with this denomination key
* @param denom_risk value of coins issued with this denomination key
* @param num_issued how many coins of this denomination did the exchange blind-sign
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
@ -2496,10 +2503,12 @@ postgres_update_denomination_balance (void *cls,
struct TALER_AUDITORDB_Session *session,
const struct GNUNET_HashCode *denom_pub_hash,
const struct TALER_Amount *denom_balance,
const struct TALER_Amount *denom_risk)
const struct TALER_Amount *denom_risk,
uint64_t num_issued)
{
struct GNUNET_PQ_QueryParam params[] = {
TALER_PQ_query_param_amount (denom_balance),
GNUNET_PQ_query_param_uint64 (&num_issued),
TALER_PQ_query_param_amount (denom_risk),
GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
GNUNET_PQ_query_param_end
@ -2519,6 +2528,7 @@ postgres_update_denomination_balance (void *cls,
* @param denom_pub_hash hash of the denomination public key
* @param[out] denom_balance value of coins outstanding with this denomination key
* @param[out] denom_risk value of coins issued with this denomination key
* @param[out] num_issued how many coins of this denomination did the exchange blind-sign
* @return transaction status code
*/
static enum GNUNET_DB_QueryStatus
@ -2526,7 +2536,8 @@ postgres_get_denomination_balance (void *cls,
struct TALER_AUDITORDB_Session *session,
const struct GNUNET_HashCode *denom_pub_hash,
struct TALER_Amount *denom_balance,
struct TALER_Amount *denom_risk)
struct TALER_Amount *denom_risk,
uint64_t *num_issued)
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
@ -2535,6 +2546,7 @@ postgres_get_denomination_balance (void *cls,
struct GNUNET_PQ_ResultSpec rs[] = {
TALER_PQ_result_spec_amount ("denom_balance", denom_balance),
TALER_PQ_result_spec_amount ("denom_risk", denom_risk),
GNUNET_PQ_result_spec_uint64 ("num_issued", num_issued),
GNUNET_PQ_result_spec_end
};

View File

@ -364,6 +364,7 @@ run (void *cls)
struct TALER_Amount refund_fee_balance2;
struct TALER_Amount rbalance;
struct TALER_Amount rbalance2;
uint64_t nissued;
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY ":12.345678",
@ -386,7 +387,8 @@ run (void *cls)
session,
&denom_pub_hash,
&denom_balance,
&rbalance));
&rbalance,
42));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: update_denomination_balance\n");
@ -401,7 +403,8 @@ run (void *cls)
session,
&denom_pub_hash,
&denom_balance,
&rbalance));
&rbalance,
62));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: get_denomination_balance\n");
@ -410,10 +413,12 @@ run (void *cls)
session,
&denom_pub_hash,
&denom_balance2,
&rbalance2));
&rbalance2,
&nissued));
FAILIF (0 != memcmp (&denom_balance2, &denom_balance, sizeof (denom_balance)));
FAILIF (0 != memcmp (&rbalance2, &rbalance, sizeof (rbalance)));
FAILIF (62 != nissued);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@ -421,26 +426,26 @@ run (void *cls)
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_balance_summary (plugin->cls,
session,
&master_pub,
&refund_fee_balance,
&melt_fee_balance,
&deposit_fee_balance,
&denom_balance,
&rbalance));
session,
&master_pub,
&refund_fee_balance,
&melt_fee_balance,
&deposit_fee_balance,
&denom_balance,
&rbalance));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: update_balance_summary\n");
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->update_balance_summary (plugin->cls,
session,
&master_pub,
&denom_balance,
&deposit_fee_balance,
&melt_fee_balance,
&refund_fee_balance,
&rbalance));
session,
&master_pub,
&denom_balance,
&deposit_fee_balance,
&melt_fee_balance,
&refund_fee_balance,
&rbalance));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: get_balance_summary\n");

View File

@ -509,7 +509,6 @@ struct TALER_AUDITORDB_Plugin
(*insert_exchange_signkey) (void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_AUDITORDB_ExchangeSigningKey *sk);
// FIXME: above function is not yet implemented!, check for _XX for prepared statement!
/**
@ -1040,6 +1039,7 @@ struct TALER_AUDITORDB_Plugin
* @param denom_pub_hash hash of the denomination public key
* @param denom_balance value of coins outstanding with this denomination key
* @param denom_risk value of coins issued with this denomination key
* @param num_issued how many coins of this denomination did the exchange blind-sign
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
@ -1047,7 +1047,8 @@ struct TALER_AUDITORDB_Plugin
struct TALER_AUDITORDB_Session *session,
const struct GNUNET_HashCode *denom_pub_hash,
const struct TALER_Amount *denom_balance,
const struct TALER_Amount *denom_risk);
const struct TALER_Amount *denom_risk,
uint64_t num_issued);
/**
@ -1059,6 +1060,7 @@ struct TALER_AUDITORDB_Plugin
* @param denom_pub_hash hash of the denomination public key
* @param denom_balance value of coins outstanding with this denomination key
* @param denom_risk value of coins issued with this denomination key
* @param num_issued how many coins of this denomination did the exchange blind-sign
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
@ -1066,7 +1068,8 @@ struct TALER_AUDITORDB_Plugin
struct TALER_AUDITORDB_Session *session,
const struct GNUNET_HashCode *denom_pub_hash,
const struct TALER_Amount *denom_balance,
const struct TALER_Amount *denom_risk);
const struct TALER_Amount *denom_risk,
uint64_t num_issued);
/**
@ -1077,6 +1080,7 @@ struct TALER_AUDITORDB_Plugin
* @param denom_pub_hash hash of the denomination public key
* @param[out] denom_balance value of coins outstanding with this denomination key
* @param[out] denom_risk value of coins issued with this denomination key
* @param[out] num_issued how many coins of this denomination did the exchange blind-sign
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
@ -1084,7 +1088,8 @@ struct TALER_AUDITORDB_Plugin
struct TALER_AUDITORDB_Session *session,
const struct GNUNET_HashCode *denom_pub_hash,
struct TALER_Amount *denom_balance,
struct TALER_Amount *denom_risk);
struct TALER_Amount *denom_risk,
uint64_t *num_issued);
/**