summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-01-29 18:12:30 +0100
committerChristian Grothoff <christian@grothoff.org>2021-01-29 18:12:30 +0100
commit10a3b45df075ec974f787783db9afeff09a54c88 (patch)
tree8cb6cf0acf274a3c594980b5331242b537f5c99f
parent38b8097d94f794287c0dea3fbbe1f80cac46a69f (diff)
downloadmerchant-10a3b45df075ec974f787783db9afeff09a54c88.tar.gz
merchant-10a3b45df075ec974f787783db9afeff09a54c88.tar.bz2
merchant-10a3b45df075ec974f787783db9afeff09a54c88.zip
retry if reserve is so far unknown (404) to merchant, instead of using short timeout that may be too short on some systems
-rw-r--r--src/backend/taler-merchant-httpd_reserves.c6
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c5
-rw-r--r--src/testing/test_merchant_api.c8
-rw-r--r--src/testing/testing_api_cmd_tip_authorize.c80
4 files changed, 76 insertions, 23 deletions
diff --git a/src/backend/taler-merchant-httpd_reserves.c b/src/backend/taler-merchant-httpd_reserves.c
index b05a22aa..2853675f 100644
--- a/src/backend/taler-merchant-httpd_reserves.c
+++ b/src/backend/taler-merchant-httpd_reserves.c
@@ -210,6 +210,12 @@ reserve_cb (void *cls,
"Failed to commit reserve activation to database (%d)\n",
(int) qs);
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Reserve activated with initial balance %s\n",
+ TALER_amount2s (balance));
+ }
free_reserve (r);
}
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index c9854942..babc47ca 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -5256,15 +5256,14 @@ RETRY:
{
struct TALER_Amount remaining;
- if (0 >=
+ if (0 >
TALER_amount_subtract (&remaining,
&exchange_initial_balance,
&tips_committed))
{
GNUNET_break (0);
postgres_rollback (pg);
- return
- TALER_EC_GENERIC_DB_INVARIANT_FAILURE;
+ return TALER_EC_GENERIC_DB_INVARIANT_FAILURE;
}
if (0 >
TALER_amount_cmp (&remaining,
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 93ebab34..57241524 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -855,10 +855,6 @@ run (void *cls,
payer_payto,
"create-reserve-tip-1"),
cmd_exec_wirewatch ("wirewatch-3"),
- /* Sleep so the merchant discovers that the reserve exists at the exchange
- before trying to authorize a tip. */
- TALER_TESTING_cmd_sleep ("wait-reserve-1",
- 1),
TALER_TESTING_cmd_tip_authorize ("authorize-tip-1",
merchant_url,
EXCHANGE_URL,
@@ -981,8 +977,6 @@ run (void *cls,
payer_payto,
"create-reserve-tip-2"),
cmd_exec_wirewatch ("wirewatch-4"),
- TALER_TESTING_cmd_sleep ("wait-reserve-2",
- 1),
TALER_TESTING_cmd_tip_authorize_from_reserve_with_ec (
"authorize-tip-insufficient-funds",
merchant_url,
@@ -1000,14 +994,12 @@ run (void *cls,
"fake-tip-authorization",
pickup_amounts_1,
TALER_EC_MERCHANT_GENERIC_TIP_ID_UNKNOWN),
-
TALER_TESTING_cmd_merchant_get_reserves ("get-reserves-2",
merchant_url,
MHD_HTTP_OK,
"create-reserve-tip-1",
"create-reserve-tip-2",
NULL),
-
TALER_TESTING_cmd_merchant_delete_reserve ("delete-reserve-tip-1",
merchant_url,
"create-reserve-tip-1",
diff --git a/src/testing/testing_api_cmd_tip_authorize.c b/src/testing/testing_api_cmd_tip_authorize.c
index 4f4d5b66..62868ecd 100644
--- a/src/testing/testing_api_cmd_tip_authorize.c
+++ b/src/testing/testing_api_cmd_tip_authorize.c
@@ -92,10 +92,35 @@ struct TipAuthorizeState
* The interpreter state.
*/
struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Task used for retries.
+ */
+ struct GNUNET_SCHEDULER_Task *retry_task;
+
+ /**
+ * How long do we wait between retries?
+ */
+ struct GNUNET_TIME_Relative backoff;
+
+ /**
+ * How many retries are left?
+ */
+ unsigned int retries_left;
+
};
/**
+ * Run the main logic of talking to the merchant.
+ *
+ * @param cls a `struct TipAuthorizeState`.
+ */
+static void
+do_retry (void *cls);
+
+
+/**
* Callback for a /tip-authorize request. Set into the state
* what was returned from the backend (@a tip_id and @a
* tip_expiration).
@@ -118,6 +143,21 @@ tip_authorize_cb (void *cls,
tas->tao = NULL;
if (tas->http_status != hr->http_status)
{
+ if ( (MHD_HTTP_NOT_FOUND == hr->http_status) &&
+ (0 < tas->retries_left) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Reserve authorization failed. Reserve may not yet be ready, retrying %u more times.\n",
+ tas->retries_left);
+ tas->retries_left--;
+ tas->backoff = GNUNET_TIME_randomized_backoff (tas->backoff,
+ GNUNET_TIME_UNIT_SECONDS);
+ tas->retry_task = GNUNET_SCHEDULER_add_delayed (tas->backoff,
+ &do_retry,
+ tas);
+ return;
+ }
+
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u (%d) to command %s\n",
hr->http_status,
@@ -197,10 +237,22 @@ tip_authorize_run (void *cls,
{
struct TipAuthorizeState *tas = cls;
+ tas->retries_left = 16;
tas->is = is;
+ tas->retry_task = GNUNET_SCHEDULER_add_now (&do_retry,
+ tas);
+}
+
+
+static void
+do_retry (void *cls)
+{
+ struct TipAuthorizeState *tas = cls;
+
+ tas->retry_task = NULL;
if (NULL == tas->reserve_reference)
{
- tas->tao = TALER_MERCHANT_tip_authorize (is->ctx,
+ tas->tao = TALER_MERCHANT_tip_authorize (tas->is->ctx,
tas->merchant_url,
"http://merchant.com/pickup",
&tas->amount,
@@ -220,7 +272,7 @@ tip_authorize_run (void *cls,
TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
0,
&reserve_pub));
- tas->tao = TALER_MERCHANT_tip_authorize2 (is->ctx,
+ tas->tao = TALER_MERCHANT_tip_authorize2 (tas->is->ctx,
tas->merchant_url,
reserve_pub,
"http://merchant.com/pickup",
@@ -229,7 +281,6 @@ tip_authorize_run (void *cls,
&tip_authorize_cb,
tas);
}
-
GNUNET_assert (NULL != tas->tao);
}
@@ -276,6 +327,11 @@ tip_authorize_cleanup (void *cls,
" did not complete\n");
TALER_MERCHANT_tip_authorize_cancel (tas->tao);
}
+ if (NULL != tas->retry_task)
+ {
+ GNUNET_SCHEDULER_cancel (tas->retry_task);
+ tas->retry_task = NULL;
+ }
GNUNET_free (tas);
}
@@ -314,15 +370,15 @@ TALER_TESTING_cmd_tip_authorize_with_ec (const char *label,
struct TALER_TESTING_Command
-TALER_TESTING_cmd_tip_authorize_from_reserve_with_ec (const char *label,
- const char *merchant_url,
- const char *exchange_url,
- const char *
- reserve_reference,
- unsigned int http_status,
- const char *justification,
- const char *amount,
- enum TALER_ErrorCode ec)
+TALER_TESTING_cmd_tip_authorize_from_reserve_with_ec (
+ const char *label,
+ const char *merchant_url,
+ const char *exchange_url,
+ const char *reserve_reference,
+ unsigned int http_status,
+ const char *justification,
+ const char *amount,
+ enum TALER_ErrorCode ec)
{
struct TipAuthorizeState *tas;