diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/taler_mintdb_plugin.h | 4 | ||||
-rw-r--r-- | src/include/taler_signatures.h | 6 | ||||
-rw-r--r-- | src/mint-tools/taler-mint-reservemod.c | 10 | ||||
-rw-r--r-- | src/mintdb/plugin_mintdb_postgres.c | 37 | ||||
-rw-r--r-- | src/mintdb/test_mintdb.c | 23 |
5 files changed, 36 insertions, 44 deletions
diff --git a/src/include/taler_mintdb_plugin.h b/src/include/taler_mintdb_plugin.h index d8644df8d..2d1671335 100644 --- a/src/include/taler_mintdb_plugin.h +++ b/src/include/taler_mintdb_plugin.h @@ -715,7 +715,6 @@ struct TALER_MINTDB_Plugin * @param balance the amount that has to be added to the reserve * @param details bank transaction details justifying the increment, * must be unique for each incoming transaction - * @param expiry the new expiration time for the reserve (#3809) * @return #GNUNET_OK upon success; #GNUNET_NO if the given * @a details are already known for this @a reserve_pub, * #GNUNET_SYSERR upon failures (DB error, incompatible currency) @@ -725,8 +724,7 @@ struct TALER_MINTDB_Plugin struct TALER_MINTDB_Session *db, const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_Amount *balance, - const char *details, - struct GNUNET_TIME_Absolute expiry); + const char *details); /** diff --git a/src/include/taler_signatures.h b/src/include/taler_signatures.h index f1d271955..70fc1c0ad 100644 --- a/src/include/taler_signatures.h +++ b/src/include/taler_signatures.h @@ -40,6 +40,12 @@ */ #define TALER_CNC_KAPPA 3 +/** + * After what time do idle reserves "expire"? We might want to make + * this a configuration option (eventually). + */ +#define TALER_IDLE_RESERVE_EXPIRATION_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, 5) + /*********************************************/ /* Mint offline signatures (with master key) */ /*********************************************/ diff --git a/src/mint-tools/taler-mint-reservemod.c b/src/mint-tools/taler-mint-reservemod.c index 9dff5731c..75093fc75 100644 --- a/src/mint-tools/taler-mint-reservemod.c +++ b/src/mint-tools/taler-mint-reservemod.c @@ -25,11 +25,6 @@ #include "taler_mintdb_plugin.h" /** - * After what time to inactive reserves expire? - */ -#define RESERVE_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, 5) - -/** * Director of the mint, containing the keys. */ static char *mint_directory; @@ -60,7 +55,6 @@ main (int argc, char *const *argv) struct TALER_Amount add_value; char *details = NULL; struct TALER_ReservePublicKeyP reserve_pub; - struct GNUNET_TIME_Absolute expiration; struct TALER_MINTDB_Session *session; const struct GNUNET_GETOPT_CommandLineOption options[] = { {'a', "add", "DENOM", @@ -163,13 +157,11 @@ main (int argc, char *const *argv) "Failed to initialize DB session\n"); goto cleanup; } - expiration = GNUNET_TIME_relative_to_absolute (RESERVE_EXPIRATION); ret = plugin->reserves_in_insert (plugin->cls, session, &reserve_pub, &add_value, - details, - expiration); + details); if (GNUNET_SYSERR == ret) { fprintf (stderr, diff --git a/src/mintdb/plugin_mintdb_postgres.c b/src/mintdb/plugin_mintdb_postgres.c index 706b92dcf..fe2f2a49c 100644 --- a/src/mintdb/plugin_mintdb_postgres.c +++ b/src/mintdb/plugin_mintdb_postgres.c @@ -240,18 +240,16 @@ postgres_create_tables (void *cls, ",current_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",expiration_date INT8 NOT NULL" ")"); - /* reserves_in table collects the transactions which transfer funds into the - reserve. The rows of this table - correspond to each incoming transaction. - FIXME: instead of an 'expiration_date', an 'execution_date' - would be more appropriate here (#3809). */ + /* reserves_in table collects the transactions which transfer funds + into the reserve. The rows of this table correspond to each + incoming transaction. */ SQLEXEC("CREATE TABLE IF NOT EXISTS reserves_in" "(reserve_pub BYTEA REFERENCES reserves (reserve_pub) ON DELETE CASCADE" ",balance_val INT8 NOT NULL" ",balance_frac INT4 NOT NULL" ",balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",details VARCHAR NOT NULL " - ",expiration_date INT8 NOT NULL" + ",execution_date INT8 NOT NULL" ",PRIMARY KEY (reserve_pub,details)" ");"); /* Create indices on reserves_in */ @@ -259,8 +257,8 @@ postgres_create_tables (void *cls, " ON reserves_in (reserve_pub);"); SQLEXEC_INDEX ("CREATE INDEX reserves_in_reserve_pub_details_index" " ON reserves_in (reserve_pub,details);"); - SQLEXEC_INDEX ("CREATE INDEX expiration_index" - " ON reserves_in (expiration_date);"); + SQLEXEC_INDEX ("CREATE INDEX execution_index" + " ON reserves_in (execution_date);"); /* Table with the withdraw operations that have been performed on a reserve. The 'h_blind_ev' is the hash of the blinded coin. It serves as a primary key, as (broken) clients that use a non-random coin and blinding factor @@ -501,7 +499,7 @@ postgres_prepare (PGconn *db_conn) ",balance_frac" ",balance_curr" ",details" - ",expiration_date" + ",execution_date" ") VALUES " "($1, $2, $3, $4, $5, $6);", 6, NULL); @@ -512,7 +510,7 @@ postgres_prepare (PGconn *db_conn) " balance_val" ",balance_frac" ",balance_curr" - ",expiration_date" /* NOTE: not used (yet), #3817 */ + ",execution_date" /* NOTE: not used (yet), #3817 */ ",details" /* NOTE: not used (yet), #3817 */ " FROM reserves_in" " WHERE reserve_pub=$1", @@ -1143,7 +1141,6 @@ reserves_update (void *cls, * @param balance the amount that has to be added to the reserve * @param details bank transaction details justifying the increment, * must be unique for each incoming transaction - * @param expiry the new expiration time for the reserve (#3809) * @return #GNUNET_OK upon success; #GNUNET_NO if the given * @a details are already known for this @a reserve_pub, * #GNUNET_SYSERR upon failures (DB error, incompatible currency) @@ -1153,12 +1150,13 @@ postgres_reserves_in_insert (void *cls, struct TALER_MINTDB_Session *session, const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_Amount *balance, - const char *details, - struct GNUNET_TIME_Absolute expiry) + const char *details) { PGresult *result; int reserve_exists; struct TALER_MINTDB_Reserve reserve; + struct GNUNET_TIME_Absolute now; + struct GNUNET_TIME_Absolute expiry; if (GNUNET_OK != postgres_start (cls, session)) @@ -1175,6 +1173,9 @@ postgres_reserves_in_insert (void *cls, GNUNET_break (0); goto rollback; } + now = GNUNET_TIME_absolute_get (); + expiry = GNUNET_TIME_absolute_add (now, + TALER_IDLE_RESERVE_EXPIRATION_TIME); if (GNUNET_NO == reserve_exists) { /* New reserve, create balance for the first time; we do this @@ -1212,7 +1213,7 @@ postgres_reserves_in_insert (void *cls, TALER_PQ_query_param_auto_from_type (&reserve.pub), TALER_PQ_query_param_amount (balance), TALER_PQ_query_param_fixed_size (details, strlen (details)), - TALER_PQ_query_param_absolute_time (&expiry), + TALER_PQ_query_param_absolute_time (&now), TALER_PQ_query_param_end }; @@ -1375,7 +1376,8 @@ postgres_insert_withdraw_info (void *cls, PGresult *result; struct TALER_MINTDB_Reserve reserve; int ret = GNUNET_SYSERR; - struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); + struct GNUNET_TIME_Absolute now; + struct GNUNET_TIME_Absolute expiry; struct TALER_PQ_QueryParam params[] = { TALER_PQ_query_param_auto_from_type (&collectable->h_coin_envelope), TALER_PQ_query_param_rsa_public_key (collectable->denom_pub.rsa_public_key), @@ -1393,6 +1395,7 @@ postgres_insert_withdraw_info (void *cls, { return GNUNET_SYSERR; } + now = GNUNET_TIME_absolute_get (); result = TALER_PQ_exec_prepared (session->conn, "insert_withdraw_info", params); @@ -1419,6 +1422,10 @@ postgres_insert_withdraw_info (void *cls, GNUNET_break (0); goto rollback; } + expiry = GNUNET_TIME_absolute_add (now, + TALER_IDLE_RESERVE_EXPIRATION_TIME); + reserve.expiry = GNUNET_TIME_absolute_max (expiry, + reserve.expiry); if (GNUNET_OK != reserves_update (cls, session, &reserve)) diff --git a/src/mintdb/test_mintdb.c b/src/mintdb/test_mintdb.c index 0bdcec365..74c1f66fe 100644 --- a/src/mintdb/test_mintdb.c +++ b/src/mintdb/test_mintdb.c @@ -51,7 +51,6 @@ static struct TALER_MINTDB_Plugin *plugin; * @param value balance value * @param fraction balance fraction * @param currency currency of the reserve - * @param expiry expiration of the reserve * @return #GNUNET_OK if the given reserve has the same balance and expiration * as the given parameters; #GNUNET_SYSERR if not */ @@ -60,8 +59,7 @@ check_reserve (struct TALER_MINTDB_Session *session, const struct TALER_ReservePublicKeyP *pub, uint64_t value, uint32_t fraction, - const char *currency, - uint64_t expiry) + const char *currency) { struct TALER_MINTDB_Reserve reserve; @@ -74,7 +72,6 @@ check_reserve (struct TALER_MINTDB_Session *session, FAILIF (value != reserve.balance.value); FAILIF (fraction != reserve.balance.fraction); FAILIF (0 != strcmp (currency, reserve.balance.currency)); - FAILIF (expiry != reserve.expiry.abs_value_us); return GNUNET_OK; drop: @@ -236,7 +233,6 @@ run (void *cls, { struct TALER_MINTDB_Session *session; struct TALER_ReservePublicKeyP reserve_pub; - struct GNUNET_TIME_Absolute expiry; struct TALER_Amount amount; struct DenomKeyPair *dkp; struct TALER_MINTDB_CollectableBlindcoin cbc; @@ -288,37 +284,31 @@ run (void *cls, amount.value = 1; amount.fraction = 1; strcpy (amount.currency, CURRENCY); - expiry = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), - GNUNET_TIME_UNIT_HOURS); result = 4; FAILIF (GNUNET_OK != plugin->reserves_in_insert (plugin->cls, session, &reserve_pub, &amount, - "justification 1", - expiry)); + "justification 1")); FAILIF (GNUNET_OK != check_reserve (session, &reserve_pub, amount.value, amount.fraction, - amount.currency, - expiry.abs_value_us)); + amount.currency)); FAILIF (GNUNET_OK != plugin->reserves_in_insert (plugin->cls, session, &reserve_pub, &amount, - "justification 2", - expiry)); + "justification 2")); FAILIF (GNUNET_OK != check_reserve (session, &reserve_pub, ++amount.value, ++amount.fraction, - amount.currency, - expiry.abs_value_us)); + amount.currency)); dkp = create_denom_key_pair (1024, session); RND_BLK(&cbc.h_coin_envelope); RND_BLK(&cbc.reserve_sig); @@ -344,8 +334,7 @@ run (void *cls, &reserve_pub, amount.value, amount.fraction, - amount.currency, - expiry.abs_value_us)); + amount.currency)); FAILIF (GNUNET_YES != plugin->get_withdraw_info (plugin->cls, session, |