aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-15 20:09:09 +0200
committerChristian Grothoff <christian@grothoff.org>2016-06-15 22:55:05 +0200
commit8c7406cb42c6c9cc8967ab8cbfd901809c8b3c2e (patch)
tree56bc904350632dbf3f33860e57ace138af6101f5 /src
parentc38a7c5518418caefd1c6725a29cfa577d40e7a4 (diff)
check refresh amounts add up correctly, fix linker issue
Diffstat (limited to 'src')
-rw-r--r--src/bank-lib/Makefile.am1
-rw-r--r--src/benchmark/taler-exchange-benchmark.c23
-rw-r--r--src/exchange-lib/exchange_api_refresh.c35
3 files changed, 52 insertions, 7 deletions
diff --git a/src/bank-lib/Makefile.am b/src/bank-lib/Makefile.am
index 289135023..a87a2c467 100644
--- a/src/bank-lib/Makefile.am
+++ b/src/bank-lib/Makefile.am
@@ -38,6 +38,7 @@ libtalerfakebank_la_LIBADD = \
-lgnunetjson \
-lgnunetutil \
-ljansson \
+ -lmicrohttpd \
$(XLIB)
diff --git a/src/benchmark/taler-exchange-benchmark.c b/src/benchmark/taler-exchange-benchmark.c
index 4b50033da..66b0c6f5e 100644
--- a/src/benchmark/taler-exchange-benchmark.c
+++ b/src/benchmark/taler-exchange-benchmark.c
@@ -186,7 +186,7 @@ struct Coin
struct TALER_EXCHANGE_DepositHandle *dh;
/**
- * Array of denominations expected to get from melt
+ * Array of denominations we expect to get from melt.
*/
struct TALER_Amount *denoms;
@@ -691,14 +691,17 @@ refresh_coin (struct Coin *coin)
struct TALER_EXCHANGE_DenomPublicKey *dpks = NULL;
const struct TALER_EXCHANGE_DenomPublicKey *curr_dpk;
struct TALER_Amount curr;
+ struct TALER_Amount left;
unsigned int ndenoms = 0;
unsigned int ndenoms2 = 0;
unsigned int off;
-
+
+ GNUNET_break (NULL == coin->denoms);
TALER_amount_get_zero (currency, &curr);
+ left = coin->left;
off = 0;
while (0 != TALER_amount_cmp (&curr,
- &coin->left))
+ &left))
{
if (off >= refresh_pk_len)
{
@@ -707,7 +710,7 @@ refresh_coin (struct Coin *coin)
break;
}
curr_dpk = &refresh_pk[off];
- while (-1 != TALER_amount_cmp (&coin->left,
+ while (-1 != TALER_amount_cmp (&left,
&curr_dpk->value))
{
GNUNET_array_append (denoms,
@@ -716,9 +719,10 @@ refresh_coin (struct Coin *coin)
GNUNET_array_append (dpks,
ndenoms2,
*curr_dpk);
- TALER_amount_subtract (&coin->left,
- &coin->left,
- &curr_dpk->value);
+ GNUNET_assert (GNUNET_SYSERR !=
+ TALER_amount_subtract (&left,
+ &left,
+ &curr_dpk->value));
}
off++;
}
@@ -1585,6 +1589,11 @@ main (int argc,
GNUNET_assert (GNUNET_SYSERR != ret);
if (GNUNET_NO == ret)
return 0;
+ if ( (0 != num_iterations) &&
+ (WARM_THRESHOLD >= num_iterations) )
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Number of iterations below WARM_THRESHOLD of %llu\n",
+ WARM_THRESHOLD);
if ( (NULL == exchange_uri) ||
(0 == strlen (exchange_uri) ))
{
diff --git a/src/exchange-lib/exchange_api_refresh.c b/src/exchange-lib/exchange_api_refresh.c
index 9a9c6b7eb..e32f73e21 100644
--- a/src/exchange-lib/exchange_api_refresh.c
+++ b/src/exchange-lib/exchange_api_refresh.c
@@ -764,6 +764,7 @@ TALER_EXCHANGE_refresh_prepare (const struct TALER_CoinSpendPrivateKeyP *melt_pr
unsigned int i;
unsigned int j;
struct GNUNET_HashContext *hash_context;
+ struct TALER_Amount total;
/* build up melt data structure */
for (i=0;i<TALER_CNC_KAPPA;i++)
@@ -799,10 +800,44 @@ TALER_EXCHANGE_refresh_prepare (const struct TALER_CoinSpendPrivateKeyP *melt_pr
md.fresh_coins[i] = GNUNET_new_array (fresh_pks_len,
struct FreshCoinP);
for (j=0;j<fresh_pks_len;j++)
+ {
setup_fresh_coin (&md.fresh_coins[i][j],
&fresh_pks[j]);
+ }
}
+ /* verify that melt_amount is above total cost */
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_get_zero (melt_amount->currency,
+ &total));
+ for (j=0;j<fresh_pks_len;j++)
+ {
+ if ( (GNUNET_OK !=
+ TALER_amount_add (&total,
+ &total,
+ &fresh_pks[j].value)) ||
+ (GNUNET_OK !=
+ TALER_amount_add (&total,
+ &total,
+ &fresh_pks[j].fee_withdraw)) )
+ {
+ GNUNET_break (0);
+ free_melt_data (&md);
+ return NULL;
+ }
+ }
+ if (1 ==
+ TALER_amount_cmp (&total,
+ melt_amount) )
+ {
+ /* Eh, this operation is more expensive than the
+ @a melt_amount. This is not OK. */
+ GNUNET_break (0);
+ free_melt_data (&md);
+ return NULL;
+ }
+
+
/* now compute melt session hash */
hash_context = GNUNET_CRYPTO_hash_context_start ();
for (i=0;i<fresh_pks_len;i++)