summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-06-19 14:52:13 +0200
committerChristian Grothoff <christian@grothoff.org>2021-06-19 14:52:13 +0200
commit8c0492be71f9a80bdfac242b45bab6dc657834b0 (patch)
tree3cc45b174b971234abb1acb8d17e5955077d71ab
parentfdf095c6efae2e6c59712996ca380bc499229370 (diff)
downloadexchange-8c0492be71f9a80bdfac242b45bab6dc657834b0.tar.gz
exchange-8c0492be71f9a80bdfac242b45bab6dc657834b0.tar.bz2
exchange-8c0492be71f9a80bdfac242b45bab6dc657834b0.zip
misc fakebank fixes
-rw-r--r--src/bank-lib/fakebank.c108
-rw-r--r--src/benchmark/benchmark.conf5
-rw-r--r--src/benchmark/taler-bank-benchmark.c89
-rw-r--r--src/include/taler_fakebank_lib.h45
4 files changed, 132 insertions, 115 deletions
diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c
index 978253b5..06470210 100644
--- a/src/bank-lib/fakebank.c
+++ b/src/bank-lib/fakebank.c
@@ -576,14 +576,17 @@ clean_transaction (struct TALER_FAKEBANK_Handle *h,
t);
GNUNET_assert (0 ==
pthread_mutex_unlock (&ca->lock));
- GNUNET_assert (0 ==
- pthread_mutex_lock (&h->uuid_map_lock));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (h->uuid_map,
- &t->request_uid,
- t));
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->uuid_map_lock));
+ if (T_DEBIT == t->type)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->uuid_map_lock));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (h->uuid_map,
+ &t->request_uid,
+ t));
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->uuid_map_lock));
+ }
t->debit_account = NULL;
t->credit_account = NULL;
}
@@ -671,8 +674,22 @@ post_transaction (struct Transaction *t)
}
-int
-TALER_FAKEBANK_make_transfer (
+/**
+ * Tell the fakebank to create another wire transfer *from* an exchange.
+ *
+ * @param h fake bank handle
+ * @param debit_account account to debit
+ * @param credit_account account to credit
+ * @param amount amount to transfer
+ * @param subject wire transfer subject to use
+ * @param exchange_base_url exchange URL
+ * @param request_uid unique number to make the request unique, or NULL to create one
+ * @param[out] ret_row_id pointer to store the row ID of this transaction
+ * @return #GNUNET_YES if the transfer was successful,
+ * #GNUNET_SYSERR if the request_uid was reused for a different transfer
+ */
+static int
+make_transfer (
struct TALER_FAKEBANK_Handle *h,
const char *debit_account,
const char *credit_account,
@@ -782,13 +799,27 @@ TALER_FAKEBANK_make_transfer (
}
-uint64_t
-TALER_FAKEBANK_make_admin_transfer (
+/**
+ * Tell the fakebank to create another wire transfer *to* an exchange.
+ *
+ * @param h fake bank handle
+ * @param debit_account account to debit
+ * @param credit_account account to credit
+ * @param amount amount to transfer
+ * @param reserve_pub reserve public key to use in subject
+ * @param[out] serial_id of the transfer
+ * @param[out] timestamp when was the transfer made
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+make_admin_transfer (
struct TALER_FAKEBANK_Handle *h,
const char *debit_account,
const char *credit_account,
const struct TALER_Amount *amount,
- const struct TALER_ReservePublicKeyP *reserve_pub)
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t *row_id,
+ struct GNUNET_TIME_Absolute *timestamp)
{
struct Transaction *t;
const struct GNUNET_PeerIdentity *pid;
@@ -824,11 +855,13 @@ TALER_FAKEBANK_make_admin_transfer (
{
/* duplicate reserve public key not allowed */
GNUNET_break (0);
- return 0;
+ return GNUNET_NO;
}
ret = __sync_fetch_and_add (&h->serial_counter,
1);
+ if (NULL != row_id)
+ *row_id = ret;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Making transfer from %s to %s over %s and subject %s at row %llu\n",
debit_account,
@@ -847,7 +880,9 @@ TALER_FAKEBANK_make_admin_transfer (
t->amount = *amount;
t->row_id = ret;
t->date = GNUNET_TIME_absolute_get ();
- GNUNET_TIME_round_abs (&t->date);
+ (void) GNUNET_TIME_round_abs (&t->date);
+ if (NULL != timestamp)
+ *timestamp = t->date;
t->type = T_CREDIT;
t->subject.credit.reserve_pub = *reserve_pub;
post_transaction (t);
@@ -863,7 +898,7 @@ TALER_FAKEBANK_make_admin_transfer (
pthread_mutex_unlock (&h->rpubs_lock));
GNUNET_assert (0 ==
pthread_mutex_unlock (&t->lock));
- return ret;
+ return GNUNET_OK;
}
@@ -992,6 +1027,8 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
enum GNUNET_JSON_PostResult pr;
json_t *json;
uint64_t row_id;
+ struct GNUNET_TIME_Absolute timestamp;
+ enum GNUNET_GenericReturnValue ret;
pr = GNUNET_JSON_post_parser (REQUEST_BUFFER_MAX,
connection,
@@ -1059,13 +1096,15 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
account,
TALER_B2S (&reserve_pub),
TALER_amount2s (&amount));
- row_id = TALER_FAKEBANK_make_admin_transfer (h,
- debit,
- account,
- &amount,
- &reserve_pub);
+ ret = make_admin_transfer (h,
+ debit,
+ account,
+ &amount,
+ &reserve_pub,
+ &row_id,
+ &timestamp);
GNUNET_free (debit);
- if (0 == row_id)
+ if (GNUNET_OK != ret)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Reserve public key not unique\n");
@@ -1078,8 +1117,6 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
}
json_decref (json);
- // FIXME: timestamp without lock is unclean,
- // return as part of TALER_FAKEBANK_make_admin_transfer instead!
/* Finally build response object */
return TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK,
@@ -1087,8 +1124,7 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
"row_id",
(json_int_t) row_id,
"timestamp",
- GNUNET_JSON_from_time_abs (
- h->transactions[row_id].date));
+ GNUNET_JSON_from_time_abs (timestamp));
}
@@ -1172,14 +1208,14 @@ handle_transfer (struct TALER_FAKEBANK_Handle *h,
int ret;
credit = TALER_xtalerbank_account_from_payto (credit_account);
- ret = TALER_FAKEBANK_make_transfer (h,
- account,
- credit,
- &amount,
- &wtid,
- base_url,
- &uuid,
- &row_id);
+ ret = make_transfer (h,
+ account,
+ credit,
+ &amount,
+ &wtid,
+ base_url,
+ &uuid,
+ &row_id);
if (GNUNET_OK != ret)
{
MHD_RESULT res;
@@ -1393,7 +1429,7 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h,
}
else
{
- struct Transaction *t = &h->transactions[ha.start_idx];
+ struct Transaction *t = &h->transactions[ha.start_idx % h->ram_limit];
GNUNET_assert (0 ==
pthread_mutex_lock (&t->lock));
@@ -1508,7 +1544,7 @@ handle_credit_history (struct TALER_FAKEBANK_Handle *h,
}
else
{
- struct Transaction *t = &h->transactions[ha.start_idx];
+ struct Transaction *t = &h->transactions[ha.start_idx % h->ram_limit];
GNUNET_assert (0 ==
pthread_mutex_lock (&t->lock));
diff --git a/src/benchmark/benchmark.conf b/src/benchmark/benchmark.conf
index 66dfeeca..a5fe4340 100644
--- a/src/benchmark/benchmark.conf
+++ b/src/benchmark/benchmark.conf
@@ -28,6 +28,11 @@ DB = postgres
# exchange (or the twister) is actually listening.
base_url = "http://localhost:8081/"
+WIREWATCH_IDLE_SLEEP_INTERVAL = 5 ms
+
+[exchange-offline]
+MASTER_PRIV_FILE = ${TALER_DATA_HOME}/exchange/offline-keys/master.priv
+
[auditor]
BASE_URL = "http://localhost:8083/"
diff --git a/src/benchmark/taler-bank-benchmark.c b/src/benchmark/taler-bank-benchmark.c
index ad46f86d..f3ec074c 100644
--- a/src/benchmark/taler-bank-benchmark.c
+++ b/src/benchmark/taler-bank-benchmark.c
@@ -22,6 +22,10 @@
* @author Marcello Stanisci
* @author Christian Grothoff
*/
+// TODO:
+// - use more than one 'client' bank account
+// - also add taler-exchange-transfer to simulate outgoing payments
+// - improve reporting logic (currently not working)
#include "platform.h"
#include <gnunet/gnunet_util_lib.h>
#include <microhttpd.h>
@@ -250,42 +254,39 @@ static void
run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
- struct TALER_Amount total_reserve_amount;
- char *user_payto_uri;
+ char *total_reserve_amount;
(void) cls;
// FIXME: vary user accounts more...
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "benchmark",
- "USER_PAYTO_URI",
- &user_payto_uri));
all_commands = GNUNET_new_array (howmany_reserves
+ 1 /* stat CMD */
+ 1 /* End CMD */,
struct TALER_TESTING_Command);
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_get_zero (currency,
- &total_reserve_amount));
- total_reserve_amount.value = 5;
+ GNUNET_asprintf (&total_reserve_amount,
+ "%s:5",
+ currency);
for (unsigned int j = 0; j < howmany_reserves; j++)
{
- char create_reserve_label[32];
-
- GNUNET_snprintf (create_reserve_label,
- sizeof (create_reserve_label),
+ char *create_reserve_label;
+ char *user_payto_uri;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "benchmark",
+ "USER_PAYTO_URI",
+ &user_payto_uri));
+ GNUNET_asprintf (&create_reserve_label,
"createreserve-%u",
j);
all_commands[j]
= TALER_TESTING_cmd_admin_add_incoming_retry (
TALER_TESTING_cmd_admin_add_incoming (add_label (
create_reserve_label),
- TALER_amount2s (
- &total_reserve_amount),
+ total_reserve_amount,
&exchange_bank_account,
- user_payto_uri));
+ add_label (user_payto_uri)));
}
- GNUNET_free (user_payto_uri);
+ GNUNET_free (total_reserve_amount);
all_commands[howmany_reserves]
= TALER_TESTING_cmd_stat (timings);
all_commands[howmany_reserves + 1]
@@ -454,6 +455,20 @@ parallel_benchmark (void)
return GNUNET_SYSERR;
}
+ {
+ struct GNUNET_OS_Process *dbinit;
+
+ dbinit = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
+ NULL, NULL, NULL,
+ "taler-exchange-dbinit",
+ "taler-exchange-dbinit",
+ "-c", cfg_filename,
+ "-r",
+ NULL);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_OS_process_wait (dbinit));
+ GNUNET_OS_process_destroy (dbinit);
+ }
/* start exchange wirewatch */
wirewatch = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
NULL, NULL, NULL,
@@ -461,21 +476,27 @@ parallel_benchmark (void)
"taler-exchange-wirewatch",
"-c", cfg_filename,
NULL);
- if (-1 != fakebank)
- {
- int wstatus;
-
- kill (fakebank,
- SIGTERM);
- waitpid (fakebank,
- &wstatus,
- 0);
- }
- if (NULL != bankd)
+ if (NULL == wirewatch)
{
- GNUNET_OS_process_kill (bankd,
- SIGTERM);
- GNUNET_OS_process_destroy (bankd);
+ if (-1 != fakebank)
+ {
+ int wstatus;
+
+ kill (fakebank,
+ SIGTERM);
+ waitpid (fakebank,
+ &wstatus,
+ 0);
+ fakebank = -1;
+ }
+ if (NULL != bankd)
+ {
+ GNUNET_OS_process_kill (bankd,
+ SIGTERM);
+ GNUNET_OS_process_destroy (bankd);
+ bankd = NULL;
+ }
+ return GNUNET_SYSERR;
}
}
@@ -694,7 +715,7 @@ main (int argc,
howmany_reserves,
howmany_clients,
GNUNET_STRINGS_relative_time_to_string (duration,
- GNUNET_NO));
+ GNUNET_YES));
fprintf (stdout,
"RAW: %04u %04u %16llu\n",
howmany_reserves,
diff --git a/src/include/taler_fakebank_lib.h b/src/include/taler_fakebank_lib.h
index 60283e7f..864345f3 100644
--- a/src/include/taler_fakebank_lib.h
+++ b/src/include/taler_fakebank_lib.h
@@ -94,51 +94,6 @@ TALER_FAKEBANK_check_empty (struct TALER_FAKEBANK_Handle *h);
/**
- * Tell the fakebank to create another wire transfer *from* an exchange.
- *
- * @param h fake bank handle
- * @param debit_account account to debit
- * @param credit_account account to credit
- * @param amount amount to transfer
- * @param subject wire transfer subject to use
- * @param exchange_base_url exchange URL
- * @param request_uid unique number to make the request unique, or NULL to create one
- * @param[out] ret_row_id pointer to store the row ID of this transaction
- * @return #GNUNET_YES if the transfer was successful,
- * #GNUNET_SYSERR if the request_uid was reused for a different transfer
- */
-int
-TALER_FAKEBANK_make_transfer (
- struct TALER_FAKEBANK_Handle *h,
- const char *debit_account,
- const char *credit_account,
- const struct TALER_Amount *amount,
- const struct TALER_WireTransferIdentifierRawP *subject,
- const char *exchange_base_url,
- const struct GNUNET_HashCode *request_uid,
- uint64_t *ret_row_id);
-
-
-/**
- * Tell the fakebank to create another wire transfer *to* an exchange.
- *
- * @param h fake bank handle
- * @param debit_account account to debit
- * @param credit_account account to credit
- * @param amount amount to transfer
- * @param reserve_pub reserve public key to use in subject
- * @return serial_id of the transfer, 0 on error
- */
-uint64_t
-TALER_FAKEBANK_make_admin_transfer (
- struct TALER_FAKEBANK_Handle *h,
- const char *debit_account,
- const char *credit_account,
- const struct TALER_Amount *amount,
- const struct TALER_ReservePublicKeyP *reserve_pub);
-
-
-/**
* Check that the @a want_amount was transferred from the @a
* want_debit to the @a want_credit account. If so, set the @a subject
* to the transfer identifier and remove the transaction from the