deal with wire fees from the past in the aggregator

This commit is contained in:
Christian Grothoff 2020-01-18 16:28:42 +01:00
parent c87722791d
commit 204b545db1
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
2 changed files with 54 additions and 44 deletions

View File

@ -303,13 +303,14 @@ static unsigned int aggregation_limit =
/** /**
* Advance the "af" pointer in @a wp to point to the * Find the record valid at time @a now in the fee
* currently valid record. * structure.
* *
* @param wa wire transfer fee data structure to update * @param wa wire transfer fee data structure to update
* @param now timestamp to update fees to * @param now timestamp to update fees to
* @return fee valid at @a now, or NULL if unknown
*/ */
static void static struct TALER_EXCHANGEDB_AggregateFees *
advance_fees (struct WireAccount *wa, advance_fees (struct WireAccount *wa,
struct GNUNET_TIME_Absolute now) struct GNUNET_TIME_Absolute now)
{ {
@ -319,13 +320,8 @@ advance_fees (struct WireAccount *wa,
af = wa->af; af = wa->af;
while ( (NULL != af) && while ( (NULL != af) &&
(af->end_date.abs_value_us < now.abs_value_us) ) (af->end_date.abs_value_us < now.abs_value_us) )
{ af = af->next;
struct TALER_EXCHANGEDB_AggregateFees *n = af->next; return af;
GNUNET_free (af);
af = n;
}
wa->af = af;
} }
@ -335,28 +331,30 @@ advance_fees (struct WireAccount *wa,
* @param wa wire account data structure to update * @param wa wire account data structure to update
* @param now timestamp to update fees to * @param now timestamp to update fees to
* @param session DB session to use * @param session DB session to use
* @return transaction status * @return fee valid at @a now, or NULL if unknown
*/ */
static enum GNUNET_DB_QueryStatus static struct TALER_EXCHANGEDB_AggregateFees *
update_fees (struct WireAccount *wa, update_fees (struct WireAccount *wa,
struct GNUNET_TIME_Absolute now, struct GNUNET_TIME_Absolute now,
struct TALER_EXCHANGEDB_Session *session) struct TALER_EXCHANGEDB_Session *session)
{ {
enum GNUNET_DB_QueryStatus qs; enum GNUNET_DB_QueryStatus qs;
struct TALER_EXCHANGEDB_AggregateFees *af;
advance_fees (wa, af = advance_fees (wa,
now); now);
if (NULL != wa->af) if (NULL != af)
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; return af;
/* Let's try to load it from disk... */ /* Let's try to load it from disk... */
wa->af = TALER_EXCHANGEDB_fees_read (cfg, wa->af = TALER_EXCHANGEDB_fees_read (cfg,
wa->method); wa->method);
advance_fees (wa,
now);
for (struct TALER_EXCHANGEDB_AggregateFees *p = wa->af; for (struct TALER_EXCHANGEDB_AggregateFees *p = wa->af;
NULL != p; NULL != p;
p = p->next) p = p->next)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Persisting fees starting at %s in database\n",
GNUNET_STRINGS_absolute_time_to_string (p->start_date));
qs = db_plugin->insert_wire_fee (db_plugin->cls, qs = db_plugin->insert_wire_fee (db_plugin->cls,
session, session,
wa->method, wa->method,
@ -369,15 +367,17 @@ update_fees (struct WireAccount *wa,
{ {
TALER_EXCHANGEDB_fees_free (wa->af); TALER_EXCHANGEDB_fees_free (wa->af);
wa->af = NULL; wa->af = NULL;
return qs; return NULL;
} }
} }
if (NULL != wa->af) af = advance_fees (wa,
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; now);
if (NULL != af)
return af;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to find current wire transfer fees for `%s'\n", "Failed to find current wire transfer fees for `%s'\n",
wa->method); wa->method);
return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; return NULL;
} }
@ -785,17 +785,21 @@ deposit_cb (void *cls,
/* make sure we have current fees */ /* make sure we have current fees */
au->execution_time = GNUNET_TIME_absolute_get (); au->execution_time = GNUNET_TIME_absolute_get ();
(void) GNUNET_TIME_round_abs (&au->execution_time); (void) GNUNET_TIME_round_abs (&au->execution_time);
qs = update_fees (au->wa,
au->execution_time,
au->session);
if (qs <= 0)
{ {
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) struct TALER_EXCHANGEDB_AggregateFees *af;
qs = GNUNET_DB_STATUS_HARD_ERROR;
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); af = update_fees (au->wa,
return qs; au->execution_time,
au->session);
if (NULL == af)
{
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
qs = GNUNET_DB_STATUS_HARD_ERROR;
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
au->wire_fee = af->wire_fee;
} }
au->wire_fee = au->wa->af->wire_fee;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Aggregator starts aggregation for deposit %llu to %s with wire fee %s\n", "Aggregator starts aggregation for deposit %llu to %s with wire fee %s\n",
@ -1055,8 +1059,10 @@ expired_reserve_cb (void *cls,
/* NOTE: potential optimization: use custom SQL API to not /* NOTE: potential optimization: use custom SQL API to not
fetch this: */ fetch this: */
(void) expiration_date; /* we know it expired */
GNUNET_assert (NULL == ctc); GNUNET_assert (NULL == ctc);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Processing reserve closure at %s\n",
GNUNET_STRINGS_absolute_time_to_string (expiration_date));
now = GNUNET_TIME_absolute_get (); now = GNUNET_TIME_absolute_get ();
(void) GNUNET_TIME_round_abs (&now); (void) GNUNET_TIME_round_abs (&now);
@ -1070,21 +1076,22 @@ expired_reserve_cb (void *cls,
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
/* lookup `closing_fee` */ /* lookup `closing_fee` from time of actual reserve expiration
qs = update_fees (wa, (we may be lagging behind!) */
now,
session);
if (qs <= 0)
{ {
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) struct TALER_EXCHANGEDB_AggregateFees *af;
qs = GNUNET_DB_STATUS_HARD_ERROR;
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); af = update_fees (wa,
global_ret = GNUNET_SYSERR; expiration_date,
if (GNUNET_DB_STATUS_HARD_ERROR == qs) session);
if (NULL == af)
{
global_ret = GNUNET_SYSERR;
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return qs; return GNUNET_DB_STATUS_HARD_ERROR;
}
closing_fee = &af->closing_fee;
} }
closing_fee = &wa->af->closing_fee;
/* calculate transfer amount */ /* calculate transfer amount */
ret = TALER_amount_subtract (&amount_without_fee, ret = TALER_amount_subtract (&amount_without_fee,

View File

@ -115,6 +115,9 @@ TALER_EXCHANGEDB_fees_read (const struct GNUNET_CONFIGURATION_Handle *cfg,
struct TALER_EXCHANGEDB_AggregateFees *n; struct TALER_EXCHANGEDB_AggregateFees *n;
n = wd2af (&wd); n = wd2af (&wd);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Loaded wire fees starting at %s from file\n",
GNUNET_STRINGS_absolute_time_to_string (n->start_date));
if ( ( (NULL == af) || if ( ( (NULL == af) ||
(endp->end_date.abs_value_us == n->start_date.abs_value_us) ) && (endp->end_date.abs_value_us == n->start_date.abs_value_us) ) &&
(n->start_date.abs_value_us < n->end_date.abs_value_us) ) (n->start_date.abs_value_us < n->end_date.abs_value_us) )