From 6355956087b0680e1154c78f7408cf113c7bec08 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Wed, 27 Nov 2019 17:02:21 +0100 Subject: [PATCH] *: Gate authority discovery module behind feature flag --- cli/src/lib.rs | 13 +++++++++++-- service/src/lib.rs | 29 ++++++++++++++++++----------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index a4fa70a57ea7..9d7392c6d2cd 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -87,13 +87,21 @@ struct ValidationWorkerCommand { pub mem_id: String, } +#[derive(Debug, StructOpt, Clone)] +pub struct PolkadotSubParams { + #[structopt(long = "enable-authority-discovery")] + pub authority_discovery_enabled: bool, +} + +cli::impl_augment_clap!(PolkadotSubParams); + /// Parses polkadot specific CLI arguments and run the service. pub fn run(worker: W, version: cli::VersionInfo) -> error::Result<()> where W: Worker, { - match cli::parse_and_prepare::(&version, "parity-polkadot", std::env::args()) { + match cli::parse_and_prepare::(&version, "parity-polkadot", std::env::args()) { cli::ParseAndPrepare::Run(cmd) => cmd.run(load_spec, worker, - |worker, _cli_args, _custom_args, mut config| { + |worker, cli_args, custom_args, mut config| { info!("{}", version.name); info!(" version {}", config.full_version()); info!(" by {}, 2017-2019", version.author); @@ -108,6 +116,7 @@ pub fn run(worker: W, version: cli::VersionInfo) -> error::Result<()> where info!("Node name: {}", config.name); info!("Roles: {}", display_role(&config)); config.custom = worker.configuration(); + config.custom.authority_discovery_enabled = custom_args.authority_discovery_enabled; let runtime = Runtime::new().map_err(|e| format!("{:?}", e))?; match config.roles { service::Roles::LIGHT => diff --git a/service/src/lib.rs b/service/src/lib.rs index 71061f4243f8..5c7a5735d59b 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -55,6 +55,9 @@ pub struct CustomConfiguration { /// Maximal `block_data` size. pub max_block_data_size: Option, + + /// Whether to enable or disable the authority discovery module. + pub authority_discovery_enabled: bool, } impl Default for CustomConfiguration { @@ -62,6 +65,7 @@ impl Default for CustomConfiguration { Self { collating_for: None, max_block_data_size: None, + authority_discovery_enabled: false, } } } @@ -160,6 +164,7 @@ pub fn new_full(config: Configuration) }; let disable_grandpa = config.disable_grandpa; let name = config.name.clone(); + let authority_discovery_enabled = config.custom.authority_discovery_enabled; // sentry nodes announce themselves as authorities to the network // and should run the same protocols authorities do, but it should @@ -279,18 +284,20 @@ pub fn new_full(config: Configuration) let babe = babe::start_babe(babe_config)?; service.spawn_essential_task(babe); - let future03_dht_event_rx = dht_event_rx.compat() - .map(|x| x.expect(" never returns an error; qed")) - .boxed(); - let authority_discovery = authority_discovery::AuthorityDiscovery::new( - service.client(), - service.network(), - service.keystore(), - future03_dht_event_rx, - ); - let future01_authority_discovery = authority_discovery.map(|x| Ok(x)).compat(); + if authority_discovery_enabled { + let future03_dht_event_rx = dht_event_rx.compat() + .map(|x| x.expect(" never returns an error; qed")) + .boxed(); + let authority_discovery = authority_discovery::AuthorityDiscovery::new( + service.client(), + service.network(), + service.keystore(), + future03_dht_event_rx, + ); + let future01_authority_discovery = authority_discovery.map(|x| Ok(x)).compat(); - service.spawn_task(future01_authority_discovery); + service.spawn_task(future01_authority_discovery); + } } // if the node isn't actively participating in consensus then it doesn't