check reserve balance after p2p merges

This commit is contained in:
Christian Grothoff 2022-05-09 13:25:10 +02:00
parent 06bfbd9150
commit 99a844e52e
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
8 changed files with 70 additions and 58 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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

View File

@ -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;
}

View File

@ -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 ()
};

View File

@ -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)
{

View File

@ -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;
}

View File

@ -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]))
{