add invariant checks

This commit is contained in:
Christian Grothoff 2021-11-25 13:37:47 +01:00
parent 98549cdc5a
commit 94012d011c
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
7 changed files with 78 additions and 15 deletions

View File

@ -290,8 +290,10 @@ handle_mhd_completion_callback (void *cls,
return; return;
GNUNET_async_scope_enter (&rc->async_scope_id, GNUNET_async_scope_enter (&rc->async_scope_id,
&old_scope); &old_scope);
TEH_check_invariants ();
if (NULL != rc->rh_cleaner) if (NULL != rc->rh_cleaner)
rc->rh_cleaner (rc); rc->rh_cleaner (rc);
TEH_check_invariants ();
{ {
#if MHD_VERSION >= 0x00097304 #if MHD_VERSION >= 0x00097304
const union MHD_ConnectionInfo *ci; const union MHD_ConnectionInfo *ci;
@ -931,6 +933,7 @@ handle_mhd_request (void *cls,
/* We're in a new async scope! */ /* We're in a new async scope! */
rc = *con_cls = GNUNET_new (struct TEH_RequestContext); rc = *con_cls = GNUNET_new (struct TEH_RequestContext);
GNUNET_async_scope_fresh (&rc->async_scope_id); GNUNET_async_scope_fresh (&rc->async_scope_id);
TEH_check_invariants ();
rc->url = url; rc->url = url;
rc->connection = connection; rc->connection = connection;
/* We only read the correlation ID on the first callback for every client */ /* We only read the correlation ID on the first callback for every client */
@ -949,6 +952,7 @@ handle_mhd_request (void *cls,
GNUNET_async_scope_enter (&rc->async_scope_id, GNUNET_async_scope_enter (&rc->async_scope_id,
&old_scope); &old_scope);
TEH_check_invariants ();
if (NULL != correlation_id) if (NULL != correlation_id)
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Handling request (%s) for URL '%s', correlation_id=%s\n", "Handling request (%s) for URL '%s', correlation_id=%s\n",
@ -1802,10 +1806,12 @@ run (void *cls,
MHD_OPTION_NOTIFY_CONNECTION, MHD_OPTION_NOTIFY_CONNECTION,
&connection_done, &connection_done,
NULL, NULL,
MHD_OPTION_LISTENING_ADDRESS_REUSE,
(unsigned int) allow_address_reuse,
MHD_OPTION_CONNECTION_TIMEOUT, MHD_OPTION_CONNECTION_TIMEOUT,
connection_timeout, connection_timeout,
(0 == allow_address_reuse)
? MHD_OPTION_END
: MHD_OPTION_LISTENING_ADDRESS_REUSE,
(unsigned int) allow_address_reuse,
MHD_OPTION_END); MHD_OPTION_END);
if (NULL == mhd) if (NULL == mhd)
{ {

View File

@ -461,6 +461,52 @@ suspend_request (struct MHD_Connection *connection)
} }
/**
* Called on each denomination key. Checks that the key still works.
*
* @param cls NULL
* @param hc denomination hash (unused)
* @param value a `struct TEH_DenominationKey`
* @return #GNUNET_OK
*/
static int
check_dk (void *cls,
const struct GNUNET_HashCode *hc,
void *value)
{
struct TEH_DenominationKey *dk = value;
struct TALER_PlanchetSecretsP ps;
struct TALER_PlanchetDetail pd;
struct TALER_CoinPubHash c_hash;
(void) hc;
(void) value;
GNUNET_assert (TALER_DENOMINATION_INVALID != dk->denom_pub.cipher);
memset (&ps,
42,
sizeof (ps));
GNUNET_assert (GNUNET_OK ==
TALER_planchet_prepare (&dk->denom_pub,
&ps,
&c_hash,
&pd));
GNUNET_free (pd.coin_ev);
return GNUNET_OK;
}
void
TEH_check_invariants ()
{
struct TEH_KeyStateHandle *ksh;
ksh = TEH_keys_get_state ();
GNUNET_CONTAINER_multihashmap_iterate (ksh->denomkey_map,
&check_dk,
NULL);
}
void void
TEH_resume_keys_requests (bool do_shutdown) TEH_resume_keys_requests (bool do_shutdown)
{ {
@ -935,8 +981,12 @@ keys_update_event_cb (void *cls,
(void) cls; (void) cls;
(void) extra; (void) extra;
(void) extra_size; (void) extra_size;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received /keys update event\n");
TEH_check_invariants ();
key_generation++; key_generation++;
TEH_resume_keys_requests (false); TEH_resume_keys_requests (false);
TEH_check_invariants ();
} }

View File

@ -96,6 +96,13 @@ struct TEH_DenominationKey
struct TEH_KeyStateHandle; struct TEH_KeyStateHandle;
/**
* Run internal invariant checks. For debugging.
*/
void
TEH_check_invariants (void);
/** /**
* Return the current key state for this thread. Possibly re-builds the key * Return the current key state for this thread. Possibly re-builds the key
* state if we have reason to believe that something changed. * state if we have reason to believe that something changed.

View File

@ -210,9 +210,12 @@ db_event_cb (void *cls,
if (! kyp->suspended) if (! kyp->suspended)
return; /* event triggered while main transaction return; /* event triggered while main transaction
was still running, or got multiple wake-up events */ was still running, or got multiple wake-up events */
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received KYC update event\n");
kyp->suspended = false; kyp->suspended = false;
GNUNET_async_scope_enter (&rc->async_scope_id, GNUNET_async_scope_enter (&rc->async_scope_id,
&old_scope); &old_scope);
TEH_check_invariants ();
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Resuming from long-polling on KYC status\n"); "Resuming from long-polling on KYC status\n");
GNUNET_CONTAINER_DLL_remove (kyp_head, GNUNET_CONTAINER_DLL_remove (kyp_head,
@ -220,6 +223,7 @@ db_event_cb (void *cls,
kyp); kyp);
MHD_resume_connection (kyp->connection); MHD_resume_connection (kyp->connection);
TALER_MHD_daemon_trigger (); TALER_MHD_daemon_trigger ();
TEH_check_invariants ();
GNUNET_async_scope_restore (&old_scope); GNUNET_async_scope_restore (&old_scope);
} }

View File

@ -26,6 +26,7 @@
#include "taler_mhd_lib.h" #include "taler_mhd_lib.h"
#include "taler_json_lib.h" #include "taler_json_lib.h"
#include "taler_dbevents.h" #include "taler_dbevents.h"
#include "taler-exchange-httpd_keys.h"
#include "taler-exchange-httpd_reserves_get.h" #include "taler-exchange-httpd_reserves_get.h"
#include "taler-exchange-httpd_responses.h" #include "taler-exchange-httpd_responses.h"
@ -152,11 +153,13 @@ db_event_cb (void *cls,
&old_scope); &old_scope);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Resuming from long-polling on reserve\n"); "Resuming from long-polling on reserve\n");
TEH_check_invariants ();
GNUNET_CONTAINER_DLL_remove (rp_head, GNUNET_CONTAINER_DLL_remove (rp_head,
rp_tail, rp_tail,
rp); rp);
MHD_resume_connection (rp->connection); MHD_resume_connection (rp->connection);
TALER_MHD_daemon_trigger (); TALER_MHD_daemon_trigger ();
TEH_check_invariants ();
GNUNET_async_scope_restore (&old_scope); GNUNET_async_scope_restore (&old_scope);
} }

View File

@ -22,6 +22,7 @@
#include <gnunet/gnunet_json_lib.h> #include <gnunet/gnunet_json_lib.h>
#include "taler_dbevents.h" #include "taler_dbevents.h"
#include "taler-exchange-httpd_responses.h" #include "taler-exchange-httpd_responses.h"
#include "taler-exchange-httpd_keys.h"
#include "taler-exchange-httpd_wire.h" #include "taler-exchange-httpd_wire.h"
#include "taler_json_lib.h" #include "taler_json_lib.h"
#include "taler_mhd_lib.h" #include "taler_mhd_lib.h"
@ -99,6 +100,9 @@ wire_update_event_cb (void *cls,
(void) cls; (void) cls;
(void) extra; (void) extra;
(void) extra_size; (void) extra_size;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received /wire update event\n");
TEH_check_invariants ();
wire_generation++; wire_generation++;
} }
@ -387,10 +391,12 @@ get_wire_state (void)
{ {
struct WireStateHandle *wsh; struct WireStateHandle *wsh;
TEH_check_invariants ();
wsh = build_wire_state (); wsh = build_wire_state ();
wire_state = wsh; wire_state = wsh;
if (NULL != old_wsh) if (NULL != old_wsh)
destroy_wire_state (old_wsh); destroy_wire_state (old_wsh);
TEH_check_invariants ();
return wsh; return wsh;
} }
return old_wsh; return old_wsh;

View File

@ -324,13 +324,6 @@ sign_keys_for_exchange (void *cls,
si->ec->exchange_url = NULL; si->ec->exchange_url = NULL;
return GNUNET_NO; return GNUNET_NO;
} }
if (GNUNET_OK !=
TALER_TESTING_url_port_free (si->ec->exchange_url))
{
GNUNET_free (si->ec->exchange_url);
si->ec->exchange_url = NULL;
return GNUNET_NO;
}
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, GNUNET_CONFIGURATION_get_value_string (cfg,
"auditor", "auditor",
@ -345,12 +338,6 @@ sign_keys_for_exchange (void *cls,
si->ec->auditor_url = NULL; si->ec->auditor_url = NULL;
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (GNUNET_OK !=
TALER_TESTING_url_port_free (si->ec->auditor_url))
{
ret = GNUNET_NO;
goto fail;
}
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, GNUNET_CONFIGURATION_get_value_string (cfg,
"exchange", "exchange",