Shutdown after sync (#2519)

## Issue Addressed

Resolves #2033 

## Proposed Changes

Adds a flag to enable shutting down beacon node right after sync is completed.

## Additional Info

Will need modification after weak subjectivity sync is enabled to change definition of a fully synced node.
This commit is contained in:
Pawan Dhananjay
2021-08-30 13:46:13 +00:00
parent 10945e0619
commit b4dd98b3c6
5 changed files with 42 additions and 0 deletions

View File

@@ -133,6 +133,8 @@ pub struct NetworkService<T: BeaconChainTypes> {
next_unsubscribe: Pin<Box<OptionFuture<Sleep>>>,
/// Subscribe to all the subnets once synced.
subscribe_all_subnets: bool,
/// Shutdown beacon node after sync is complete.
shutdown_after_sync: bool,
/// A timer for updating various network metrics.
metrics_update: tokio::time::Interval,
/// gossipsub_parameter_update timer
@@ -254,6 +256,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {
next_fork_update,
next_unsubscribe,
subscribe_all_subnets: config.subscribe_all_subnets,
shutdown_after_sync: config.shutdown_after_sync,
metrics_update,
gossipsub_parameter_update,
fork_context,
@@ -436,6 +439,18 @@ fn spawn_service<T: BeaconChainTypes>(
}
}
NetworkMessage::SubscribeCoreTopics => {
if service.shutdown_after_sync {
let _ = shutdown_sender
.send(ShutdownReason::Success(
"Beacon node completed sync. Shutting down as --shutdown-after-sync flag is enabled"))
.await
.map_err(|e| warn!(
service.log,
"failed to send a shutdown signal";
"error" => %e
));
return;
}
let mut subscribed_topics: Vec<GossipTopic> = vec![];
for topic_kind in eth2_libp2p::types::CORE_TOPICS.iter() {
for fork_digest in service.required_gossip_fork_digests() {