diff --git a/external/c-libp2p b/external/c-libp2p index 2d8d371..cf5116a 160000 --- a/external/c-libp2p +++ b/external/c-libp2p @@ -1 +1 @@ -Subproject commit 2d8d3718a126013f5906462886e918184d0cecf5 +Subproject commit cf5116a23423f0601f88d7ddcdb6dceca75acd48 diff --git a/include/lantern/networking/gossipsub_service.h b/include/lantern/networking/gossipsub_service.h index a2e5240..421a8e7 100644 --- a/include/lantern/networking/gossipsub_service.h +++ b/include/lantern/networking/gossipsub_service.h @@ -63,6 +63,7 @@ struct lantern_gossipsub_service { }; void lantern_gossipsub_service_init(struct lantern_gossipsub_service *service); +void lantern_gossipsub_service_stop(struct lantern_gossipsub_service *service); void lantern_gossipsub_service_reset(struct lantern_gossipsub_service *service); int lantern_gossipsub_service_start( struct lantern_gossipsub_service *service, diff --git a/src/core/client.c b/src/core/client.c index 2ed19af..c1704dc 100644 --- a/src/core/client.c +++ b/src/core/client.c @@ -3264,7 +3264,7 @@ static void shutdown_genesis_and_network(struct lantern_client *client) "client", &(const struct lantern_log_metadata){.validator = client->node_id}, "shutdown: stopping gossipsub"); - lantern_gossipsub_service_reset(&client->gossip); + lantern_gossipsub_service_stop(&client->gossip); client->gossip_running = false; lantern_log_info( "client", @@ -3275,6 +3275,7 @@ static void shutdown_genesis_and_network(struct lantern_client *client) &(const struct lantern_log_metadata){.validator = client->node_id}, "shutdown: resetting libp2p host"); lantern_libp2p_host_reset(&client->network); + lantern_gossipsub_service_reset(&client->gossip); lantern_log_info( "client", &(const struct lantern_log_metadata){.validator = client->node_id}, diff --git a/src/networking/gossipsub_service.c b/src/networking/gossipsub_service.c index b89e588..2d1c815 100644 --- a/src/networking/gossipsub_service.c +++ b/src/networking/gossipsub_service.c @@ -714,7 +714,7 @@ void lantern_gossipsub_service_init(struct lantern_gossipsub_service *service) { memset(service, 0, sizeof(*service)); } -void lantern_gossipsub_service_reset(struct lantern_gossipsub_service *service) { +static void lantern_gossipsub_service_remove_validators(struct lantern_gossipsub_service *service) { if (!service) { return; } @@ -738,8 +738,24 @@ void lantern_gossipsub_service_reset(struct lantern_gossipsub_service *service) service->vote_validator_handle = NULL; service->vote_subnet_validator_handle = NULL; service->aggregated_attestation_validator_handle = NULL; +} + +void lantern_gossipsub_service_stop(struct lantern_gossipsub_service *service) { + if (!service) { + return; + } + lantern_gossipsub_service_remove_validators(service); if (service->gossipsub) { libp2p_gossipsub_stop(service->gossipsub); + } +} + +void lantern_gossipsub_service_reset(struct lantern_gossipsub_service *service) { + if (!service) { + return; + } + lantern_gossipsub_service_stop(service); + if (service->gossipsub) { libp2p_gossipsub_free(service->gossipsub); service->gossipsub = NULL; }