summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-05-11 12:50:58 +0200
committerChristian Grothoff <christian@grothoff.org>2021-05-11 12:50:58 +0200
commit5ab6a385f191a85eef24076ecc6a307665598f19 (patch)
treea906bb3adecd95a27c6057aa927d6b8e89ec70d0 /src
parent0bcf8ea877423dd9401f74d9fdb4df790267548f (diff)
downloadmerchant-5ab6a385f191a85eef24076ecc6a307665598f19.tar.gz
merchant-5ab6a385f191a85eef24076ecc6a307665598f19.tar.bz2
merchant-5ab6a385f191a85eef24076ecc6a307665598f19.zip
add instance to query to ensure no cross-instance conflicts; still, this does not explain the GNUNET_break()/assert failure in #6854
Diffstat (limited to 'src')
-rw-r--r--src/backend/taler-merchant-httpd_private-post-transfers.c3
-rw-r--r--src/backenddb/merchant-0001.sql2
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c8
-rw-r--r--src/backenddb/test_merchantdb.c163
-rw-r--r--src/include/taler_merchantdb_plugin.h2
5 files changed, 100 insertions, 78 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-transfers.c b/src/backend/taler-merchant-httpd_private-post-transfers.c
index 9741a0a5..aafe4742 100644
--- a/src/backend/taler-merchant-httpd_private-post-transfers.c
+++ b/src/backend/taler-merchant-httpd_private-post-transfers.c
@@ -952,6 +952,7 @@ TMH_private_post_transfers (const struct TMH_RequestHandler *rh,
"transfer");
}
qs = TMH_db->lookup_transfer (TMH_db->cls,
+ ptc->hc->instance->settings.id,
ptc->exchange_url,
&ptc->wtid,
&total_amount,
@@ -1027,6 +1028,8 @@ TMH_private_post_transfers (const struct TMH_RequestHandler *rh,
TALER_EC_GENERIC_DB_STORE_FAILED,
"transfer");
case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ /* insert failed due to UNIQUE violation, after
+ the earlier lookup failed? very strange! */
GNUNET_break (0);
break;
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
diff --git a/src/backenddb/merchant-0001.sql b/src/backenddb/merchant-0001.sql
index ba2129dc..6e79c7ff 100644
--- a/src/backenddb/merchant-0001.sql
+++ b/src/backenddb/merchant-0001.sql
@@ -359,7 +359,7 @@ CREATE TABLE IF NOT EXISTS merchant_transfers
REFERENCES merchant_accounts (account_serial) ON DELETE CASCADE
,verified BOOLEAN NOT NULL DEFAULT FALSE
,confirmed BOOLEAN NOT NULL DEFAULT FALSE
- ,UNIQUE (wtid, exchange_url)
+ ,UNIQUE (wtid, exchange_url, account_serial)
);
COMMENT ON TABLE merchant_transfers
IS 'table represents the information provided by the (trusted) merchant about incoming wire transfers';
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index b5a75222..dc8c8456 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -3839,6 +3839,7 @@ postgres_lookup_deposits_by_contract_and_coin (
static enum GNUNET_DB_QueryStatus
postgres_lookup_transfer (
void *cls,
+ const char *instance_id,
const char *exchange_url,
const struct TALER_WireTransferIdentifierRawP *wtid,
struct TALER_Amount *total_amount,
@@ -3850,6 +3851,7 @@ postgres_lookup_transfer (
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_string (exchange_url),
GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_string (instance_id),
GNUNET_PQ_query_param_end
};
uint8_t verified8;
@@ -7816,9 +7818,11 @@ postgres_connect (void *cls)
" FROM merchant_transfers"
" JOIN merchant_transfer_signatures USING (credit_serial)"
" JOIN merchant_accounts USING (account_serial)"
+ " JOIN merchant_instances USING (merchant_serial)"
" WHERE wtid=$2"
- " AND exchange_url=$1",
- 2),
+ " AND exchange_url=$1"
+ " AND merchant_id=$3;",
+ 3),
/* for postgres_set_transfer_status_to_verified() */
GNUNET_PQ_make_prepare ("set_transfer_status_to_verified",
"UPDATE merchant_transfers SET"
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index aabc431a..237bd18e 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -2568,26 +2568,34 @@ lookup_deposits_cb (void *cls,
cmp->results_length += 1;
for (unsigned int i = 0; cmp->deposits_to_cmp_length > i; ++i)
{
- if ((GNUNET_OK == TALER_amount_cmp_currency (
+ if ((GNUNET_OK ==
+ TALER_amount_cmp_currency (
&cmp->deposits_to_cmp[i].amount_with_fee,
amount_with_fee)) &&
- (0 == TALER_amount_cmp (&cmp->deposits_to_cmp[i].amount_with_fee,
- amount_with_fee)) &&
- (GNUNET_OK == TALER_amount_cmp_currency (
+ (0 ==
+ TALER_amount_cmp (&cmp->deposits_to_cmp[i].amount_with_fee,
+ amount_with_fee)) &&
+ (GNUNET_OK ==
+ TALER_amount_cmp_currency (
&cmp->deposits_to_cmp[i].deposit_fee,
deposit_fee)) &&
- (0 == TALER_amount_cmp (&cmp->deposits_to_cmp[i].deposit_fee,
- deposit_fee)) &&
- (GNUNET_OK == TALER_amount_cmp_currency (
+ (0 ==
+ TALER_amount_cmp (&cmp->deposits_to_cmp[i].deposit_fee,
+ deposit_fee)) &&
+ (GNUNET_OK ==
+ TALER_amount_cmp_currency (
&cmp->deposits_to_cmp[i].refund_fee,
refund_fee)) &&
- (0 == TALER_amount_cmp (&cmp->deposits_to_cmp[i].refund_fee,
- refund_fee)) &&
- (GNUNET_OK == TALER_amount_cmp_currency (
+ (0 ==
+ TALER_amount_cmp (&cmp->deposits_to_cmp[i].refund_fee,
+ refund_fee)) &&
+ (GNUNET_OK ==
+ TALER_amount_cmp_currency (
&cmp->deposits_to_cmp[i].wire_fee,
wire_fee)) &&
- (0 == TALER_amount_cmp (&cmp->deposits_to_cmp[i].wire_fee,
- wire_fee)))
+ (0 ==
+ TALER_amount_cmp (&cmp->deposits_to_cmp[i].wire_fee,
+ wire_fee)))
{
cmp->results_matching[i] += 1;
}
@@ -2664,21 +2672,21 @@ test_lookup_deposits (const struct InstanceData *instance,
* @param exchange_pub public key of the exchange.
*/
static void
-lookup_deposits_contract_coin_cb (void *cls,
- const char *exchange_url,
- const struct TALER_Amount *amount_with_fee,
- const struct TALER_Amount *deposit_fee,
- const struct TALER_Amount *refund_fee,
- const struct TALER_Amount *wire_fee,
- const struct GNUNET_HashCode *h_wire,
- struct GNUNET_TIME_Absolute deposit_timestamp,
- struct GNUNET_TIME_Absolute refund_deadline,
- const struct
- TALER_ExchangeSignatureP *exchange_sig,
- const struct
- TALER_ExchangePublicKeyP *exchange_pub)
+lookup_deposits_contract_coin_cb (
+ void *cls,
+ const char *exchange_url,
+ const struct TALER_Amount *amount_with_fee,
+ const struct TALER_Amount *deposit_fee,
+ const struct TALER_Amount *refund_fee,
+ const struct TALER_Amount *wire_fee,
+ const struct GNUNET_HashCode *h_wire,
+ struct GNUNET_TIME_Absolute deposit_timestamp,
+ struct GNUNET_TIME_Absolute refund_deadline,
+ const struct TALER_ExchangeSignatureP *exchange_sig,
+ const struct TALER_ExchangePublicKeyP *exchange_pub)
{
struct TestLookupDeposits_Closure *cmp = cls;
+
if (NULL == cmp)
return;
cmp->results_length += 1;
@@ -2730,13 +2738,12 @@ lookup_deposits_contract_coin_cb (void *cls,
* @return 0 on success, 1 otherwise.
*/
static int
-test_lookup_deposits_contract_and_coin (const struct InstanceData *instance,
- const struct
- GNUNET_HashCode *h_contract,
- const struct
- TALER_CoinSpendPublicKeyP *coin_pub,
- unsigned int deposits_length,
- const struct DepositData *deposits)
+test_lookup_deposits_contract_and_coin (
+ const struct InstanceData *instance,
+ const struct GNUNET_HashCode *h_contract,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ unsigned int deposits_length,
+ const struct DepositData *deposits)
{
unsigned int results_matching[deposits_length];
struct TestLookupDeposits_Closure cmp = {
@@ -2748,17 +2755,16 @@ test_lookup_deposits_contract_and_coin (const struct InstanceData *instance,
memset (results_matching,
0,
sizeof (unsigned int) * deposits_length);
- TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
- plugin->lookup_deposits_by_contract_and_coin (
- plugin->cls,
- instance
- ->instance.id,
- h_contract,
- coin_pub,
- &
- lookup_deposits_contract_coin_cb,
- &cmp),
- "Lookup deposits by contract and coin failed\n");
+ TEST_COND_RET_ON_FAIL (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->lookup_deposits_by_contract_and_coin (
+ plugin->cls,
+ instance->instance.id,
+ h_contract,
+ coin_pub,
+ &lookup_deposits_contract_coin_cb,
+ &cmp),
+ "Lookup deposits by contract and coin failed\n");
if (deposits_length != cmp.results_length)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -3273,7 +3279,6 @@ struct TransferData
*/
struct TALER_WireTransferIdentifierRawP wtid;
-
/**
* The main data for the transfer.
*/
@@ -3370,14 +3375,18 @@ make_transfer (const struct ExchangeSignkeyData *signkey,
* @return 1 on success, 0 otherwise.
*/
static int
-test_lookup_transfer (const struct TransferData *transfer)
+test_lookup_transfer (
+ const struct InstanceData *instance,
+ const struct TransferData *transfer)
{
struct TALER_Amount total_with_fee;
struct TALER_Amount total;
struct TALER_Amount fee;
struct GNUNET_TIME_Absolute time;
bool verified;
+
if (1 != plugin->lookup_transfer (plugin->cls,
+ instance->instance.id,
transfer->exchange_url,
&transfer->wtid,
&total,
@@ -3482,12 +3491,12 @@ lookup_transfer_summary_cb (void *cls,
* @return 1 on success, 0 otherwise.
*/
static int
-test_lookup_transfer_summary (const char *exchange_url,
- const struct
- TALER_WireTransferIdentifierRawP *wtid,
- const char *expected_order_id,
- const struct TALER_Amount *expected_deposit_value,
- const struct TALER_Amount *expected_deposit_fee)
+test_lookup_transfer_summary (
+ const char *exchange_url,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const char *expected_order_id,
+ const struct TALER_Amount *expected_deposit_value,
+ const struct TALER_Amount *expected_deposit_fee)
{
struct TestLookupTransferSummary_Closure cmp = {
.order_id = expected_order_id,
@@ -3591,11 +3600,11 @@ lookup_transfer_details_cb (void *cls,
* @return 1 on success, 0 otherwise.
*/
static int
-test_lookup_transfer_details (const char *exchange_url,
- const struct
- TALER_WireTransferIdentifierRawP *wtid,
- unsigned int details_length,
- const struct TALER_TrackTransferDetails *details)
+test_lookup_transfer_details (
+ const char *exchange_url,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ unsigned int details_length,
+ const struct TALER_TrackTransferDetails *details)
{
unsigned int results_matching[details_length];
struct TestLookupTransferDetails_Closure cmp = {
@@ -3676,14 +3685,14 @@ struct TestLookupTransferDetailsByOrder_Closure
* @param transfer_confirmed whether the transfer was confirmed.
*/
static void
-lookup_transfer_details_order_cb (void *cls,
- const struct
- TALER_WireTransferIdentifierRawP *wtid,
- const char *exchange_url,
- struct GNUNET_TIME_Absolute execution_time,
- const struct TALER_Amount *deposit_value,
- const struct TALER_Amount *deposit_fee,
- bool transfer_confirmed)
+lookup_transfer_details_order_cb (
+ void *cls,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const char *exchange_url,
+ struct GNUNET_TIME_Absolute execution_time,
+ const struct TALER_Amount *deposit_value,
+ const struct TALER_Amount *deposit_fee,
+ bool transfer_confirmed)
{
struct TestLookupTransferDetailsByOrder_Closure *cmp = cls;
if (NULL == cmp)
@@ -3724,10 +3733,10 @@ lookup_transfer_details_order_cb (void *cls,
* @return 0 on success, 1 otherwise.
*/
static int
-test_lookup_transfer_details_by_order (uint64_t order_serial,
- unsigned int transfers_length,
- const struct
- TransferData *transfers)
+test_lookup_transfer_details_by_order (
+ uint64_t order_serial,
+ unsigned int transfers_length,
+ const struct TransferData *transfers)
{
unsigned int results_matching[transfers_length];
struct TestLookupTransferDetailsByOrder_Closure cmp = {
@@ -4051,6 +4060,7 @@ test_insert_deposit_to_transfer (const struct InstanceData *instance,
uint64_t deposit_serial = get_deposit_serial (instance,
order,
deposit);
+
TEST_COND_RET_ON_FAIL (expected_result ==
plugin->insert_deposit_to_transfer (plugin->cls,
deposit_serial,
@@ -4070,11 +4080,11 @@ test_insert_deposit_to_transfer (const struct InstanceData *instance,
* @return 0 on success, 1 otherwise.
*/
static int
-test_insert_transfer_details (const struct InstanceData *instance,
- const struct
- TALER_MERCHANTDB_AccountDetails *account,
- const struct TransferData *transfer,
- enum GNUNET_DB_QueryStatus expected_result)
+test_insert_transfer_details (
+ const struct InstanceData *instance,
+ const struct TALER_MERCHANTDB_AccountDetails *account,
+ const struct TransferData *transfer,
+ enum GNUNET_DB_QueryStatus expected_result)
{
TEST_COND_RET_ON_FAIL (expected_result ==
plugin->insert_transfer_details (plugin->cls,
@@ -4285,7 +4295,8 @@ run_test_transfers (struct TestTransfers_Closure *cls)
NULL,
false,
true));
- TEST_RET_ON_FAIL (test_lookup_transfer (&cls->transfers[0]));
+ TEST_RET_ON_FAIL (test_lookup_transfer (&cls->instance,
+ &cls->transfers[0]));
TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
plugin->set_transfer_status_to_verified (plugin->cls,
cls->deposit.
@@ -4295,7 +4306,8 @@ run_test_transfers (struct TestTransfers_Closure *cls)
wtid),
"Set transfer status to verified failed\n");
cls->transfers[0].verified = true;
- TEST_RET_ON_FAIL (test_lookup_transfer (&cls->transfers[0]));
+ TEST_RET_ON_FAIL (test_lookup_transfer (&cls->instance,
+ &cls->transfers[0]));
TEST_RET_ON_FAIL (test_lookup_transfer_summary (cls->deposit.exchange_url,
&cls->transfers[0].wtid,
cls->order.id,
@@ -4331,6 +4343,7 @@ static int
test_transfers (void)
{
struct TestTransfers_Closure test_cls;
+
pre_test_transfers (&test_cls);
int test_result = run_test_transfers (&test_cls);
post_test_transfers (&test_cls);
diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h
index 09063897..677e90d4 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -1643,6 +1643,7 @@ struct TALER_MERCHANTDB_Plugin
* Lookup transfer status.
*
* @param cls closure
+ * @param instance_id the instance to look up details at
* @param exchange_url the exchange that made the transfer
* @param payto_uri account that received the transfer
* @param wtid wire transfer subject
@@ -1657,6 +1658,7 @@ struct TALER_MERCHANTDB_Plugin
enum GNUNET_DB_QueryStatus
(*lookup_transfer)(
void *cls,
+ const char *instance_id,
const char *exchange_url,
const struct TALER_WireTransferIdentifierRawP *wtid,
struct TALER_Amount *total_amount,