gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] branch master updated (1a37d9d8 -> 6503a9fe)


From: gnunet
Subject: [taler-exchange] branch master updated (1a37d9d8 -> 6503a9fe)
Date: Mon, 10 Aug 2020 08:15:29 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a change to branch master
in repository exchange.

    from 1a37d9d8 gana
     new c2a0196f postgres documentation suggests to avoid 'FOR UPDATE' with 
serializable transactions
     new a97983dd indentation and logging fixes
     new 6503a9fe experimental fix to #6452: merge two SQL statements into one

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/exchangedb/plugin_exchangedb_postgres.c | 100 +++++++++++++++++++---------
 src/testing/test_bank_api.c                 |   6 +-
 src/testing/test_bank_api_twisted.c         |  12 ++--
 src/testing/testing_api_cmd_bank_transfer.c |   6 +-
 src/testing/testing_api_twister_helpers.c   |  31 +++++----
 5 files changed, 100 insertions(+), 55 deletions(-)

diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index 7934639b..1dc58883 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -254,6 +254,10 @@ postgres_get_session (void *cls)
       GNUNET_PQ_make_try_execute ("SET auto_explain.log_min_duration=50;"),
       GNUNET_PQ_make_try_execute ("SET auto_explain.log_timing=TRUE;"),
       GNUNET_PQ_make_try_execute ("SET auto_explain.log_analyze=TRUE;"),
+      /* https://wiki.postgresql.org/wiki/Serializable suggests to really
+         force the default to 'serializable' if SSI is to be used. */
+      GNUNET_PQ_make_try_execute (
+        "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL 
SERIALIZABLE;"),
       GNUNET_PQ_make_try_execute ("SET enable_sort=OFF;"),
       GNUNET_PQ_make_try_execute ("SET enable_seqscan=OFF;"),
       GNUNET_PQ_EXECUTE_STATEMENT_END
@@ -356,8 +360,7 @@ postgres_get_session (void *cls)
                               ",gc_date"
                               " FROM reserves"
                               " WHERE reserve_pub=$1"
-                              " LIMIT 1"
-                              " FOR UPDATE;",
+                              " LIMIT 1;",
                               1),
       /* Used in #postgres_reserves_in_insert() when the reserve is new */
       GNUNET_PQ_make_prepare ("reserve_create",
@@ -396,6 +399,30 @@ postgres_get_session (void *cls)
                               " WHERE"
                               " reserve_pub=$5;",
                               5),
+      /* Used in #insert_withdraw_info() when coins are withdrawn from the 
reserve */
+      GNUNET_PQ_make_prepare ("reserve_reduce",
+                              "UPDATE reserves"
+                              " SET"
+                              " gc_date="
+                              " CASE WHEN (reserves.gc_date > $2)"
+                              "      THEN reserves.gc_date"
+                              "      ELSE $2"
+                              " END"
+                              ",current_balance_val="
+                              " CASE WHEN (reserves.current_balance_frac >= 
$4)"
+                              "      THEN reserves.current_balance_val - $3"
+                              "      ELSE reserves.current_balance_val - $3 - 
1"
+                              " END"
+                              ",current_balance_frac="
+                              " CASE WHEN (reserves.current_balance_frac >= 
$4)"
+                              "      THEN reserves.current_balance_frac - $4"
+                              "      ELSE 100000000 + 
reserves.current_balance_frac - $4"
+                              " END"
+                              " WHERE reserve_pub=$1"
+                              "  AND current_balance_val >= $3"
+                              "  AND ( (current_balance_frac >= $4) OR"
+                              "        (current_balance_val > $3) )",
+                              4),
       /* Used in #postgres_reserves_in_insert() to store transaction details */
       GNUNET_PQ_make_prepare ("reserves_in_add_transaction",
                               "INSERT INTO reserves_in "
@@ -461,8 +488,7 @@ postgres_get_session (void *cls)
                               ",execution_date"
                               ",sender_account_details"
                               " FROM reserves_in"
-                              " WHERE reserve_pub=$1"
-                              " FOR UPDATE;",
+                              " WHERE reserve_pub=$1;",
                               1),
       /* Lock withdraw table; NOTE: we may want to eventually shard the
          deposit table to avoid this lock being the main point of
@@ -507,8 +533,7 @@ postgres_get_session (void *cls)
                               " FROM reserves_out"
                               "    JOIN denominations denom"
                               "      USING (denom_pub_hash)"
-                              " WHERE h_blind_ev=$1"
-                              " FOR UPDATE;",
+                              " WHERE h_blind_ev=$1;",
                               1),
       /* Used during #postgres_get_reserve_history() to
          obtain all of the /reserve/withdraw operations that
@@ -528,8 +553,7 @@ postgres_get_session (void *cls)
                               " FROM reserves_out"
                               "    JOIN denominations denom"
                               "      USING (denom_pub_hash)"
-                              " WHERE reserve_pub=$1"
-                              " FOR UPDATE",
+                              " WHERE reserve_pub=$1;",
                               1),
       /* Used in #postgres_select_withdrawals_above_serial_id() */
       GNUNET_PQ_make_prepare ("audit_get_reserves_out_incr",
@@ -564,8 +588,7 @@ postgres_get_session (void *cls)
                               " denom_pub_hash"
                               ",denom_sig"
                               " FROM known_coins"
-                              " WHERE coin_pub=$1"
-                              " FOR UPDATE;",
+                              " WHERE coin_pub=$1;",
                               1),
       /* Used in #postgres_get_coin_denomination() to fetch
          the denomination public key hash for
@@ -701,8 +724,7 @@ postgres_get_session (void *cls)
                               "    JOIN denominations denom "
                               "      USING (denom_pub_hash)"
                               " WHERE rc=$1"
-                              "   ORDER BY freshcoin_index ASC"
-                              " FOR UPDATE;",
+                              "   ORDER BY freshcoin_index ASC;",
                               1),
 
       /* Used in #postgres_insert_refresh_reveal() to store the transfer
@@ -830,8 +852,7 @@ postgres_get_session (void *cls)
                               " JOIN denominations USING (denom_pub_hash)"
                               " WHERE ((coin_pub=$1)"
                               "    AND (merchant_pub=$3)"
-                              "    AND (h_contract_terms=$2))"
-                              " FOR UPDATE;",
+                              "    AND (h_contract_terms=$2));",
                               3),
       /* Fetch deposits with rowid '\geq' the given parameter */
       GNUNET_PQ_make_prepare ("audit_get_deposits_incr",
@@ -970,8 +991,7 @@ postgres_get_session (void *cls)
                               "      USING (coin_pub)"
                               "    JOIN denominations denom"
                               "      USING (denom_pub_hash)"
-                              " WHERE coin_pub=$1"
-                              " FOR UPDATE;",
+                              " WHERE coin_pub=$1;",
                               1),
 
       /* Used in #postgres_get_link_data(). */
@@ -1282,8 +1302,7 @@ postgres_get_session (void *cls)
                               "      USING (coin_pub)"
                               "    JOIN reserves_out ro"
                               "      USING (h_blind_ev)"
-                              " WHERE ro.reserve_pub=$1"
-                              " FOR UPDATE;",
+                              " WHERE ro.reserve_pub=$1;",
                               1),
       /* Used in #postgres_get_coin_transactions() to obtain recoup 
transactions
          affecting old coins of refreshed coins */
@@ -1306,8 +1325,7 @@ postgres_get_session (void *cls)
                               "    FROM refresh_commitments"
                               "       JOIN refresh_revealed_coins rrc"
                               "           USING (rc)"
-                              "    WHERE old_coin_pub=$1)"
-                              " FOR UPDATE;",
+                              "    WHERE old_coin_pub=$1);",
                               1),
       /* Used in #postgres_get_reserve_history() */
       GNUNET_PQ_make_prepare ("close_by_reserve",
@@ -1320,8 +1338,7 @@ postgres_get_session (void *cls)
                               ",receiver_account"
                               ",wtid"
                               " FROM reserves_close"
-                              " WHERE reserve_pub=$1"
-                              " FOR UPDATE",
+                              " WHERE reserve_pub=$1;",
                               1),
       /* Used in #postgres_get_expired_reserves() */
       GNUNET_PQ_make_prepare ("get_expired_reserves",
@@ -1355,8 +1372,7 @@ postgres_get_session (void *cls)
                               "   USING (h_blind_ev)"
                               " JOIN known_coins coins"
                               "   USING (coin_pub)"
-                              " WHERE recoup.coin_pub=$1"
-                              " FOR UPDATE;",
+                              " WHERE recoup.coin_pub=$1;",
                               1),
       /* Used in #postgres_get_coin_transactions() to obtain recoup 
transactions
          for a refreshed coin */
@@ -1378,8 +1394,7 @@ postgres_get_session (void *cls)
                               "      ON (rrc.rc = rc.rc)"
                               "    JOIN known_coins coins"
                               "      USING (coin_pub)"
-                              " WHERE coin_pub=$1"
-                              " FOR UPDATE;",
+                              " WHERE coin_pub=$1;",
                               1),
       /* Used in #postgres_get_reserve_by_h_blind() */
       GNUNET_PQ_make_prepare ("reserve_by_h_blind",
@@ -1387,8 +1402,7 @@ postgres_get_session (void *cls)
                               " reserve_pub"
                               " FROM reserves_out"
                               " WHERE h_blind_ev=$1"
-                              " LIMIT 1"
-                              " FOR UPDATE;",
+                              " LIMIT 1;",
                               1),
       /* Used in #postgres_get_old_coin_by_h_blind() */
       GNUNET_PQ_make_prepare ("old_coin_by_h_blind",
@@ -1398,8 +1412,7 @@ postgres_get_session (void *cls)
                               "   JOIN refresh_commitments rcom"
                               "      USING (rc)"
                               " WHERE h_coin_ev=$1"
-                              " LIMIT 1"
-                              " FOR UPDATE;",
+                              " LIMIT 1;",
                               1),
       /* used in #postgres_commit */
       GNUNET_PQ_make_prepare ("do_commit",
@@ -2165,6 +2178,7 @@ postgres_insert_withdraw_info (
     return qs;
   }
 
+#if 0
   /* update reserve balance */
   reserve.pub = collectable->reserve_pub;
   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
@@ -2189,7 +2203,7 @@ postgres_insert_withdraw_info (
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Withdrawal from reserve `%s' refused due to balance mismatch. 
Retrying.\n",
                 TALER_B2S (&collectable->reserve_pub));
-    return GNUNET_DB_STATUS_SOFT_ERROR;
+    return GNUNET_DB_STATUS_SOFT_ERROR; // FIXME: really soft error? would 
retry help!?
   }
   expiry = GNUNET_TIME_absolute_add (now,
                                      pg->legal_reserve_expiration_time);
@@ -2205,6 +2219,30 @@ postgres_insert_withdraw_info (
     GNUNET_break (0);
     qs = GNUNET_DB_STATUS_HARD_ERROR;
   }
+#else
+  {
+    struct GNUNET_PQ_QueryParam params[] = {
+      GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_pub),
+      TALER_PQ_query_param_absolute_time (&expiry),
+      TALER_PQ_query_param_amount (&collectable->amount_with_fee),
+      GNUNET_PQ_query_param_end
+    };
+
+    expiry = GNUNET_TIME_absolute_add (now,
+                                       pg->legal_reserve_expiration_time);
+    qs = GNUNET_PQ_eval_prepared_non_select (session->conn,
+                                             "reserve_reduce",
+                                             params);
+    if (0 == qs)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Withdrawal from reserve `%s' refused due to balance 
mismatch.\n",
+                  TALER_B2S (&collectable->reserve_pub));
+      return GNUNET_DB_STATUS_HARD_ERROR;
+    }
+  }
+
+#endif
   return qs;
 }
 
diff --git a/src/testing/test_bank_api.c b/src/testing/test_bank_api.c
index 3e34974b..8e788493 100644
--- a/src/testing/test_bank_api.c
+++ b/src/testing/test_bank_api.c
@@ -197,9 +197,9 @@ main (int argc,
       return 77;
     }
 
-    if (NULL == (bankd = TALER_TESTING_run_bank (CONFIG_FILE_PYBANK,
-                                                 bc.exchange_auth.
-                                                 wire_gateway_url)))
+    if (NULL == (bankd = TALER_TESTING_run_bank (
+                   CONFIG_FILE_PYBANK,
+                   bc.exchange_auth.wire_gateway_url)))
     {
       GNUNET_break (0);
       return 77;
diff --git a/src/testing/test_bank_api_twisted.c 
b/src/testing/test_bank_api_twisted.c
index d17c3c81..b3e861e5 100644
--- a/src/testing/test_bank_api_twisted.c
+++ b/src/testing/test_bank_api_twisted.c
@@ -174,8 +174,8 @@ main (int argc,
   else
     cfgfilename = CONFIG_FILE_PYBANK;
 
-  if (NULL == (twister_url = TALER_TWISTER_prepare_twister
-                               (cfgfilename)))
+  if (NULL == (twister_url = TALER_TWISTER_prepare_twister (
+                 cfgfilename)))
   {
     GNUNET_break (0);
     return 77;
@@ -189,7 +189,6 @@ main (int argc,
     GNUNET_free (twister_url);
     return 77;
   }
-
   if (GNUNET_YES == with_fakebank)
   {
     TALER_LOG_DEBUG ("Running against the Fakebank.\n");
@@ -217,9 +216,9 @@ main (int argc,
       return 77;
     }
 
-    if (NULL == (bankd = TALER_TESTING_run_bank (cfgfilename,
-                                                 bc.exchange_auth.
-                                                 wire_gateway_url)))
+    if (NULL == (bankd = TALER_TESTING_run_bank (
+                   cfgfilename,
+                   bc.exchange_auth.wire_gateway_url)))
     {
       GNUNET_break (0);
       GNUNET_free (twister_url);
@@ -227,6 +226,7 @@ main (int argc,
     }
   }
 
+  sleep (5);
   ret = GNUNET_CONFIGURATION_parse_and_run (cfgfilename,
                                             &setup_with_cfg,
                                             NULL);
diff --git a/src/testing/testing_api_cmd_bank_transfer.c 
b/src/testing/testing_api_cmd_bank_transfer.c
index 7e7174b2..36d5e891 100644
--- a/src/testing/testing_api_cmd_bank_transfer.c
+++ b/src/testing/testing_api_cmd_bank_transfer.c
@@ -209,7 +209,7 @@ confirmation_cb (void *cls,
     }
     GNUNET_break (0);
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Fakebank returned HTTP status %u/%d\n",
+                "Bank returned HTTP status %u/%d\n",
                 http_status,
                 (int) ec);
     TALER_TESTING_interpreter_fail (is);
@@ -252,8 +252,8 @@ transfer_run (void *cls,
                                &buf_size);
   fts->is = is;
   fts->weh
-    = TALER_BANK_transfer
-        (TALER_TESTING_interpreter_get_context (is),
+    = TALER_BANK_transfer (
+        TALER_TESTING_interpreter_get_context (is),
         &fts->auth,
         buf,
         buf_size,
diff --git a/src/testing/testing_api_twister_helpers.c 
b/src/testing/testing_api_twister_helpers.c
index 5f8663d4..935d8bcc 100644
--- a/src/testing/testing_api_twister_helpers.c
+++ b/src/testing/testing_api_twister_helpers.c
@@ -44,13 +44,16 @@ TALER_TWISTER_prepare_twister (const char *config_filename)
 
   cfg = GNUNET_CONFIGURATION_create ();
 
-  if (GNUNET_OK != GNUNET_CONFIGURATION_load
-        (cfg, config_filename))
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_load (cfg,
+                                 config_filename))
     TWISTER_FAIL ();
 
-  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number
-        (cfg, "twister",
-        "HTTP_PORT", &port))
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_number (cfg,
+                                             "twister",
+                                             "HTTP_PORT",
+                                             &port))
   {
     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
                                "twister",
@@ -61,8 +64,9 @@ TALER_TWISTER_prepare_twister (const char *config_filename)
 
   GNUNET_CONFIGURATION_destroy (cfg);
 
-  if (GNUNET_OK != GNUNET_NETWORK_test_port_free
-        (IPPROTO_TCP, (uint16_t) port))
+  if (GNUNET_OK !=
+      GNUNET_NETWORK_test_port_free (IPPROTO_TCP,
+                                     (uint16_t) port))
   {
     fprintf (stderr,
              "Required port %llu not available, skipping.\n",
@@ -119,8 +123,10 @@ TALER_TWISTER_run_twister (const char *config_filename)
   }
 
 
-  if (GNUNET_SYSERR == GNUNET_OS_process_wait_status
-        (client_proc, &type, &code))
+  if (GNUNET_SYSERR ==
+      GNUNET_OS_process_wait_status (client_proc,
+                                     &type,
+                                     &code))
   {
     GNUNET_OS_process_destroy (client_proc);
     GNUNET_OS_process_kill (proc, SIGTERM);
@@ -131,7 +137,8 @@ TALER_TWISTER_run_twister (const char *config_filename)
   if ( (type == GNUNET_OS_PROCESS_EXITED) &&
        (0 != code) )
   {
-    fprintf (stderr, "Failed to check twister works.\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Failed to check twister works.\n");
     GNUNET_OS_process_destroy (client_proc);
     GNUNET_OS_process_kill (proc, SIGTERM);
     GNUNET_OS_process_wait (proc);
@@ -141,8 +148,8 @@ TALER_TWISTER_run_twister (const char *config_filename)
   if ( (type != GNUNET_OS_PROCESS_EXITED) ||
        (0 != code) )
   {
-    fprintf (stderr, "Unexpected error running"
-             " `taler-twister'!\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected error running `taler-twister'!\n");
     GNUNET_OS_process_destroy (client_proc);
     GNUNET_OS_process_kill (proc, SIGTERM);
     GNUNET_OS_process_wait (proc);

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]