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:
parent
10945e0619
commit
b4dd98b3c6
@ -109,6 +109,9 @@ pub struct Config {
|
|||||||
/// prevents sending client identifying information over identify.
|
/// prevents sending client identifying information over identify.
|
||||||
pub private: bool,
|
pub private: bool,
|
||||||
|
|
||||||
|
/// Shutdown beacon node after sync is completed.
|
||||||
|
pub shutdown_after_sync: bool,
|
||||||
|
|
||||||
/// List of extra topics to initially subscribe to as strings.
|
/// List of extra topics to initially subscribe to as strings.
|
||||||
pub topics: Vec<GossipKind>,
|
pub topics: Vec<GossipKind>,
|
||||||
}
|
}
|
||||||
@ -183,6 +186,7 @@ impl Default for Config {
|
|||||||
private: false,
|
private: false,
|
||||||
subscribe_all_subnets: false,
|
subscribe_all_subnets: false,
|
||||||
import_all_attestations: false,
|
import_all_attestations: false,
|
||||||
|
shutdown_after_sync: false,
|
||||||
topics: Vec::new(),
|
topics: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,8 @@ pub struct NetworkService<T: BeaconChainTypes> {
|
|||||||
next_unsubscribe: Pin<Box<OptionFuture<Sleep>>>,
|
next_unsubscribe: Pin<Box<OptionFuture<Sleep>>>,
|
||||||
/// Subscribe to all the subnets once synced.
|
/// Subscribe to all the subnets once synced.
|
||||||
subscribe_all_subnets: bool,
|
subscribe_all_subnets: bool,
|
||||||
|
/// Shutdown beacon node after sync is complete.
|
||||||
|
shutdown_after_sync: bool,
|
||||||
/// A timer for updating various network metrics.
|
/// A timer for updating various network metrics.
|
||||||
metrics_update: tokio::time::Interval,
|
metrics_update: tokio::time::Interval,
|
||||||
/// gossipsub_parameter_update timer
|
/// gossipsub_parameter_update timer
|
||||||
@ -254,6 +256,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
|||||||
next_fork_update,
|
next_fork_update,
|
||||||
next_unsubscribe,
|
next_unsubscribe,
|
||||||
subscribe_all_subnets: config.subscribe_all_subnets,
|
subscribe_all_subnets: config.subscribe_all_subnets,
|
||||||
|
shutdown_after_sync: config.shutdown_after_sync,
|
||||||
metrics_update,
|
metrics_update,
|
||||||
gossipsub_parameter_update,
|
gossipsub_parameter_update,
|
||||||
fork_context,
|
fork_context,
|
||||||
@ -436,6 +439,18 @@ fn spawn_service<T: BeaconChainTypes>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
NetworkMessage::SubscribeCoreTopics => {
|
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![];
|
let mut subscribed_topics: Vec<GossipTopic> = vec![];
|
||||||
for topic_kind in eth2_libp2p::types::CORE_TOPICS.iter() {
|
for topic_kind in eth2_libp2p::types::CORE_TOPICS.iter() {
|
||||||
for fork_digest in service.required_gossip_fork_digests() {
|
for fork_digest in service.required_gossip_fork_digests() {
|
||||||
|
@ -51,6 +51,12 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
|||||||
.help("Disables the discovery packet filter. Useful for testing in smaller networks")
|
.help("Disables the discovery packet filter. Useful for testing in smaller networks")
|
||||||
.takes_value(false),
|
.takes_value(false),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("shutdown-after-sync")
|
||||||
|
.long("shutdown-after-sync")
|
||||||
|
.help("Shutdown beacon node as soon as sync is completed")
|
||||||
|
.takes_value(false),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("zero-ports")
|
Arg::with_name("zero-ports")
|
||||||
.long("zero-ports")
|
.long("zero-ports")
|
||||||
|
@ -467,6 +467,10 @@ pub fn set_network_config(
|
|||||||
config.import_all_attestations = true;
|
config.import_all_attestations = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cli_args.is_present("shutdown-after-sync") {
|
||||||
|
config.shutdown_after_sync = true;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(listen_address_str) = cli_args.value_of("listen-address") {
|
if let Some(listen_address_str) = cli_args.value_of("listen-address") {
|
||||||
let listen_address = listen_address_str
|
let listen_address = listen_address_str
|
||||||
.parse()
|
.parse()
|
||||||
|
@ -308,6 +308,19 @@ fn network_import_all_attestations_flag() {
|
|||||||
.with_config(|config| assert!(config.network.import_all_attestations));
|
.with_config(|config| assert!(config.network.import_all_attestations));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
|
fn network_shutdown_after_sync_flag() {
|
||||||
|
CommandLineTest::new()
|
||||||
|
.flag("shutdown-after-sync", None)
|
||||||
|
.run()
|
||||||
|
.with_config(|config| assert!(config.network.shutdown_after_sync));
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn network_shutdown_after_sync_disabled_flag() {
|
||||||
|
CommandLineTest::new()
|
||||||
|
.run()
|
||||||
|
.with_config(|config| assert!(!config.network.shutdown_after_sync));
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
fn network_listen_address_flag() {
|
fn network_listen_address_flag() {
|
||||||
let addr = "127.0.0.2".parse::<Ipv4Addr>().unwrap();
|
let addr = "127.0.0.2".parse::<Ipv4Addr>().unwrap();
|
||||||
CommandLineTest::new()
|
CommandLineTest::new()
|
||||||
|
Loading…
Reference in New Issue
Block a user