aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-23 11:55:10 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-23 11:55:10 +0200
commit727eccbe644aede46ef5eafc11964992960457e0 (patch)
treec97d05c90f929e0ddc15a0320636d68f079cb7f3
parenta039bf4d81b4e2c01da6d21a7e36f209853f0c3f (diff)
downloadexchange-727eccbe644aede46ef5eafc11964992960457e0.tar.gz
exchange-727eccbe644aede46ef5eafc11964992960457e0.zip
add invariant checks for #6214
-rw-r--r--src/exchangedb/exchangedb_transactions.c11
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c7
2 files changed, 14 insertions, 4 deletions
diff --git a/src/exchangedb/exchangedb_transactions.c b/src/exchangedb/exchangedb_transactions.c
index 7fe65d523..93e4104e6 100644
--- a/src/exchangedb/exchangedb_transactions.c
+++ b/src/exchangedb/exchangedb_transactions.c
@@ -41,12 +41,14 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals (
41 struct TALER_Amount spent = *off; 41 struct TALER_Amount spent = *off;
42 struct TALER_Amount refunded; 42 struct TALER_Amount refunded;
43 struct TALER_Amount deposit_fee; 43 struct TALER_Amount deposit_fee;
44 int have_refund; 44 bool have_refund;
45 bool have_deposit;
45 46
46 GNUNET_assert (GNUNET_OK == 47 GNUNET_assert (GNUNET_OK ==
47 TALER_amount_get_zero (spent.currency, 48 TALER_amount_get_zero (spent.currency,
48 &refunded)); 49 &refunded));
49 have_refund = GNUNET_NO; 50 have_refund = false;
51 have_deposit = false;
50 for (struct TALER_EXCHANGEDB_TransactionList *pos = tl; 52 for (struct TALER_EXCHANGEDB_TransactionList *pos = tl;
51 NULL != pos; 53 NULL != pos;
52 pos = pos->next) 54 pos = pos->next)
@@ -55,6 +57,7 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals (
55 { 57 {
56 case TALER_EXCHANGEDB_TT_DEPOSIT: 58 case TALER_EXCHANGEDB_TT_DEPOSIT:
57 /* spent += pos->amount_with_fee */ 59 /* spent += pos->amount_with_fee */
60 have_deposit = true;
58 if (0 > 61 if (0 >
59 TALER_amount_add (&spent, 62 TALER_amount_add (&spent,
60 &spent, 63 &spent,
@@ -94,7 +97,7 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals (
94 GNUNET_break (0); 97 GNUNET_break (0);
95 return GNUNET_SYSERR; 98 return GNUNET_SYSERR;
96 } 99 }
97 have_refund = GNUNET_YES; 100 have_refund = true;
98 break; 101 break;
99 case TALER_EXCHANGEDB_TT_OLD_COIN_RECOUP: 102 case TALER_EXCHANGEDB_TT_OLD_COIN_RECOUP:
100 /* refunded += pos->value */ 103 /* refunded += pos->value */
@@ -152,7 +155,7 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals (
152 GNUNET_break (0); 155 GNUNET_break (0);
153 return GNUNET_SYSERR; 156 return GNUNET_SYSERR;
154 } 157 }
155 158 GNUNET_break (have_deposit);
156 *ret = spent; 159 *ret = spent;
157 return GNUNET_OK; 160 return GNUNET_OK;
158} 161}
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 4f57f32fe..e517d069b 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -4004,6 +4004,11 @@ struct CoinHistoryContext
4004 * Set to 'true' if the transaction failed. 4004 * Set to 'true' if the transaction failed.
4005 */ 4005 */
4006 bool failed; 4006 bool failed;
4007
4008 /**
4009 * Set to 'true' if we found a deposit (for invariant check).
4010 */
4011 bool have_deposit;
4007}; 4012};
4008 4013
4009 4014
@@ -4029,6 +4034,7 @@ add_coin_deposit (void *cls,
4029 struct TALER_EXCHANGEDB_TransactionList *tl; 4034 struct TALER_EXCHANGEDB_TransactionList *tl;
4030 uint64_t serial_id; 4035 uint64_t serial_id;
4031 4036
4037 chc->have_deposit = true;
4032 deposit = GNUNET_new (struct TALER_EXCHANGEDB_DepositListEntry); 4038 deposit = GNUNET_new (struct TALER_EXCHANGEDB_DepositListEntry);
4033 { 4039 {
4034 struct GNUNET_PQ_ResultSpec rs[] = { 4040 struct GNUNET_PQ_ResultSpec rs[] = {
@@ -4506,6 +4512,7 @@ postgres_get_coin_transactions (
4506 *tlp = chc.head; 4512 *tlp = chc.head;
4507 if (NULL == chc.head) 4513 if (NULL == chc.head)
4508 return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; 4514 return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
4515 GNUNET_break (chc.have_deposit);
4509 return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; 4516 return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
4510} 4517}
4511 4518