exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 81332e22941497f8181300c4ba43952e5052e7b5
parent 39d908dfb9de0c1ca792723747d0fb41d2c3233e
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 23 Aug 2024 19:43:55 +0200

fix wire-debit auditor

Diffstat:
Msrc/auditor/taler-helper-auditor-wire-debit.c | 54++++++++++++++++++++++++++++++++++++------------------
Msrc/auditordb/auditor_do_get_auditor_progress.sql | 18++++++++++++------
Msrc/auditordb/auditor_do_get_balance.sql | 7++++---
Msrc/auditordb/pg_get_auditor_progress.c | 5+++--
Msrc/auditordb/test_auditordb_checkpoints.c | 13++++++++++---
5 files changed, 65 insertions(+), 32 deletions(-)

diff --git a/src/auditor/taler-helper-auditor-wire-debit.c b/src/auditor/taler-helper-auditor-wire-debit.c @@ -43,13 +43,6 @@ /** - * How much time do we allow the aggregator to lag behind? If - * wire transfers should have been made more than #GRACE_PERIOD - * before, we issue warnings. - */ -#define GRACE_PERIOD GNUNET_TIME_UNIT_HOURS - -/** * Maximum number of wire transfers we process per * (database) transaction. */ @@ -60,16 +53,25 @@ * timestamps? Should be sufficiently large to avoid bogus reports from deltas * created by imperfect clock synchronization and network delay. */ -#define TIME_TOLERANCE GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, \ - 15) +#define TIME_TOLERANCE GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_MINUTES, \ + 15) + + +/** + * How long do we try to long-poll for bank wire transfers? + */ +#define MAX_LONGPOLL_DELAY GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_HOURS, \ + 1) /** - * How long do we long-poll for bank wire transfers? + * How long do we wait between polling for bank wire transfers at the minimum? */ -#define MAX_LONGPOLL_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS \ - , \ - 1) +#define MIN_LONGPOLL_DELAY GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_MINUTES, \ + 5) /** @@ -558,6 +560,11 @@ commit (enum GNUNET_DB_QueryStatus qs) NULL != wa; wa = wa->next) { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Transaction of account %s ends at %llu/%llu\n", + wa->ai->section_name, + (unsigned long long) wa->last_wire_out_serial_id, + (unsigned long long) wa->wire_off_out); qs = TALER_ARL_adb->update_auditor_progress ( TALER_ARL_adb->cls, wa->label_wire_out_serial_id, @@ -1065,6 +1072,7 @@ wire_out_cb ( GNUNET_TIME_timestamp2s (date), TALER_amount2s (amount), TALER_B2S (wtid)); + wa->last_wire_out_serial_id = rowid + 1; TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_wire_out), &TALER_ARL_USE_AB (total_wire_out), amount); @@ -1207,7 +1215,6 @@ wire_out_cb ( free_roi (NULL, &key, roi)); - wa->last_wire_out_serial_id = rowid + 1; return ret; } } @@ -1290,7 +1297,7 @@ dh_long_poll (void *cls) wa->dhh_task = NULL; wa->dhh_next - = GNUNET_TIME_relative_to_absolute (MAX_LONGPOLL_DELAY); + = GNUNET_TIME_relative_to_absolute (MIN_LONGPOLL_DELAY); GNUNET_assert (NULL == wa->dhh); wa->dhh = TALER_BANK_debit_history ( ctx, @@ -1322,8 +1329,12 @@ history_debit_cb ( size_t slen; wa->dhh = NULL; - if (MHD_HTTP_OK == dhr->http_status) + if ( (MHD_HTTP_OK == dhr->http_status) && + (0 != dhr->details.ok.details_length) ) + { + /* As we got results, we go again *immediately* */ wa->dhh_next = GNUNET_TIME_UNIT_ZERO_ABS; + } GNUNET_assert (NULL == wa->dhh_task); wa->dhh_task = GNUNET_SCHEDULER_add_at (wa->dhh_next, @@ -1338,11 +1349,12 @@ history_debit_cb ( = &dhr->details.ok.details[i]; GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Analyzing bank DEBIT at %s of %s with WTID %s\n", + "Analyzing bank DEBIT #%llu at %s of %s with WTID %s\n", + (unsigned long long) dd->serial_id, GNUNET_TIME_timestamp2s (dd->execution_date), TALER_amount2s (&dd->amount), TALER_B2S (&dd->wtid)); - wa->wire_off_out = dd->serial_id; + wa->wire_off_out = dd->serial_id + 1; slen = strlen (dd->credit_account_uri) + 1; roi = GNUNET_malloc (sizeof (struct ReserveOutInfo) + slen); @@ -1615,7 +1627,13 @@ begin_transaction (void) GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return qs; } + GNUNET_assert (2 == qs); wa->start_wire_out_serial_id = wa->last_wire_out_serial_id; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Resuming account %s debit audit at %llu/%llu\n", + wa->ai->section_name, + (unsigned long long) wa->last_wire_out_serial_id, + (unsigned long long) wa->wire_off_out); } qs = TALER_ARL_adb->get_auditor_progress ( TALER_ARL_adb->cls, diff --git a/src/auditordb/auditor_do_get_auditor_progress.sql b/src/auditordb/auditor_do_get_auditor_progress.sql @@ -15,22 +15,28 @@ -- -- @author Christian Grothoff -CREATE OR REPLACE FUNCTION auditor_do_get_auditor_progress( +DROP FUNCTION IF EXISTS auditor_do_get_auditor_progress; +CREATE FUNCTION auditor_do_get_auditor_progress( IN in_keys TEXT[]) -RETURNS INT8 +RETURNS SETOF INT8 LANGUAGE plpgsql AS $$ DECLARE - my_key TEXT; + ini_key TEXT; my_off INT8; BEGIN - FOREACH my_key IN ARRAY in_keys + FOREACH ini_key IN ARRAY in_keys LOOP SELECT progress_offset INTO my_off FROM auditor_progress - WHERE progress_key=my_key; - RETURN my_off; + WHERE progress_key=ini_key; + IF FOUND + THEN + RETURN NEXT my_off; + ELSE + RETURN NEXT NULL; + END IF; END LOOP; END $$; diff --git a/src/auditordb/auditor_do_get_balance.sql b/src/auditordb/auditor_do_get_balance.sql @@ -15,9 +15,10 @@ -- -- @author Christian Grothoff +DROP FUNCTION IF EXISTS auditor_do_get_balance; CREATE OR REPLACE FUNCTION auditor_do_get_balance( IN in_keys TEXT[]) -RETURNS taler_amount +RETURNS SETOF taler_amount LANGUAGE plpgsql AS $$ DECLARE @@ -36,9 +37,9 @@ BEGIN THEN my_val.val = my_rec.val; my_val.frac = my_rec.frac; - RETURN my_val; + RETURN NEXT my_val; ELSE - RETURN NULL; + RETURN NEXT NULL; END IF; END LOOP; END $$; diff --git a/src/auditordb/pg_get_auditor_progress.c b/src/auditordb/pg_get_auditor_progress.c @@ -75,7 +75,7 @@ auditor_progress_cb (void *cls, { struct AuditorProgressContext *ctx = cls; - GNUNET_assert (num_results <= ctx->len); + GNUNET_assert (num_results == ctx->len); for (unsigned int i = 0; i < num_results; i++) { bool is_missing = false; @@ -142,7 +142,6 @@ TAH_PG_get_auditor_progress (void *cls, keys[0] = progress_key; dsts[0] = progress_offset; - va_start (ap, progress_offset); while (off < cnt) @@ -163,6 +162,7 @@ TAH_PG_get_auditor_progress (void *cls, " auditor_do_get_auditor_progress AS progress_offset" " FROM auditor_do_get_auditor_progress " "($1);"); + ctx.off = 0; qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, "get_auditor_progress", params, @@ -173,6 +173,7 @@ TAH_PG_get_auditor_progress (void *cls, return GNUNET_DB_STATUS_HARD_ERROR; if (qs < 0) return qs; + GNUNET_assert (ctx.off == cnt); return qs; } } diff --git a/src/auditordb/test_auditordb_checkpoints.c b/src/auditordb/test_auditordb_checkpoints.c @@ -179,15 +179,23 @@ run (void *cls) * Test3 = 245 * Let's make sure that's the case! */ uint64_t value; + uint64_t valueNX; + uint64_t value3; GNUNET_assert ( - GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == + 3 == plugin->get_auditor_progress ( plugin->cls, "Test", &value, + "TestNX", + &valueNX, + "Test3", + &value3, NULL) ); GNUNET_assert (value == 42); + GNUNET_assert (valueNX == 0); + GNUNET_assert (value3 == 245); /* Ensure the rest are also at their expected values */ GNUNET_assert ( @@ -323,8 +331,7 @@ run (void *cls) &a1, NULL) ); - GNUNET_assert (GNUNET_OK != - TALER_amount_is_valid (&a1)); + GNUNET_assert (TALER_amount_is_zero (&a1)); result = 0; GNUNET_break (0 <=