commit 40f20de4584f21989d9ba876d4cda5e9b75f823a
parent fd5b68841d14bf5f54d5596840ad7d322f8fe5f3
Author: Özgür Kesim <oec@codeblau.de>
Date: Fri, 4 Apr 2025 14:18:54 +0200
[auditor,exchange] cleanup of code and added debug statements
Diffstat:
4 files changed, 46 insertions(+), 35 deletions(-)
diff --git a/src/auditor/report-lib.c b/src/auditor/report-lib.c
@@ -85,16 +85,20 @@ static struct GNUNET_CONTAINER_MultiUuidmap *denominations_by_serial;
/**
* Helper to convert a serial/row id to a uuid for the lookup
- * in a uuid hash table
+ * in a uuid hash table.
+ *
+ * @param serial serial id of entry
+ * @param[out] uuid uuid to write
*/
-static struct GNUNET_Uuid
+static void
serial_to_uuid (
- uint64_t serial)
+ uint64_t serial,
+ struct GNUNET_Uuid *uuid)
{
- struct GNUNET_Uuid uuid;
- uuid.value[0] = serial;
- uuid.value[1] = serial >> 32;
- return uuid;
+ uuid->value[0] = serial;
+ uuid->value[1] = serial >> 32;
+ uuid->value[2] = 0;
+ uuid->value[3] = 0;
}
@@ -149,7 +153,7 @@ add_denomination (
&issue->denom_hash.hash,
i,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- uuid = serial_to_uuid (denom_serial);
+ serial_to_uuid (denom_serial, &uuid);
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multiuuidmap_put (denominations_by_serial,
&uuid,
@@ -246,7 +250,9 @@ TALER_ARL_get_denomination_info_by_serial (
const struct TALER_EXCHANGEDB_DenominationKeyInformation **issuep)
{
enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_Uuid uuid = serial_to_uuid (denom_serial);
+ struct GNUNET_Uuid uuid;
+
+ serial_to_uuid (denom_serial, &uuid);
if (NULL == denominations_by_serial)
{
diff --git a/src/auditor/taler-helper-auditor-coins.c b/src/auditor/taler-helper-auditor-coins.c
@@ -241,6 +241,7 @@ report_emergency_by_amount (
"Reporting emergency on denomination `%s' over loss of %s\n",
GNUNET_h2s (&issue->denom_hash.hash),
TALER_amount2s (loss));
+
qs = TALER_ARL_adb->insert_emergency (
TALER_ARL_adb->cls,
&emergency);
@@ -293,6 +294,13 @@ report_emergency_by_count (
.value = issue->value
};
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Reporting emergency on denomination `%s' with issued %lu vs known %lu over risk of %s\n",
+ GNUNET_h2s (&issue->denom_hash.hash),
+ num_issued,
+ num_known,
+ TALER_amount2s (risk));
+
qs = TALER_ARL_adb->insert_emergency_by_count (
TALER_ARL_adb->cls,
&emergenciesByCount);
@@ -870,7 +878,7 @@ sync_denomination (void *cls,
to auditor database for next iteration */
long long cnt;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Final balance for denomination `%s' is %s (%llu)\n",
GNUNET_h2s (denom_hash),
TALER_amount2s (&ds->dcd.denom_balance),
@@ -999,10 +1007,6 @@ withdraw_cb (void *cls,
const struct TALER_Amount *amount_with_fee)
{
struct CoinContext *cc = cls;
- struct DenominationSummary *ds;
- struct TALER_DenominationHashP dh;
- const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue;
- enum GNUNET_DB_QueryStatus qs;
/* Note: some optimization potential here: lots of fields we
could avoid fetching from the database with a custom function. */
@@ -1019,6 +1023,11 @@ withdraw_cb (void *cls,
for (size_t i=0; i < num_evs; i++)
{
+ struct DenominationSummary *ds;
+ struct TALER_DenominationHashP dh;
+ const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue;
+ enum GNUNET_DB_QueryStatus qs;
+
qs = TALER_ARL_get_denomination_info_by_serial (denom_serials[i],
&issue);
if (0 > qs)
@@ -1049,12 +1058,13 @@ withdraw_cb (void *cls,
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == cc->qs);
return GNUNET_SYSERR;
}
+ ds->dcd.num_issued++;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Issued coin in denomination `%s' of total value %s\n",
GNUNET_h2s (&dh.hash),
TALER_amount2s (&issue->value));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "New balance of denomination `%s' is %s\n",
+ "New balance of denomination `%s' after withdraw is %s\n",
GNUNET_h2s (&dh.hash),
TALER_amount2s (&ds->dcd.denom_balance));
TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_escrowed),
@@ -1063,7 +1073,6 @@ withdraw_cb (void *cls,
TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_balance_risk),
&TALER_ARL_USE_AB (coin_balance_risk),
&issue->value);
- ds->dcd.num_issued++;
TALER_ARL_amount_add (&ds->dcd.denom_balance,
&ds->dcd.denom_balance,
&issue->value);
@@ -1203,7 +1212,7 @@ check_known_coin (
GNUNET_break (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs);
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Checking denomination signature on %s\n",
TALER_B2S (coin_pub));
qs = TALER_ARL_edb->get_known_coin (TALER_ARL_edb->cls,
@@ -1581,7 +1590,7 @@ refresh_session_cb (void *cls,
&dsi->dcd.denom_risk,
&ni->value);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "New balance of denomination `%s' is %s\n",
+ "New balance of denomination `%s' after refresh_reveal is %s\n",
GNUNET_h2s (&ni->denom_hash.hash),
TALER_amount2s (&dsi->dcd.denom_balance));
TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_escrowed),
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
@@ -1687,7 +1687,7 @@ handle_mhd_request (void *cls,
.handler.post = &TEH_handler_csr_withdraw,
.nargs = 0
},
- /* withdraw request, available since v24 of the API */
+ /* withdraw request, available since v26 of the API */
{
.url = "withdraw",
.method = MHD_HTTP_METHOD_POST,
diff --git a/src/exchange/taler-exchange-httpd_withdraw.c b/src/exchange/taler-exchange-httpd_withdraw.c
@@ -1475,7 +1475,7 @@ withdraw_new_request (
{
size_t num_coins = json_array_size (j_denoms_h);
size_t array_size = json_array_size (j_coin_evs);
- const char *error = NULL;
+ const char *error;
_Static_assert (
TALER_MAX_FRESH_COINS < INT_MAX / TALER_CNC_KAPPA,
@@ -1510,9 +1510,9 @@ withdraw_new_request (
wc->request.persist.num_coins = num_coins;
wc->request.num_planchets = array_size;
+ error = NULL;
} while (0);
-
#undef BAIL_IF
if (NULL != error)
@@ -1524,18 +1524,16 @@ withdraw_new_request (
error);
return GNUNET_SYSERR;
}
-
}
-
- wc->request.denoms_h
- = GNUNET_new_array (wc->request.persist.num_coins,
- struct TALER_DenominationHashP);
-
/* extract the denomination hashes */
{
size_t idx;
json_t *value;
+ wc->request.denoms_h
+ = GNUNET_new_array (wc->request.persist.num_coins,
+ struct TALER_DenominationHashP);
+
json_array_foreach (j_denoms_h, idx, value) {
struct GNUNET_JSON_Specification ispec[] = {
GNUNET_JSON_spec_fixed_auto (NULL,
@@ -1550,11 +1548,6 @@ withdraw_new_request (
return res;
}
}
-
- wc->request.planchets =
- GNUNET_new_array (wc->request.num_planchets,
- struct TALER_BlindedPlanchet);
-
/* Calculate the hash over the blinded coin envelopes */
{
struct GNUNET_HashContext *hash_context;
@@ -1562,6 +1555,10 @@ withdraw_new_request (
hash_context = GNUNET_CRYPTO_hash_context_start ();
GNUNET_assert (NULL != hash_context);
+ wc->request.planchets =
+ GNUNET_new_array (wc->request.num_planchets,
+ struct TALER_BlindedPlanchet);
+
/* Parse blinded envelopes. */
{
json_t *j_cev;
@@ -1583,7 +1580,6 @@ withdraw_new_request (
if (GNUNET_OK != res)
return res;
-
/* Continue to hash of the coin candidates */
{
struct TALER_BlindedCoinHashP bch;
@@ -1614,7 +1610,7 @@ withdraw_new_request (
"duplicate planchet");
return GNUNET_SYSERR;
}
- } /* end duplicate check */
+ } /* end duplicate check */
} /* json_array_foreach over j_coin_evs */
} /* scope of j_kappa_planchets, idx */
@@ -1622,7 +1618,7 @@ withdraw_new_request (
GNUNET_CRYPTO_hash_context_finish (hash_context,
&wc->request.persist.h_planchets.hash);
} /* scope of hash_context */
- } /* scope of j_denoms_h, j_blinded_coin_evs */
+ } /* scope of j_denoms_h, j_blinded_coin_evs */
return GNUNET_OK;
}