diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-06-22 14:47:54 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-06-22 14:47:54 +0200 |
commit | ba5af82db137c465a84e44b85aeb7aa6fed0c957 (patch) | |
tree | 00d85da80f5c9f1b64afccc13ae3feb089aae2a9 | |
parent | 0caf3ac2b7716b55da43b492d0a24e33694724c5 (diff) | |
download | exchange-ba5af82db137c465a84e44b85aeb7aa6fed0c957.tar.gz exchange-ba5af82db137c465a84e44b85aeb7aa6fed0c957.zip |
-bugfixes, and FTBFS
-rw-r--r-- | src/bank-lib/fakebank.c | 6 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 74 | ||||
-rw-r--r-- | src/include/taler_exchangedb_plugin.h | 15 |
3 files changed, 77 insertions, 18 deletions
diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c index f656c878d..7dbf7df5d 100644 --- a/src/bank-lib/fakebank.c +++ b/src/bank-lib/fakebank.c | |||
@@ -1403,7 +1403,8 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h, | |||
1403 | { | 1403 | { |
1404 | struct Transaction *t = h->transactions[ha.start_idx % h->ram_limit]; | 1404 | struct Transaction *t = h->transactions[ha.start_idx % h->ram_limit]; |
1405 | 1405 | ||
1406 | if (NULL == t) | 1406 | if ( (NULL == t) || |
1407 | (t->row_id != ha.start_idx) ) | ||
1407 | { | 1408 | { |
1408 | GNUNET_assert (0 == | 1409 | GNUNET_assert (0 == |
1409 | pthread_mutex_unlock (&h->big_lock)); | 1410 | pthread_mutex_unlock (&h->big_lock)); |
@@ -1524,7 +1525,8 @@ handle_credit_history (struct TALER_FAKEBANK_Handle *h, | |||
1524 | { | 1525 | { |
1525 | struct Transaction *t = h->transactions[ha.start_idx % h->ram_limit]; | 1526 | struct Transaction *t = h->transactions[ha.start_idx % h->ram_limit]; |
1526 | 1527 | ||
1527 | if (NULL == t) | 1528 | if ( (NULL == t) || |
1529 | (t->row_id != ha.start_idx) ) | ||
1528 | { | 1530 | { |
1529 | GNUNET_assert (0 == | 1531 | GNUNET_assert (0 == |
1530 | pthread_mutex_unlock (&h->big_lock)); | 1532 | pthread_mutex_unlock (&h->big_lock)); |
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 886d26ed4..9032d0da1 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c | |||
@@ -436,7 +436,8 @@ postgres_get_session (void *cls) | |||
436 | ",gc_date" | 436 | ",gc_date" |
437 | ") VALUES " | 437 | ") VALUES " |
438 | "($1, $2, $3, $4, $5, $6)" | 438 | "($1, $2, $3, $4, $5, $6)" |
439 | " ON CONFLICT DO NOTHING;", | 439 | " ON CONFLICT DO NOTHING" |
440 | " RETURNING reserve_uuid;", | ||
440 | 6), | 441 | 6), |
441 | /* Used in #postgres_insert_reserve_closed() */ | 442 | /* Used in #postgres_insert_reserve_closed() */ |
442 | GNUNET_PQ_make_prepare ("reserves_close_insert", | 443 | GNUNET_PQ_make_prepare ("reserves_close_insert", |
@@ -478,6 +479,19 @@ postgres_get_session (void *cls) | |||
478 | " WHERE reserve_pub=$1" | 479 | " WHERE reserve_pub=$1" |
479 | " ON CONFLICT DO NOTHING;", | 480 | " ON CONFLICT DO NOTHING;", |
480 | 7), | 481 | 7), |
482 | /* Used in #postgres_reserves_in_insert() to store transaction details */ | ||
483 | GNUNET_PQ_make_prepare ("reserves_in_add_by_uuid", | ||
484 | "INSERT INTO reserves_in " | ||
485 | "(reserve_uuid" | ||
486 | ",wire_reference" | ||
487 | ",credit_val" | ||
488 | ",credit_frac" | ||
489 | ",exchange_account_section" | ||
490 | ",sender_account_details" | ||
491 | ",execution_date" | ||
492 | ") VALUES ($1, $2, $3, $4, $5, $6, $7)" | ||
493 | " ON CONFLICT DO NOTHING;", | ||
494 | 7), | ||
481 | /* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound | 495 | /* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound |
482 | transactions for reserves with serial id '\geq' the given parameter */ | 496 | transactions for reserves with serial id '\geq' the given parameter */ |
483 | GNUNET_PQ_make_prepare ("reserves_in_get_latest_wire_reference", | 497 | GNUNET_PQ_make_prepare ("reserves_in_get_latest_wire_reference", |
@@ -3488,6 +3502,7 @@ postgres_reserves_in_insert (void *cls, | |||
3488 | struct GNUNET_TIME_Absolute expiry; | 3502 | struct GNUNET_TIME_Absolute expiry; |
3489 | struct GNUNET_TIME_Absolute gc; | 3503 | struct GNUNET_TIME_Absolute gc; |
3490 | struct GNUNET_TIME_Absolute now; | 3504 | struct GNUNET_TIME_Absolute now; |
3505 | uint64_t reserve_uuid; | ||
3491 | 3506 | ||
3492 | now = GNUNET_TIME_absolute_get (); | 3507 | now = GNUNET_TIME_absolute_get (); |
3493 | (void) GNUNET_TIME_round_abs (&now); | 3508 | (void) GNUNET_TIME_round_abs (&now); |
@@ -3517,34 +3532,61 @@ postgres_reserves_in_insert (void *cls, | |||
3517 | TALER_PQ_query_param_absolute_time (&gc), | 3532 | TALER_PQ_query_param_absolute_time (&gc), |
3518 | GNUNET_PQ_query_param_end | 3533 | GNUNET_PQ_query_param_end |
3519 | }; | 3534 | }; |
3535 | struct GNUNET_PQ_ResultSpec rs[] = { | ||
3536 | GNUNET_PQ_result_spec_uint64 ("reserve_uuid", | ||
3537 | &reserve_uuid), | ||
3538 | GNUNET_PQ_result_spec_end | ||
3539 | }; | ||
3520 | 3540 | ||
3521 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3541 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3522 | "Reserve does not exist; creating a new one\n"); | 3542 | "Reserve does not exist; creating a new one\n"); |
3523 | /* Note: query uses 'on conflict do nothing' */ | 3543 | /* Note: query uses 'on conflict do nothing' */ |
3524 | qs1 = GNUNET_PQ_eval_prepared_non_select (session->conn, | 3544 | qs1 = GNUNET_PQ_eval_prepared_singleton_select (session->conn, |
3525 | "reserve_create", | 3545 | "reserve_create", |
3526 | params); | 3546 | params, |
3547 | rs); | ||
3527 | if (qs1 < 0) | 3548 | if (qs1 < 0) |
3528 | return qs1; | 3549 | return qs1; |
3529 | } | 3550 | } |
3530 | 3551 | ||
3531 | /* Create new incoming transaction, "ON CONFLICT DO NOTHING" | 3552 | /* Create new incoming transaction, "ON CONFLICT DO NOTHING" |
3532 | is again used to guard against duplicates. */ | 3553 | is again used to guard against duplicates. */ |
3554 | |||
3533 | { | 3555 | { |
3534 | struct GNUNET_PQ_QueryParam params[] = { | ||
3535 | GNUNET_PQ_query_param_auto_from_type (&reserve.pub), | ||
3536 | GNUNET_PQ_query_param_uint64 (&wire_ref), | ||
3537 | TALER_PQ_query_param_amount (balance), | ||
3538 | GNUNET_PQ_query_param_string (exchange_account_section), | ||
3539 | GNUNET_PQ_query_param_string (sender_account_details), | ||
3540 | TALER_PQ_query_param_absolute_time (&execution_time), | ||
3541 | GNUNET_PQ_query_param_end | ||
3542 | }; | ||
3543 | enum GNUNET_DB_QueryStatus qs2; | 3556 | enum GNUNET_DB_QueryStatus qs2; |
3544 | 3557 | ||
3545 | qs2 = GNUNET_PQ_eval_prepared_non_select (session->conn, | 3558 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs1) |
3546 | "reserves_in_add_transaction", | 3559 | { |
3547 | params); | 3560 | struct GNUNET_PQ_QueryParam params[] = { |
3561 | GNUNET_PQ_query_param_auto_from_type (&reserve.pub), | ||
3562 | GNUNET_PQ_query_param_uint64 (&wire_ref), | ||
3563 | TALER_PQ_query_param_amount (balance), | ||
3564 | GNUNET_PQ_query_param_string (exchange_account_section), | ||
3565 | GNUNET_PQ_query_param_string (sender_account_details), | ||
3566 | TALER_PQ_query_param_absolute_time (&execution_time), | ||
3567 | GNUNET_PQ_query_param_end | ||
3568 | }; | ||
3569 | |||
3570 | qs2 = GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
3571 | "reserves_in_add_transaction", | ||
3572 | params); | ||
3573 | } | ||
3574 | else | ||
3575 | { | ||
3576 | struct GNUNET_PQ_QueryParam params[] = { | ||
3577 | GNUNET_PQ_query_param_uint64 (&reserve_uuid), | ||
3578 | GNUNET_PQ_query_param_uint64 (&wire_ref), | ||
3579 | TALER_PQ_query_param_amount (balance), | ||
3580 | GNUNET_PQ_query_param_string (exchange_account_section), | ||
3581 | GNUNET_PQ_query_param_string (sender_account_details), | ||
3582 | TALER_PQ_query_param_absolute_time (&execution_time), | ||
3583 | GNUNET_PQ_query_param_end | ||
3584 | }; | ||
3585 | |||
3586 | qs2 = GNUNET_PQ_eval_prepared_non_select (session->conn, | ||
3587 | "reserves_in_add_by_uuid", | ||
3588 | params); | ||
3589 | } | ||
3548 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs2) | 3590 | if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs2) |
3549 | { | 3591 | { |
3550 | GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs2); | 3592 | GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs2); |
diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index 75e8f8bb6..1eab06fc8 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h | |||
@@ -2095,6 +2095,21 @@ struct TALER_EXCHANGEDB_Plugin | |||
2095 | 2095 | ||
2096 | 2096 | ||
2097 | /** | 2097 | /** |
2098 | * Start a READ COMMITTED transaction. | ||
2099 | * | ||
2100 | * @param cls the `struct PostgresClosure` with the plugin-specific state | ||
2101 | * @param session the database connection | ||
2102 | * @param name unique name identifying the transaction (for debugging) | ||
2103 | * must point to a constant | ||
2104 | * @return #GNUNET_OK on success | ||
2105 | */ | ||
2106 | int | ||
2107 | (*start_read_committed)(void *cls, | ||
2108 | struct TALER_EXCHANGEDB_Session *session, | ||
2109 | const char *name); | ||
2110 | |||
2111 | |||
2112 | /** | ||
2098 | * Commit a transaction. | 2113 | * Commit a transaction. |
2099 | * | 2114 | * |
2100 | * @param cls the @e cls of this struct with the plugin-specific state | 2115 | * @param cls the @e cls of this struct with the plugin-specific state |