From 0325277200bc04cf615edecafd81e87eeeda32c8 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Fri, 15 Apr 2022 16:41:14 +0300 Subject: [PATCH 1/3] use deny-list instead of allow-list for BEEFY Instead of allowing BEEFY to run on specific test nets, inverse the condition to explicitly disallow BEEFY on production chains that we don't want it to run on yet. This allows other test chains (other than Rococo/Wococo) that use the polkadot service file to enable and test BEEFY. Signed-off-by: Adrian Catangiu --- node/service/src/lib.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 8059ff5230ab..a419463f1c47 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -239,6 +239,9 @@ pub enum Error { /// Can be called for a `Configuration` to identify which network the configuration targets. pub trait IdentifyVariant { + /// Returns if this is a configuration for the `Polkadot` network. + fn is_polkadot(&self) -> bool; + /// Returns if this is a configuration for the `Kusama` network. fn is_kusama(&self) -> bool; @@ -259,6 +262,9 @@ pub trait IdentifyVariant { } impl IdentifyVariant for Box { + fn is_polkadot(&self) -> bool { + self.id().starts_with("polkadot") || self.id().starts_with("dot") + } fn is_kusama(&self) -> bool { self.id().starts_with("kusama") || self.id().starts_with("ksm") } @@ -675,7 +681,7 @@ pub fn new_full( mut config: Configuration, is_collator: IsCollator, grandpa_pause: Option<(u32, u32)>, - enable_beefy: bool, + mut enable_beefy: bool, jaeger_agent: Option, telemetry_worker_handle: Option, program_path: Option, @@ -711,6 +717,13 @@ where Some(backoff) }; + // For now BEEFY is explicitly disabled on non-test chains. + if config.chain_spec.is_polkadot() || + config.chain_spec.is_kusama() || + config.chain_spec.is_westend() + { + enable_beefy = false; + } let disable_grandpa = config.disable_grandpa; let name = config.network.node_name.clone(); @@ -781,7 +794,7 @@ where &client.block_hash(0).ok().flatten().expect("Genesis block exists; qed"), &config.chain_spec, ); - if chain_spec.is_rococo() || chain_spec.is_wococo() || chain_spec.is_versi() { + if enable_beefy { config .network .extra_sets @@ -1111,8 +1124,7 @@ where let keystore_opt = if role.is_authority() { Some(keystore_container.sync_keystore()) } else { None }; - // We currently only run the BEEFY gadget on the Rococo and Wococo testnets. - if enable_beefy && (chain_spec.is_rococo() || chain_spec.is_wococo() || chain_spec.is_versi()) { + if enable_beefy { let beefy_params = beefy_gadget::BeefyParams { client: client.clone(), backend: backend.clone(), From e6a6d009e3ca7b1adf7dbba696890060b52a784f Mon Sep 17 00:00:00 2001 From: acatangiu Date: Tue, 19 Apr 2022 12:32:58 +0300 Subject: [PATCH 2/3] address review comments --- node/service/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index a419463f1c47..59159f07c4d6 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -717,11 +717,16 @@ where Some(backoff) }; + // For now BEEFY is explicitly disabled on non-test chains. if config.chain_spec.is_polkadot() || config.chain_spec.is_kusama() || config.chain_spec.is_westend() { + gum::warn!( + "Refusing to enable BEEFY on a production network; \ + BEEFY is still experimental." + ); enable_beefy = false; } From 752b4e972648cbcce33b80132d3ab1f3ec8f8bba Mon Sep 17 00:00:00 2001 From: acatangiu Date: Fri, 22 Apr 2022 12:55:32 +0300 Subject: [PATCH 3/3] throw error if BEEFY enabled on production networks Signed-off-by: acatangiu --- cli/src/command.rs | 7 +++++++ node/service/src/lib.rs | 17 +++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cli/src/command.rs b/cli/src/command.rs index 698fbaad6ff3..ef13e222658b 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -273,6 +273,13 @@ where .map_err(Error::from)?; let chain_spec = &runner.config().chain_spec; + // Disallow BEEFY on production networks. + if cli.run.beefy && + (chain_spec.is_polkadot() || chain_spec.is_kusama() || chain_spec.is_westend()) + { + return Err(Error::Other("BEEFY disallowed on production networks".to_string())) + } + set_default_ss58_version(chain_spec); let grandpa_pause = if cli.run.grandpa_pause.is_empty() { diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 59159f07c4d6..b5f0da6f8c7f 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -681,7 +681,7 @@ pub fn new_full( mut config: Configuration, is_collator: IsCollator, grandpa_pause: Option<(u32, u32)>, - mut enable_beefy: bool, + enable_beefy: bool, jaeger_agent: Option, telemetry_worker_handle: Option, program_path: Option, @@ -718,16 +718,13 @@ where Some(backoff) }; - // For now BEEFY is explicitly disabled on non-test chains. - if config.chain_spec.is_polkadot() || - config.chain_spec.is_kusama() || - config.chain_spec.is_westend() + // If not on a known test network, warn the user that BEEFY is still experimental. + if enable_beefy && + !config.chain_spec.is_rococo() && + !config.chain_spec.is_wococo() && + !config.chain_spec.is_versi() { - gum::warn!( - "Refusing to enable BEEFY on a production network; \ - BEEFY is still experimental." - ); - enable_beefy = false; + gum::warn!("BEEFY is still experimental, usage on a production network is discouraged."); } let disable_grandpa = config.disable_grandpa;