Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

service: use deny-list instead of allow-list for BEEFY #5331

Merged
merged 7 commits into from
Apr 26, 2022
25 changes: 21 additions & 4 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -259,6 +262,9 @@ pub trait IdentifyVariant {
}

impl IdentifyVariant for Box<dyn ChainSpec> {
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")
}
Expand Down Expand Up @@ -675,7 +681,7 @@ pub fn new_full<RuntimeApi, ExecutorDispatch, OverseerGenerator>(
mut config: Configuration,
is_collator: IsCollator,
grandpa_pause: Option<(u32, u32)>,
enable_beefy: bool,
mut enable_beefy: bool,
jaeger_agent: Option<std::net::SocketAddr>,
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
program_path: Option<std::path::PathBuf>,
Expand Down Expand Up @@ -712,6 +718,18 @@ where
Some(backoff)
};

// For now BEEFY is explicitly disabled on non-test chains.
acatangiu marked this conversation as resolved.
Show resolved Hide resolved
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a warn: if enable_beefy { warn!("Tried to enable BEEFY on a production network. Refusing as BEEFY is still experimental.") }. Something along those lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that as well, but I found it odd that log crate is not used anywhere in node/service and I just assumed there's a reason for it...

I'll add log dependency and log a warn!, but writing it out here as well so anybody who knows of a reason we shouldn't, can react 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a local crate for logging that also deals with tracing gum::warn! should work.

Copy link
Contributor

@drahnr drahnr Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to make that easier to discover, but here's the rationale for the interested reader around why we need gum https://github.com/paritytech/polkadot/blob/6cafab2d926000fa612af29b02e8ed482d4dd9c5/node/gum/README.md

drahnr marked this conversation as resolved.
Show resolved Hide resolved
}

let disable_grandpa = config.disable_grandpa;
let name = config.network.node_name.clone();

Expand Down Expand Up @@ -781,7 +799,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
Expand Down Expand Up @@ -1111,8 +1129,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(),
Expand Down