diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-01-26 18:25:24 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-01-26 18:25:30 +0100 |
commit | 52f2abe75732403263d51e365706999cb9db11d7 (patch) | |
tree | 46ec83aae7e673cae4fef4f5ab4385b042c49524 | |
parent | 1e0d328f91e4aa2ad783725671bb20d3e8cc1ef4 (diff) | |
download | merchant-52f2abe75732403263d51e365706999cb9db11d7.tar.gz merchant-52f2abe75732403263d51e365706999cb9db11d7.tar.bz2 merchant-52f2abe75732403263d51e365706999cb9db11d7.zip |
work on #8061
-rw-r--r-- | src/backend/taler-merchant-depositcheck.c | 34 | ||||
-rw-r--r-- | src/backenddb/merchant-0002.sql | 3 | ||||
-rw-r--r-- | src/backenddb/pg_lookup_pending_deposits.c | 5 | ||||
-rw-r--r-- | src/backenddb/pg_update_deposit_confirmation_status.c | 7 | ||||
-rw-r--r-- | src/backenddb/pg_update_deposit_confirmation_status.h | 2 | ||||
-rw-r--r-- | src/include/taler_merchantdb_plugin.h | 6 |
6 files changed, 47 insertions, 10 deletions
diff --git a/src/backend/taler-merchant-depositcheck.c b/src/backend/taler-merchant-depositcheck.c index b472fd65..5fec222f 100644 --- a/src/backend/taler-merchant-depositcheck.c +++ b/src/backend/taler-merchant-depositcheck.c @@ -108,6 +108,11 @@ struct ExchangeInteraction struct GNUNET_TIME_Absolute wire_deadline; /** + * Current value for the retry backoff + */ + struct GNUNET_TIME_Relative retry_backoff; + + /** * Target account hash of the deposit. */ struct TALER_MerchantWireHashP h_wire; @@ -401,7 +406,10 @@ deposit_get_cb (void *cls, const struct TALER_EXCHANGE_GetDepositResponse *dr) { struct ExchangeInteraction *w = cls; + struct GNUNET_TIME_Absolute future_retry; + future_retry + = GNUNET_TIME_relative_to_absolute (w->retry_backoff); switch (dr->hr.http_status) { case MHD_HTTP_OK: @@ -421,6 +429,18 @@ deposit_get_cb (void *cls, GNUNET_SCHEDULER_shutdown (); return; } + qs = db_plugin->update_deposit_confirmation_status ( + db_plugin->cls, + w->deposit_serial, + GNUNET_TIME_absolute_to_timestamp (future_retry), + w->retry_backoff, + NULL); + if (qs < 0) + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } break; } case MHD_HTTP_ACCEPTED: @@ -457,10 +477,6 @@ deposit_get_cb (void *cls, (TALER_AML_NORMAL == dr->details.accepted.aml_decision)) { - struct GNUNET_TIME_Absolute future_retry; - - future_retry - = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Bumping wire transfer deadline in DB to %s as that is when we will retry\n", GNUNET_TIME_absolute2s (future_retry)); @@ -468,6 +484,7 @@ deposit_get_cb (void *cls, db_plugin->cls, w->deposit_serial, GNUNET_TIME_absolute_to_timestamp (future_retry), + w->retry_backoff, "Exchange reported 202 Accepted but no KYC block"); if (qs < 0) { @@ -481,15 +498,12 @@ deposit_get_cb (void *cls, default: { enum GNUNET_DB_QueryStatus qs; - struct GNUNET_TIME_Absolute future_retry; char *msg; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Exchange %s returned tracking failure for deposited coin %s\n", exchange_url, TALER_B2S (&w->coin_pub)); - future_retry - = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS); GNUNET_asprintf (&msg, "Unexpected exchange status %u (#%d, %s)\n", dr->hr.http_status, @@ -498,7 +512,8 @@ deposit_get_cb (void *cls, qs = db_plugin->update_deposit_confirmation_status ( db_plugin->cls, w->deposit_serial, - future_retry, + GNUNET_TIME_absolute_to_timestamp (future_retry), + w->retry_backoff, msg); GNUNET_free (msg); if (qs < 0) @@ -530,6 +545,7 @@ deposit_get_cb (void *cls, * @param cls NULL * @param deposit_serial identifies the deposit operation * @param wire_deadline when is the wire due + * @param retry_backoff current value for the retry backoff * @param h_contract_terms hash of the contract terms * @param merchant_priv private key of the merchant * @param instance_id row ID of the instance @@ -542,6 +558,7 @@ pending_deposits_cb ( void *cls, uint64_t deposit_serial, struct GNUNET_TIME_Absolute wire_deadline, + struct GNUNET_TIME_Relative retry_backoff, const struct TALER_PrivateContractHashP *h_contract_terms, const struct TALER_MerchantPrivateKeyP *merchant_priv, const char *instance_id, @@ -563,6 +580,7 @@ pending_deposits_cb ( } w->deposit_serial = deposit_serial; w->wire_deadline = wire_deadline; + w->retry_backoff = GNUNET_TIME_STD_BACKOFF (retry_backoff); w->h_contract_terms = *h_contract_terms; w->merchant_priv = *merchant_priv; w->h_wire = *h_wire; diff --git a/src/backenddb/merchant-0002.sql b/src/backenddb/merchant-0002.sql index f929d891..447b705b 100644 --- a/src/backenddb/merchant-0002.sql +++ b/src/backenddb/merchant-0002.sql @@ -52,11 +52,14 @@ CREATE INDEX IF NOT EXISTS merchant_contract_terms_by_merchant_and_session ALTER TABLE merchant_deposit_confirmations ADD COLUMN wire_transfer_deadline INT8 DEFAULT (0) NOT NULL, + ADD COLUMN retry_backoff INT8 DEFAULT (0) NOT NULL, ADD COLUMN wire_pending BOOL DEFAULT (TRUE) NOT NULL, ADD COLUMN exchange_failure TEXT DEFAULT NULL; COMMENT ON COLUMN merchant_deposit_confirmations.wire_transfer_deadline IS 'when should the exchange make the wire transfer at the latest'; +COMMENT ON COLUMN merchant_deposit_confirmations.retry_backoff + IS 'exponentially increasing value we add to the wire_transfer_deadline on each failure to confirm the wire transfer'; COMMENT ON COLUMN merchant_deposit_confirmations.wire_pending IS 'true if we are awaiting wire details for a deposit of this purchase and are not blocked on KYC'; COMMENT ON COLUMN merchant_deposit_confirmations.exchange_failure diff --git a/src/backenddb/pg_lookup_pending_deposits.c b/src/backenddb/pg_lookup_pending_deposits.c index 6c14464f..c48fc24d 100644 --- a/src/backenddb/pg_lookup_pending_deposits.c +++ b/src/backenddb/pg_lookup_pending_deposits.c @@ -73,6 +73,7 @@ lookup_deposits_cb (void *cls, { uint64_t deposit_serial; struct GNUNET_TIME_Absolute wire_deadline; + struct GNUNET_TIME_Relative retry_backoff; struct TALER_PrivateContractHashP h_contract_terms; struct TALER_MerchantPrivateKeyP merchant_priv; char *instance_id; @@ -91,6 +92,8 @@ lookup_deposits_cb (void *cls, &instance_id), GNUNET_PQ_result_spec_absolute_time ("wire_transfer_deadline", &wire_deadline), + GNUNET_PQ_result_spec_relative_time ("retry_backoff", + &retry_backoff), GNUNET_PQ_result_spec_auto_from_type ("h_wire", &h_wire), TALER_PQ_result_spec_amount_with_currency ("amount_with_fee", @@ -114,6 +117,7 @@ lookup_deposits_cb (void *cls, ldc->cb (ldc->cb_cls, deposit_serial, wire_deadline, + retry_backoff, &h_contract_terms, &merchant_priv, instance_id, @@ -165,6 +169,7 @@ TMH_PG_lookup_pending_deposits ( ",md.amount_with_fee" ",md.deposit_fee" ",md.coin_pub" + ",mdc.retry_backoff" " FROM merchant_deposit_confirmations mdc" " JOIN merchant_contract_terms mct" " USING (order_serial)" diff --git a/src/backenddb/pg_update_deposit_confirmation_status.c b/src/backenddb/pg_update_deposit_confirmation_status.c index 0bc327cd..e0def393 100644 --- a/src/backenddb/pg_update_deposit_confirmation_status.c +++ b/src/backenddb/pg_update_deposit_confirmation_status.c @@ -31,13 +31,17 @@ TMH_PG_update_deposit_confirmation_status ( void *cls, uint64_t deposit_serial, struct GNUNET_TIME_Timestamp future_retry, + struct GNUNET_TIME_Relative retry_backoff, const char *emsg) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&deposit_serial), GNUNET_PQ_query_param_timestamp (&future_retry), - GNUNET_PQ_query_param_string (emsg), + NULL == emsg + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (emsg), + GNUNET_PQ_query_param_relative_time (&retry_backoff), GNUNET_PQ_query_param_end }; @@ -47,6 +51,7 @@ TMH_PG_update_deposit_confirmation_status ( "UPDATE merchant_deposit_confirmations SET" " wire_transfer_deadline=$2" ",exchange_failure=$3" + ",retry_backoff=$4" " WHERE deposit_confirmation_serial=" " (SELECT deposit_confirmation_serial" " FROM merchant_deposits" diff --git a/src/backenddb/pg_update_deposit_confirmation_status.h b/src/backenddb/pg_update_deposit_confirmation_status.h index 196e0f27..b494a3a1 100644 --- a/src/backenddb/pg_update_deposit_confirmation_status.h +++ b/src/backenddb/pg_update_deposit_confirmation_status.h @@ -33,6 +33,7 @@ * @param cls closure * @param deposit_serial deposit to update status for * @param future_retry when should we ask the exchange again + * @param retry_backoff current value for the retry backoff * @param emsg error message to record * @return database result code */ @@ -41,6 +42,7 @@ TMH_PG_update_deposit_confirmation_status ( void *cls, uint64_t deposit_serial, struct GNUNET_TIME_Timestamp future_retry, + struct GNUNET_TIME_Relative retry_backoff, const char *emsg); diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h index 2567d56e..7d0f2080 100644 --- a/src/include/taler_merchantdb_plugin.h +++ b/src/include/taler_merchantdb_plugin.h @@ -801,6 +801,7 @@ typedef void * @param cls NULL * @param deposit_serial identifies the deposit operation * @param wire_deadline when is the wire due + * @param retry_backoff current value of the retry backoff * @param h_contract_terms hash of the contract terms * @param merchant_priv private key of the merchant * @param instance_id name of the instance @@ -813,6 +814,7 @@ typedef void void *cls, uint64_t deposit_serial, struct GNUNET_TIME_Absolute wire_deadline, + struct GNUNET_TIME_Relative retry_backoff, const struct TALER_PrivateContractHashP *h_contract_terms, const struct TALER_MerchantPrivateKeyP *merchant_priv, const char *instance_id, @@ -3709,6 +3711,7 @@ struct TALER_MERCHANTDB_Plugin * @param cls closure * @param deposit_serial deposit to update status for * @param future_retry when should we ask the exchange again + * @param retry_backoff current value for the retry backoff * @param emsg error message to record * @return database result code */ @@ -3716,7 +3719,8 @@ struct TALER_MERCHANTDB_Plugin (*update_deposit_confirmation_status)( void *cls, uint64_t deposit_serial, - struct GNUNET_TIME_Absolute future_retry, + struct GNUNET_TIME_Timestamp future_retry, + struct GNUNET_TIME_Relative retry_backoff, const char *emsg); }; |