use execution time for transactions, but expiration time for reserve summary (fixes #3809)

This commit is contained in:
Christian Grothoff 2015-06-11 13:14:59 +02:00
parent babeff1968
commit edc6d38082
5 changed files with 36 additions and 44 deletions

View File

@ -715,7 +715,6 @@ struct TALER_MINTDB_Plugin
* @param balance the amount that has to be added to the reserve * @param balance the amount that has to be added to the reserve
* @param details bank transaction details justifying the increment, * @param details bank transaction details justifying the increment,
* must be unique for each incoming transaction * 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 * @return #GNUNET_OK upon success; #GNUNET_NO if the given
* @a details are already known for this @a reserve_pub, * @a details are already known for this @a reserve_pub,
* #GNUNET_SYSERR upon failures (DB error, incompatible currency) * #GNUNET_SYSERR upon failures (DB error, incompatible currency)
@ -725,8 +724,7 @@ struct TALER_MINTDB_Plugin
struct TALER_MINTDB_Session *db, struct TALER_MINTDB_Session *db,
const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *balance, const struct TALER_Amount *balance,
const char *details, const char *details);
struct GNUNET_TIME_Absolute expiry);
/** /**

View File

@ -40,6 +40,12 @@
*/ */
#define TALER_CNC_KAPPA 3 #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) */ /* Mint offline signatures (with master key) */
/*********************************************/ /*********************************************/

View File

@ -24,11 +24,6 @@
#include <libpq-fe.h> #include <libpq-fe.h>
#include "taler_mintdb_plugin.h" #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. * Director of the mint, containing the keys.
*/ */
@ -60,7 +55,6 @@ main (int argc, char *const *argv)
struct TALER_Amount add_value; struct TALER_Amount add_value;
char *details = NULL; char *details = NULL;
struct TALER_ReservePublicKeyP reserve_pub; struct TALER_ReservePublicKeyP reserve_pub;
struct GNUNET_TIME_Absolute expiration;
struct TALER_MINTDB_Session *session; struct TALER_MINTDB_Session *session;
const struct GNUNET_GETOPT_CommandLineOption options[] = { const struct GNUNET_GETOPT_CommandLineOption options[] = {
{'a', "add", "DENOM", {'a', "add", "DENOM",
@ -163,13 +157,11 @@ main (int argc, char *const *argv)
"Failed to initialize DB session\n"); "Failed to initialize DB session\n");
goto cleanup; goto cleanup;
} }
expiration = GNUNET_TIME_relative_to_absolute (RESERVE_EXPIRATION);
ret = plugin->reserves_in_insert (plugin->cls, ret = plugin->reserves_in_insert (plugin->cls,
session, session,
&reserve_pub, &reserve_pub,
&add_value, &add_value,
details, details);
expiration);
if (GNUNET_SYSERR == ret) if (GNUNET_SYSERR == ret)
{ {
fprintf (stderr, fprintf (stderr,

View File

@ -240,18 +240,16 @@ postgres_create_tables (void *cls,
",current_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",current_balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",expiration_date INT8 NOT NULL" ",expiration_date INT8 NOT NULL"
")"); ")");
/* reserves_in table collects the transactions which transfer funds into the /* reserves_in table collects the transactions which transfer funds
reserve. The rows of this table into the reserve. The rows of this table correspond to each
correspond to each incoming transaction. incoming transaction. */
FIXME: instead of an 'expiration_date', an 'execution_date'
would be more appropriate here (#3809). */
SQLEXEC("CREATE TABLE IF NOT EXISTS reserves_in" SQLEXEC("CREATE TABLE IF NOT EXISTS reserves_in"
"(reserve_pub BYTEA REFERENCES reserves (reserve_pub) ON DELETE CASCADE" "(reserve_pub BYTEA REFERENCES reserves (reserve_pub) ON DELETE CASCADE"
",balance_val INT8 NOT NULL" ",balance_val INT8 NOT NULL"
",balance_frac INT4 NOT NULL" ",balance_frac INT4 NOT NULL"
",balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL" ",balance_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",details VARCHAR NOT NULL " ",details VARCHAR NOT NULL "
",expiration_date INT8 NOT NULL" ",execution_date INT8 NOT NULL"
",PRIMARY KEY (reserve_pub,details)" ",PRIMARY KEY (reserve_pub,details)"
");"); ");");
/* Create indices on reserves_in */ /* Create indices on reserves_in */
@ -259,8 +257,8 @@ postgres_create_tables (void *cls,
" ON reserves_in (reserve_pub);"); " ON reserves_in (reserve_pub);");
SQLEXEC_INDEX ("CREATE INDEX reserves_in_reserve_pub_details_index" SQLEXEC_INDEX ("CREATE INDEX reserves_in_reserve_pub_details_index"
" ON reserves_in (reserve_pub,details);"); " ON reserves_in (reserve_pub,details);");
SQLEXEC_INDEX ("CREATE INDEX expiration_index" SQLEXEC_INDEX ("CREATE INDEX execution_index"
" ON reserves_in (expiration_date);"); " ON reserves_in (execution_date);");
/* Table with the withdraw operations that have been performed on a reserve. /* 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 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 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_frac"
",balance_curr" ",balance_curr"
",details" ",details"
",expiration_date" ",execution_date"
") VALUES " ") VALUES "
"($1, $2, $3, $4, $5, $6);", "($1, $2, $3, $4, $5, $6);",
6, NULL); 6, NULL);
@ -512,7 +510,7 @@ postgres_prepare (PGconn *db_conn)
" balance_val" " balance_val"
",balance_frac" ",balance_frac"
",balance_curr" ",balance_curr"
",expiration_date" /* NOTE: not used (yet), #3817 */ ",execution_date" /* NOTE: not used (yet), #3817 */
",details" /* NOTE: not used (yet), #3817 */ ",details" /* NOTE: not used (yet), #3817 */
" FROM reserves_in" " FROM reserves_in"
" WHERE reserve_pub=$1", " 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 balance the amount that has to be added to the reserve
* @param details bank transaction details justifying the increment, * @param details bank transaction details justifying the increment,
* must be unique for each incoming transaction * 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 * @return #GNUNET_OK upon success; #GNUNET_NO if the given
* @a details are already known for this @a reserve_pub, * @a details are already known for this @a reserve_pub,
* #GNUNET_SYSERR upon failures (DB error, incompatible currency) * #GNUNET_SYSERR upon failures (DB error, incompatible currency)
@ -1153,12 +1150,13 @@ postgres_reserves_in_insert (void *cls,
struct TALER_MINTDB_Session *session, struct TALER_MINTDB_Session *session,
const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *balance, const struct TALER_Amount *balance,
const char *details, const char *details)
struct GNUNET_TIME_Absolute expiry)
{ {
PGresult *result; PGresult *result;
int reserve_exists; int reserve_exists;
struct TALER_MINTDB_Reserve reserve; struct TALER_MINTDB_Reserve reserve;
struct GNUNET_TIME_Absolute now;
struct GNUNET_TIME_Absolute expiry;
if (GNUNET_OK != postgres_start (cls, if (GNUNET_OK != postgres_start (cls,
session)) session))
@ -1175,6 +1173,9 @@ postgres_reserves_in_insert (void *cls,
GNUNET_break (0); GNUNET_break (0);
goto rollback; goto rollback;
} }
now = GNUNET_TIME_absolute_get ();
expiry = GNUNET_TIME_absolute_add (now,
TALER_IDLE_RESERVE_EXPIRATION_TIME);
if (GNUNET_NO == reserve_exists) if (GNUNET_NO == reserve_exists)
{ {
/* New reserve, create balance for the first time; we do this /* 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_auto_from_type (&reserve.pub),
TALER_PQ_query_param_amount (balance), TALER_PQ_query_param_amount (balance),
TALER_PQ_query_param_fixed_size (details, strlen (details)), 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 TALER_PQ_query_param_end
}; };
@ -1375,7 +1376,8 @@ postgres_insert_withdraw_info (void *cls,
PGresult *result; PGresult *result;
struct TALER_MINTDB_Reserve reserve; struct TALER_MINTDB_Reserve reserve;
int ret = GNUNET_SYSERR; 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[] = { struct TALER_PQ_QueryParam params[] = {
TALER_PQ_query_param_auto_from_type (&collectable->h_coin_envelope), TALER_PQ_query_param_auto_from_type (&collectable->h_coin_envelope),
TALER_PQ_query_param_rsa_public_key (collectable->denom_pub.rsa_public_key), 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; return GNUNET_SYSERR;
} }
now = GNUNET_TIME_absolute_get ();
result = TALER_PQ_exec_prepared (session->conn, result = TALER_PQ_exec_prepared (session->conn,
"insert_withdraw_info", "insert_withdraw_info",
params); params);
@ -1419,6 +1422,10 @@ postgres_insert_withdraw_info (void *cls,
GNUNET_break (0); GNUNET_break (0);
goto rollback; 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, if (GNUNET_OK != reserves_update (cls,
session, session,
&reserve)) &reserve))

View File

@ -51,7 +51,6 @@ static struct TALER_MINTDB_Plugin *plugin;
* @param value balance value * @param value balance value
* @param fraction balance fraction * @param fraction balance fraction
* @param currency currency of the reserve * @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 * @return #GNUNET_OK if the given reserve has the same balance and expiration
* as the given parameters; #GNUNET_SYSERR if not * as the given parameters; #GNUNET_SYSERR if not
*/ */
@ -60,8 +59,7 @@ check_reserve (struct TALER_MINTDB_Session *session,
const struct TALER_ReservePublicKeyP *pub, const struct TALER_ReservePublicKeyP *pub,
uint64_t value, uint64_t value,
uint32_t fraction, uint32_t fraction,
const char *currency, const char *currency)
uint64_t expiry)
{ {
struct TALER_MINTDB_Reserve reserve; struct TALER_MINTDB_Reserve reserve;
@ -74,7 +72,6 @@ check_reserve (struct TALER_MINTDB_Session *session,
FAILIF (value != reserve.balance.value); FAILIF (value != reserve.balance.value);
FAILIF (fraction != reserve.balance.fraction); FAILIF (fraction != reserve.balance.fraction);
FAILIF (0 != strcmp (currency, reserve.balance.currency)); FAILIF (0 != strcmp (currency, reserve.balance.currency));
FAILIF (expiry != reserve.expiry.abs_value_us);
return GNUNET_OK; return GNUNET_OK;
drop: drop:
@ -236,7 +233,6 @@ run (void *cls,
{ {
struct TALER_MINTDB_Session *session; struct TALER_MINTDB_Session *session;
struct TALER_ReservePublicKeyP reserve_pub; struct TALER_ReservePublicKeyP reserve_pub;
struct GNUNET_TIME_Absolute expiry;
struct TALER_Amount amount; struct TALER_Amount amount;
struct DenomKeyPair *dkp; struct DenomKeyPair *dkp;
struct TALER_MINTDB_CollectableBlindcoin cbc; struct TALER_MINTDB_CollectableBlindcoin cbc;
@ -288,37 +284,31 @@ run (void *cls,
amount.value = 1; amount.value = 1;
amount.fraction = 1; amount.fraction = 1;
strcpy (amount.currency, CURRENCY); strcpy (amount.currency, CURRENCY);
expiry = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
GNUNET_TIME_UNIT_HOURS);
result = 4; result = 4;
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->reserves_in_insert (plugin->cls, plugin->reserves_in_insert (plugin->cls,
session, session,
&reserve_pub, &reserve_pub,
&amount, &amount,
"justification 1", "justification 1"));
expiry));
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
check_reserve (session, check_reserve (session,
&reserve_pub, &reserve_pub,
amount.value, amount.value,
amount.fraction, amount.fraction,
amount.currency, amount.currency));
expiry.abs_value_us));
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->reserves_in_insert (plugin->cls, plugin->reserves_in_insert (plugin->cls,
session, session,
&reserve_pub, &reserve_pub,
&amount, &amount,
"justification 2", "justification 2"));
expiry));
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
check_reserve (session, check_reserve (session,
&reserve_pub, &reserve_pub,
++amount.value, ++amount.value,
++amount.fraction, ++amount.fraction,
amount.currency, amount.currency));
expiry.abs_value_us));
dkp = create_denom_key_pair (1024, session); dkp = create_denom_key_pair (1024, session);
RND_BLK(&cbc.h_coin_envelope); RND_BLK(&cbc.h_coin_envelope);
RND_BLK(&cbc.reserve_sig); RND_BLK(&cbc.reserve_sig);
@ -344,8 +334,7 @@ run (void *cls,
&reserve_pub, &reserve_pub,
amount.value, amount.value,
amount.fraction, amount.fraction,
amount.currency, amount.currency));
expiry.abs_value_us));
FAILIF (GNUNET_YES != FAILIF (GNUNET_YES !=
plugin->get_withdraw_info (plugin->cls, plugin->get_withdraw_info (plugin->cls,
session, session,