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

Name changes for GrandPa and Beefy notifications protocols #10463

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3cf86ef
grandpa: update notif protocol name
acatangiu Dec 9, 2021
fbf7cf5
grandpa: add chain id prefix to protocol name
acatangiu Dec 10, 2021
2b22762
grandpa: beautify protocol name handling
acatangiu Dec 10, 2021
206beaa
grandpa: prepend genesis hash to protocol name
acatangiu Dec 10, 2021
952e0a7
chain-spec: add optional 'fork_id'
acatangiu Dec 13, 2021
758ff84
grandpa: protocol_name mod instead of struct
acatangiu Dec 13, 2021
b3a0243
beefy: add genesis hash prefix to protocol name
acatangiu Dec 13, 2021
44baf42
chainspec: add fork_id
acatangiu Dec 14, 2021
0f9d6cc
grandpa: simplify protocol name
acatangiu Dec 14, 2021
393c8cf
Merge branch 'master' of github.com:paritytech/substrate into grandpa…
acatangiu Dec 14, 2021
482f0bc
grandpa: contain protocol name building logic
acatangiu Dec 16, 2021
1dda847
beefy: contain protocol name building logic
acatangiu Dec 16, 2021
1262cce
grandpa: fix tests
acatangiu Dec 16, 2021
f3a006d
Merge branch 'master' of github.com:paritytech/substrate into grandpa…
acatangiu Dec 16, 2021
b4b8a74
fix merge damage
acatangiu Dec 16, 2021
0de4362
fix docs reference visibility
acatangiu Dec 20, 2021
a07eec6
Update client/finality-grandpa/src/lib.rs
acatangiu Dec 20, 2021
1aa9753
Update client/finality-grandpa/src/communication/mod.rs
acatangiu Dec 20, 2021
5673f48
Update client/beefy/src/lib.rs
acatangiu Dec 20, 2021
5a6a7b2
Update client/beefy/src/lib.rs
acatangiu Dec 20, 2021
d70ed35
avoid using hash default, even for protocol names
acatangiu Jan 4, 2022
d5802f6
Merge branch 'master' of github.com:paritytech/substrate into grandpa…
acatangiu Jan 4, 2022
3c7f699
Merge branch 'master' of github.com:paritytech/substrate into grandpa…
acatangiu Jan 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions bin/node-template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub fn development_config() -> Result<ChainSpec, String> {
None,
// Protocol ID
None,
None,
// Properties
None,
// Extensions
Expand Down Expand Up @@ -117,6 +118,7 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
None,
// Properties
None,
None,
// Extensions
None,
))
Expand Down
12 changes: 10 additions & 2 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.

use node_template_runtime::{self, opaque::Block, RuntimeApi};
use sc_client_api::ExecutorProvider;
use sc_client_api::{BlockBackend, ExecutorProvider};
use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams};
pub use sc_executor::NativeElseWasmExecutor;
use sc_finality_grandpa::SharedVoterState;
Expand Down Expand Up @@ -180,8 +180,15 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
))),
};
}
let grandpa_protocol_name = sc_finality_grandpa::protocol_standard_name(
&client.block_hash(0).ok().flatten().expect("Genesis block exists; qed"),
&config.chain_spec,
);

config.network.extra_sets.push(sc_finality_grandpa::grandpa_peers_set_config());
config
.network
.extra_sets
.push(sc_finality_grandpa::grandpa_peers_set_config(grandpa_protocol_name.clone()));
let warp_sync = Arc::new(sc_finality_grandpa::warp_proof::NetworkProvider::new(
backend.clone(),
grandpa_link.shared_authority_set().clone(),
Expand Down Expand Up @@ -306,6 +313,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
keystore,
local_role: role,
telemetry: telemetry.as_ref().map(|x| x.handle()),
protocol_name: grandpa_protocol_name,
};

if enable_grandpa {
Expand Down
5 changes: 5 additions & 0 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ pub fn staging_testnet_config() -> ChainSpec {
),
None,
None,
None,
Default::default(),
)
}
Expand Down Expand Up @@ -386,6 +387,7 @@ pub fn development_config() -> ChainSpec {
None,
None,
None,
None,
Default::default(),
)
}
Expand All @@ -410,6 +412,7 @@ pub fn local_testnet_config() -> ChainSpec {
None,
None,
None,
None,
Default::default(),
)
}
Expand Down Expand Up @@ -441,6 +444,7 @@ pub(crate) mod tests {
None,
None,
None,
None,
Default::default(),
)
}
Expand All @@ -456,6 +460,7 @@ pub(crate) mod tests {
None,
None,
None,
None,
Default::default(),
)
}
Expand Down
10 changes: 9 additions & 1 deletion bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,15 @@ pub fn new_full_base(

let shared_voter_state = rpc_setup;
let auth_disc_publish_non_global_ips = config.network.allow_non_globals_in_dht;
let grandpa_protocol_name = grandpa::protocol_standard_name(
&client.block_hash(0).ok().flatten().expect("Genesis block exists; qed"),
&config.chain_spec,
);

config.network.extra_sets.push(grandpa::grandpa_peers_set_config());
config
.network
.extra_sets
.push(grandpa::grandpa_peers_set_config(grandpa_protocol_name.clone()));
let warp_sync = Arc::new(grandpa::warp_proof::NetworkProvider::new(
backend.clone(),
import_setup.1.shared_authority_set().clone(),
Expand Down Expand Up @@ -488,6 +495,7 @@ pub fn new_full_base(
keystore,
local_role: role,
telemetry: telemetry.as_ref().map(|x| x.handle()),
protocol_name: grandpa_protocol_name,
};

if enable_grandpa {
Expand Down
1 change: 1 addition & 0 deletions bin/utils/chain-spec-builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ fn generate_chain_spec(
None,
None,
None,
None,
Default::default(),
);

Expand Down
1 change: 1 addition & 0 deletions client/beefy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sp-core = { version = "4.1.0-dev", path = "../../primitives/core" }
sp-keystore = { version = "0.10.0", path = "../../primitives/keystore" }
sp-runtime = { version = "4.0.0", path = "../../primitives/runtime" }

sc-chain-spec = { version = "4.0.0-dev", path = "../../client/chain-spec" }
sc-utils = { version = "4.0.0-dev", path = "../utils" }
sc-client-api = { version = "4.0.0-dev", path = "../api" }
sc-keystore = { version = "4.0.0-dev", path = "../keystore" }
Expand Down
41 changes: 34 additions & 7 deletions client/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,40 @@ mod round;
mod worker;

pub mod notification;

pub const BEEFY_PROTOCOL_NAME: &str = "/paritytech/beefy/1";
pub use beefy_protocol_name::standard_name as protocol_standard_name;

pub(crate) mod beefy_protocol_name {
use sc_chain_spec::ChainSpec;

const NAME: &'static str = "/beefy/1";
/// Old names for the notifications protocol, used for backward compatibility.
pub(crate) const LEGACY_NAMES: [&'static str; 1] = ["/paritytech/beefy/1"];

/// Name of the notifications protocol used by BEEFY.
///
/// Must be registered towards the networking in order for BEEFY to properly function.
pub fn standard_name<Hash: std::fmt::Display>(
genesis_hash: &Hash,
chain_spec: &Box<dyn ChainSpec>,
) -> std::borrow::Cow<'static, str> {
acatangiu marked this conversation as resolved.
Show resolved Hide resolved
let chain_prefix = match chain_spec.fork_id() {
Some(fork_id) => format!("/{}/{}", genesis_hash, fork_id),
None => format!("/{}", genesis_hash),
};
format!("{}{}", chain_prefix, NAME).into()
}
}

/// Returns the configuration value to put in
/// [`sc_network::config::NetworkConfiguration::extra_sets`].
pub fn beefy_peers_set_config() -> sc_network::config::NonDefaultSetConfig {
let mut cfg =
sc_network::config::NonDefaultSetConfig::new(BEEFY_PROTOCOL_NAME.into(), 1024 * 1024);
/// For standard protocol name see [`beefy_protocol_name::standard_name`].
pub fn beefy_peers_set_config(
protocol_name: std::borrow::Cow<'static, str>,
) -> sc_network::config::NonDefaultSetConfig {
let mut cfg = sc_network::config::NonDefaultSetConfig::new(protocol_name, 1024 * 1024);

cfg.allow_non_reserved(25, 25);
cfg.add_fallback_names(beefy_protocol_name::LEGACY_NAMES.iter().map(|&n| n.into()).collect());
cfg
}

Expand Down Expand Up @@ -101,6 +126,8 @@ where
pub min_block_delta: u32,
/// Prometheus metric registry
pub prometheus_registry: Option<Registry>,
/// Chain specific GRANDPA protocol name. See [`beefy_protocol_name::standard_name`].
pub protocol_name: std::borrow::Cow<'static, str>,
}

/// Start the BEEFY gadget.
Expand All @@ -122,11 +149,11 @@ where
signed_commitment_sender,
min_block_delta,
prometheus_registry,
protocol_name,
} = beefy_params;

let gossip_validator = Arc::new(gossip::GossipValidator::new());
let gossip_engine =
GossipEngine::new(network, BEEFY_PROTOCOL_NAME, gossip_validator.clone(), None);
let gossip_engine = GossipEngine::new(network, protocol_name, gossip_validator.clone(), None);

let metrics =
prometheus_registry.as_ref().map(metrics::Metrics::register).and_then(
Expand Down
12 changes: 12 additions & 0 deletions client/chain-spec/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ struct ClientSpec<E> {
boot_nodes: Vec<MultiaddrWithPeerId>,
telemetry_endpoints: Option<TelemetryEndpoints>,
protocol_id: Option<String>,
fork_id: Option<String>,
properties: Option<Properties>,
#[serde(flatten)]
extensions: E,
Expand Down Expand Up @@ -226,6 +227,11 @@ impl<G, E> ChainSpec<G, E> {
self.client_spec.protocol_id.as_ref().map(String::as_str)
}

/// Optional network fork identifier.
pub fn fork_id(&self) -> Option<&str> {
self.client_spec.fork_id.as_ref().map(String::as_str)
}

/// Additional loosly-typed properties of the chain.
///
/// Returns an empty JSON object if 'properties' not defined in config
Expand Down Expand Up @@ -257,6 +263,7 @@ impl<G, E> ChainSpec<G, E> {
boot_nodes: Vec<MultiaddrWithPeerId>,
telemetry_endpoints: Option<TelemetryEndpoints>,
protocol_id: Option<&str>,
fork_id: Option<&str>,
properties: Option<Properties>,
extensions: E,
) -> Self {
Expand All @@ -267,6 +274,7 @@ impl<G, E> ChainSpec<G, E> {
boot_nodes,
telemetry_endpoints,
protocol_id: protocol_id.map(str::to_owned),
fork_id: fork_id.map(str::to_owned),
properties,
extensions,
consensus_engine: (),
Expand Down Expand Up @@ -384,6 +392,10 @@ where
ChainSpec::protocol_id(self)
}

fn fork_id(&self) -> Option<&str> {
ChainSpec::fork_id(self)
}

fn properties(&self) -> Properties {
ChainSpec::properties(self)
}
Expand Down
2 changes: 2 additions & 0 deletions client/chain-spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ pub trait ChainSpec: BuildStorage + Send + Sync {
fn telemetry_endpoints(&self) -> &Option<TelemetryEndpoints>;
/// Network protocol id.
fn protocol_id(&self) -> Option<&str>;
/// Optional network fork identifier. `None` by default.
fn fork_id(&self) -> Option<&str>;
/// Additional loosly-typed properties of the chain.
///
/// Returns an empty JSON object if 'properties' not defined in config
Expand Down
1 change: 1 addition & 0 deletions client/cli/src/commands/insert_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ mod tests {
None,
None,
None,
None,
NoExtension::None,
)))
}
Expand Down
1 change: 1 addition & 0 deletions client/finality-grandpa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ parity-scale-codec = { version = "2.3.1", features = ["derive"] }
sp-application-crypto = { version = "4.0.0", path = "../../primitives/application-crypto" }
sp-arithmetic = { version = "4.0.0", path = "../../primitives/arithmetic" }
sp-runtime = { version = "4.0.0", path = "../../primitives/runtime" }
sc-chain-spec = { version = "4.0.0-dev", path = "../../client/chain-spec" }
sc-utils = { version = "4.0.0-dev", path = "../utils" }
sp-consensus = { version = "0.10.0-dev", path = "../../primitives/consensus/common" }
sc-consensus = { version = "0.10.0-dev", path = "../consensus/common" }
Expand Down
Loading