summaryrefslogtreecommitdiff
path: root/src/benchmark
diff options
context:
space:
mode:
Diffstat (limited to 'src/benchmark')
-rw-r--r--src/benchmark/taler-exchange-benchmark.c137
1 files changed, 80 insertions, 57 deletions
diff --git a/src/benchmark/taler-exchange-benchmark.c b/src/benchmark/taler-exchange-benchmark.c
index c47b352b8..93df0ae0d 100644
--- a/src/benchmark/taler-exchange-benchmark.c
+++ b/src/benchmark/taler-exchange-benchmark.c
@@ -52,12 +52,11 @@ static unsigned int nreserves;
/**
* How many coins are in `coins` array. This is needed
- * as the number of coins is not always nreserves * COINS_PER_RESERVE
+ * as the number of coins is not always nreserves * COINS_PER_RESERVE
* due to refresh operations
*/
unsigned int ncoins;
-
/**
* Bank details of who creates reserves
*/
@@ -87,6 +86,11 @@ struct RefreshRevealCls {
* Which coin in the list are we melting
*/
unsigned int coin_index;
+
+ /**
+ * Array of denominations expected to get from melt
+ */
+ struct TALER_Amount *denoms;
};
/**
@@ -168,6 +172,12 @@ struct Coin {
unsigned int refresh;
/**
+ * If the coin has to be refreshed, this value indicates
+ * how much is left on this coin
+ */
+ struct TALER_Amount left;
+
+ /**
* Refresh melt handle
*/
struct TALER_EXCHANGE_RefreshMeltHandle *rmh;
@@ -179,7 +189,6 @@ struct Coin {
};
-
/**
* Handle to the exchange's process
*/
@@ -216,16 +225,6 @@ static struct Reserve *reserves;
static struct Coin *coins;
/**
- * Indices of spent coins
- */
-static unsigned int *spent_coins;
-
-/**
- * Current number of spent coins
- */
-static unsigned int spent_coins_size = 0;
-
-/**
* Transaction id counter, used in /deposit's
*/
static unsigned int transaction_id = 0;
@@ -412,29 +411,31 @@ reveal_cb (void *cls,
return;
}
else
+ {
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Coin #%d revealed!\n",
rrcls->coin_index);
+ coins[rrcls->coin_index].left.value = 0;
+ }
+
keys = TALER_EXCHANGE_get_keys (exchange);
for (i=0; i<num_coins; i++)
{
struct Coin fresh_coin;
- struct TALER_Amount amount;
- char *refresh_denom;
-
- GNUNET_asprintf (&refresh_denom,
- "%s:%s",
- currency,
- refresh_denoms[i]);
+ char *revealed_str;
+
+ revealed_str = TALER_amount_to_string (&rrcls->denoms[i]);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "revealing %s "
+ "# of coins after refresh: %d\n",
+ revealed_str,
+ ncoins);
+
+ GNUNET_free (revealed_str);
fresh_coin.reserve_index = coins[rrcls->coin_index].reserve_index;
- TALER_string_to_amount (refresh_denom, &amount);
- GNUNET_free (refresh_denom);
- fresh_coin.pk = find_pk (keys, &amount);
+ fresh_coin.pk = find_pk (keys, &rrcls->denoms[i]);
fresh_coin.sig = sigs[i];
GNUNET_array_append (coins, ncoins, fresh_coin);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "# of coins after refresh: %d\n",
- ncoins);
}
GNUNET_free (rrcls);
}
@@ -457,8 +458,8 @@ melt_cb (void *cls,
const struct TALER_ExchangePublicKeyP *exchange_pub,
const json_t *full_response)
{
+ /* free'd in `reveal_cb` */
struct RefreshRevealCls *rrcls = cls;
- /* FIXME to be freed */
coins[rrcls->coin_index].rmh = NULL;
if (MHD_HTTP_OK != http_status)
@@ -467,12 +468,13 @@ melt_cb (void *cls,
fail ("Coin not correctly melted!\n");
return;
}
+
coins[rrcls->coin_index].rrh
= TALER_EXCHANGE_refresh_reveal (exchange,
rrcls->blob_size,
rrcls->blob,
noreveal_index,
- reveal_cb,
+ &reveal_cb,
rrcls);
}
@@ -519,30 +521,52 @@ deposit_cb (void *cls,
fail ("At least one coin has not been deposited, status: %d\n");
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Coin #%d correctly spent!\n", coin_index);
- GNUNET_array_append (spent_coins, spent_coins_size, coin_index);
- spent_coins_size++;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Coin #%d correctly spent!\n",
+ coin_index);
if (GNUNET_YES == coins[coin_index].refresh)
{
- struct TALER_Amount melt_amount;
struct RefreshRevealCls *rrcls;
-
- TALER_amount_get_zero (currency, &melt_amount);
- melt_amount.value = 7;
char *blob;
size_t blob_size;
-
+ const struct TALER_EXCHANGE_Keys *keys;
+ struct TALER_Amount *denoms = NULL;
+ struct TALER_EXCHANGE_DenomPublicKey *dpks = NULL;
+ const struct TALER_EXCHANGE_DenomPublicKey *curr_dpk;
+ struct TALER_Amount curr;
+ unsigned int ndenoms = 0;
+ unsigned int ndenoms2 = 0;
+ unsigned long long acc_value;
+
+ TALER_amount_get_zero (currency, &curr);
+ curr.value = COIN_VALUE >> 1;
+ acc_value = 0;
+
+ keys = TALER_EXCHANGE_get_keys (exchange);
+ for (; curr.value > 0; curr.value = curr.value >> 1)
+ {
+ if (acc_value + curr.value <= coins[coin_index].left.value)
+ {
+ GNUNET_array_append (denoms, ndenoms, curr);
+ GNUNET_assert (NULL != (curr_dpk = find_pk (keys, &curr)));
+ GNUNET_array_append (dpks, ndenoms2, *curr_dpk);
+ acc_value += curr.value;
+ }
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "# of coins to get in melt: %d\n",
+ ndenoms2);
blob = TALER_EXCHANGE_refresh_prepare (&coins[coin_index].coin_priv,
- &melt_amount,
+ &coins[coin_index].left,
&coins[coin_index].sig,
coins[coin_index].pk,
GNUNET_YES,
- refresh_pk_len,
- refresh_pk,
+ ndenoms2,
+ dpks,
&blob_size);
if (NULL == blob)
{
- fail ("Failed to prepare refresh");
+ fail ("Failed to prepare refresh\n");
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -550,14 +574,11 @@ deposit_cb (void *cls,
(unsigned int) blob_size);
refreshed_once = GNUNET_YES;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "# of coins to get in melt: %d\n",
- refresh_pk_len);
rrcls = GNUNET_new (struct RefreshRevealCls);
rrcls->blob = blob;
rrcls->blob_size = blob_size;
rrcls->coin_index = coin_index;
-
+ rrcls->denoms = denoms;
coins[coin_index].rmh = TALER_EXCHANGE_refresh_melt (exchange,
blob_size,
blob,
@@ -589,7 +610,8 @@ deposit_cb (void *cls,
/**
* Function called upon completion of our /reserve/withdraw request.
- * This is merely the function which spends withdrawn coins
+ * This is merely the function which spends withdrawn coins. For each
+ * spent coin, ti either refresh it or re-withdraw it.
*
* @param cls closure with the interpreter state
* @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request
@@ -613,7 +635,7 @@ reserve_withdraw_cb (void *cls,
fail ("At least one coin has not correctly been withdrawn\n");
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%d-th coin withdrawn\n",
coin_index);
coins[coin_index].sig.rsa_signature =
@@ -646,18 +668,20 @@ reserve_withdraw_cb (void *cls,
if (GNUNET_YES == eval_probability (REFRESH_PROBABILITY)
&& GNUNET_NO == refreshed_once)
{
+ /**
+ * Always spending 1 out of 8 KUDOS. To be improved by randomly
+ * picking the spent amount
+ */
struct TALER_Amount one;
TALER_amount_get_zero (currency, &one);
one.value = 1;
- /**
- * If the coin is going to be refreshed, only 1 unit
- * of currency will be spent, since 4 units are going
- * to be refreshed
- */
TALER_amount_subtract (&amount,
&one,
&coins[coin_index].pk->fee_deposit);
+ TALER_amount_subtract (&coins[coin_index].left,
+ &coins[coin_index].pk->value,
+ &one);
coins[coin_index].refresh = GNUNET_YES;
refreshed_once = GNUNET_YES;
}
@@ -826,6 +850,7 @@ benchmark_run (void *cls)
&reserve_pub.eddsa_pub);
reserves[i].aih = TALER_EXCHANGE_admin_add_incoming (exchange,
+ "http://localhost:18080/",
&reserve_pub,
&reserve_amount,
execution_date,
@@ -837,6 +862,9 @@ benchmark_run (void *cls)
json_decref (transfer_details);
}
json_decref (sender_details);
+ sender_details = NULL;
+ transfer_details = NULL;
+
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"benchmark_run() returns\n");
}
@@ -847,7 +875,7 @@ benchmark_run (void *cls)
* since that is the only amount refreshed so far by the benchmark
*
* @param NULL-terminated array of value.fraction pairs
- * @return GNUNET_OK if the array is correctly built, GNUNET_SYSERR
+ * @return #GNUNET_OK if the array is correctly built, #GNUNET_SYSERR
* otherwise
*/
static unsigned int
@@ -994,7 +1022,6 @@ do_shutdown (void *cls)
GNUNET_free_non_null (reserves);
GNUNET_free_non_null (coins);
- GNUNET_free_non_null (spent_coins);
GNUNET_free_non_null (currency);
if (NULL != exchange)
@@ -1085,10 +1112,6 @@ run (void *cls)
NULL);
GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_array_append (spent_coins,
- spent_coins_size,
- 1);
- spent_coins_size++;
reserves = NULL;
coins = NULL;
ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,