From 99a844e52e48bb6e8ed63fc737d6ee62b3f0baf6 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 9 May 2022 13:25:10 +0200 Subject: check reserve balance after p2p merges --- src/exchange/taler-exchange-httpd_reserves_get.c | 60 ++++++++++-------------- src/exchangedb/drop0001-exchange-part.sql | 2 +- src/exchangedb/exchange-0001-part.sql | 4 +- src/lib/exchange_api_reserves_status.c | 9 ++-- src/testing/test_exchange_p2p.c | 42 +++++++++++++---- src/testing/testing_api_cmd_purse_get.c | 4 +- src/testing/testing_api_cmd_reserve_get.c | 5 +- src/util/payto.c | 2 +- 8 files changed, 70 insertions(+), 58 deletions(-) (limited to 'src') diff --git a/src/exchange/taler-exchange-httpd_reserves_get.c b/src/exchange/taler-exchange-httpd_reserves_get.c index 0b5db7c88..27f8faecd 100644 --- a/src/exchange/taler-exchange-httpd_reserves_get.c +++ b/src/exchange/taler-exchange-httpd_reserves_get.c @@ -174,19 +174,15 @@ struct ReserveHistoryContext */ struct TALER_ReservePublicKeyP reserve_pub; -#ifndef MBOSS_DONE - /** - * History of the reserve, set in the callback. - * FIXME: get rid of this once benchmarking is done! - */ - struct TALER_EXCHANGEDB_ReserveHistory *rh; -#endif - /** * Balance of the reserve, set in the callback. */ struct TALER_Amount balance; + /** + * Set to true if we did not find the reserve. + */ + bool not_found; }; @@ -214,16 +210,9 @@ reserve_balance_transaction (void *cls, struct ReserveHistoryContext *rsc = cls; enum GNUNET_DB_QueryStatus qs; -#ifdef MBOSS_DONE qs = TEH_plugin->get_reserve_balance (TEH_plugin->cls, &rsc->reserve_pub, &rsc->balance); -#else - qs = TEH_plugin->get_reserve_history (TEH_plugin->cls, - &rsc->reserve_pub, - &rsc->balance, - &rsc->rh); -#endif if (GNUNET_DB_STATUS_HARD_ERROR == qs) { GNUNET_break (0); @@ -233,6 +222,10 @@ reserve_balance_transaction (void *cls, TALER_EC_GENERIC_DB_FETCH_FAILED, "get_reserve_balance"); } + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) + rsc->not_found = true; + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) + rsc->not_found = false; return qs; } @@ -242,7 +235,6 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc, const char *const args[1]) { struct ReserveHistoryContext rsc; - MHD_RESULT mhd_ret; struct GNUNET_TIME_Relative timeout = GNUNET_TIME_UNIT_ZERO; struct GNUNET_DB_EventHandler *eh = NULL; @@ -302,22 +294,25 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc, &db_event_cb, rc); } - rsc.rh = NULL; - if (GNUNET_OK != - TEH_DB_run_transaction (rc->connection, - "get reserve balance", - TEH_MT_REQUEST_OTHER, - &mhd_ret, - &reserve_balance_transaction, - &rsc)) { - if (NULL != eh) - TEH_plugin->event_listen_cancel (TEH_plugin->cls, - eh); - return mhd_ret; + MHD_RESULT mhd_ret; + + if (GNUNET_OK != + TEH_DB_run_transaction (rc->connection, + "get reserve balance", + TEH_MT_REQUEST_OTHER, + &mhd_ret, + &reserve_balance_transaction, + &rsc)) + { + if (NULL != eh) + TEH_plugin->event_listen_cancel (TEH_plugin->cls, + eh); + return mhd_ret; + } } /* generate proper response */ - if (NULL == rsc.rh) + if (rsc.not_found) { struct ReservePoller *rp = rc->rh_ctx; @@ -349,16 +344,11 @@ TEH_handler_reserves_get (struct TEH_RequestContext *rc, if (NULL != eh) TEH_plugin->event_listen_cancel (TEH_plugin->cls, eh); - mhd_ret = TALER_MHD_REPLY_JSON_PACK ( + return TALER_MHD_REPLY_JSON_PACK ( rc->connection, MHD_HTTP_OK, TALER_JSON_pack_amount ("balance", &rsc.balance)); -#ifndef MBOSS_DONE - TEH_plugin->free_reserve_history (TEH_plugin->cls, - rsc.rh); -#endif - return mhd_ret; } diff --git a/src/exchangedb/drop0001-exchange-part.sql b/src/exchangedb/drop0001-exchange-part.sql index 82b51769a..9e5dcd11a 100644 --- a/src/exchangedb/drop0001-exchange-part.sql +++ b/src/exchangedb/drop0001-exchange-part.sql @@ -78,7 +78,7 @@ DROP TABLE IF EXISTS wad_out_entries CASCADE; DROP TABLE IF EXISTS wads_in CASCADE; DROP TABLE IF EXISTS wad_in_entries CASCADE; DROP TABLE IF EXISTS partner_accounts CASCADE; - +DROP TABLE IF EXISTS purse_actions CASCADE; DROP FUNCTION IF EXISTS exchange_do_withdraw; DROP FUNCTION IF EXISTS exchange_do_withdraw_limit_check; diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql index f5276d0b8..c2b3855a5 100644 --- a/src/exchangedb/exchange-0001-part.sql +++ b/src/exchangedb/exchange-0001-part.sql @@ -3136,8 +3136,8 @@ THEN -- The taler-exchange-router will take care of this. UPDATE purse_actions SET action_date=0 --- "immediately" - ,partner_serial_id=NEW.partner_serial_id - WHERE purse_pub=NEW.purse_pub; + ,partner_serial_id=my_partner_serial_id + WHERE purse_pub=in_purse_pub; ELSE -- This is a local reserve, update balance immediately. UPDATE reserves diff --git a/src/lib/exchange_api_reserves_status.c b/src/lib/exchange_api_reserves_status.c index eecd40b9c..f1221c2ba 100644 --- a/src/lib/exchange_api_reserves_status.c +++ b/src/lib/exchange_api_reserves_status.c @@ -318,10 +318,11 @@ TALER_EXCHANGE_reserves_status ( json_decref (status_obj); } ctx = TEAH_handle_to_context (exchange); - rsh->job = GNUNET_CURL_job_add (ctx, - eh, - &handle_reserves_status_finished, - rsh); + rsh->job = GNUNET_CURL_job_add2 (ctx, + eh, + rsh->post_ctx.headers, + &handle_reserves_status_finished, + rsh); return rsh; } diff --git a/src/testing/test_exchange_p2p.c b/src/testing/test_exchange_p2p.c index 39e6bb32c..e4d6f5b2f 100644 --- a/src/testing/test_exchange_p2p.c +++ b/src/testing/test_exchange_p2p.c @@ -158,7 +158,7 @@ run (void *cls, "EUR:1.01", NULL), TALER_TESTING_cmd_purse_poll ( - "poll-purse-before-merge", + "push-poll-purse-before-merge", MHD_HTTP_OK, "purse-with-deposit", "EUR:1", @@ -175,13 +175,24 @@ run (void *cls, "push-get-contract", "create-reserve-1"), TALER_TESTING_cmd_purse_poll_finish ( - "merge-purse-poll-finish", + "push-merge-purse-poll-finish", GNUNET_TIME_relative_multiply ( GNUNET_TIME_UNIT_SECONDS, 5), - "poll-purse-before-merge"), - // FIXME: trigger p2p job - // FIXME: check reserve history! + "push-poll-purse-before-merge"), + TALER_TESTING_cmd_status ( + "push-check-post-merge-reserve-balance-get", + "create-reserve-1", + "EUR:1", + MHD_HTTP_OK), +#if FIXME + /* POST history doesn't yet support P2P transfers */ + TALER_TESTING_cmd_reserves_status ( + "push-check-post-merge-reserve-balance-post", + "create-reserve-1", + "EUR:1", + MHD_HTTP_OK), +#endif TALER_TESTING_cmd_end () }; struct TALER_TESTING_Command pull[] = { @@ -198,7 +209,7 @@ run (void *cls, false, /* for deposit */ "purse-create-with-reserve"), TALER_TESTING_cmd_purse_poll ( - "poll-purse-before-deposit", + "pull-poll-purse-before-deposit", MHD_HTTP_OK, "purse-create-with-reserve", "EUR:1", @@ -213,13 +224,24 @@ run (void *cls, "EUR:1.01", NULL), TALER_TESTING_cmd_purse_poll_finish ( - "deposit-purse-poll-finish", + "pull-deposit-purse-poll-finish", GNUNET_TIME_relative_multiply ( GNUNET_TIME_UNIT_SECONDS, 5), - "poll-purse-before-deposit"), - // FIXME: trigger p2p job - // FIXME: check reserve history! + "pull-poll-purse-before-deposit"), + TALER_TESTING_cmd_status ( + "pull-check-post-merge-reserve-balance-get", + "create-reserve-1", + "EUR:2", + MHD_HTTP_OK), +#if FIXME + /* POST history doesn't yet support P2P transfers */ + TALER_TESTING_cmd_reserves_status ( + "push-check-post-merge-reserve-balance-post", + "create-reserve-1", + "EUR:2", + MHD_HTTP_OK), +#endif TALER_TESTING_cmd_end () }; diff --git a/src/testing/testing_api_cmd_purse_get.c b/src/testing/testing_api_cmd_purse_get.c index 828310ae7..3fc576912 100644 --- a/src/testing/testing_api_cmd_purse_get.c +++ b/src/testing/testing_api_cmd_purse_get.c @@ -141,7 +141,6 @@ purse_status_cb (void *cls, } if (MHD_HTTP_OK == ss->expected_response_code) { -#if 0 struct TALER_Amount eb; GNUNET_assert (GNUNET_OK == @@ -152,11 +151,10 @@ purse_status_cb (void *cls, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected amount in purse: %s\n", - TALER_amount_to_string (&rs->details.ok.balance)); + TALER_amount_to_string (&rs->details.success.balance)); TALER_TESTING_interpreter_fail (ss->is); return; } -#endif } if (NULL != ss->ps) { diff --git a/src/testing/testing_api_cmd_reserve_get.c b/src/testing/testing_api_cmd_reserve_get.c index b4375ee20..f9b8ff6cd 100644 --- a/src/testing/testing_api_cmd_reserve_get.c +++ b/src/testing/testing_api_cmd_reserve_get.c @@ -144,8 +144,9 @@ reserve_status_cb (void *cls, &rs->details.ok.balance)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected amount in reserve: %s\n", - TALER_amount_to_string (&rs->details.ok.balance)); + "Unexpected amount %s in reserve, wanted %s\n", + TALER_amount_to_string (&rs->details.ok.balance), + ss->expected_balance); TALER_TESTING_interpreter_fail (ss->is); return; } diff --git a/src/util/payto.c b/src/util/payto.c index c596f8d3f..971e24961 100644 --- a/src/util/payto.c +++ b/src/util/payto.c @@ -193,7 +193,7 @@ TALER_payto_validate (const char *payto_uri) /* This is more strict than RFC 8905, alas we do not need to support messages/instructions/etc., and it is generally better to start with a narrow whitelist; we can be more permissive later ...*/ #define ALLOWED_CHARACTERS \ - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/:&?-.,=" + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/:&?-.,=+" if (NULL == strchr (ALLOWED_CHARACTERS, (int) payto_uri[i])) { -- cgit v1.2.3