From 3cf86efe5c4bbd0e457f8d65cce52b963e00684b Mon Sep 17 00:00:00 2001 From: acatangiu Date: Thu, 9 Dec 2021 17:37:49 +0200 Subject: [PATCH 01/19] grandpa: update notif protocol name --- client/finality-grandpa/src/communication/mod.rs | 4 +++- client/finality-grandpa/src/lib.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/finality-grandpa/src/communication/mod.rs b/client/finality-grandpa/src/communication/mod.rs index c370e1d642d7d..1fd3de2810c96 100644 --- a/client/finality-grandpa/src/communication/mod.rs +++ b/client/finality-grandpa/src/communication/mod.rs @@ -69,7 +69,9 @@ pub(crate) mod tests; /// Name of the notifications protocol used by Grandpa. Must be registered towards the networking /// in order for Grandpa to properly function. -pub const GRANDPA_PROTOCOL_NAME: &'static str = "/paritytech/grandpa/1"; +pub(crate) const GRANDPA_PROTOCOL_NAME: &'static str = "/substrate/grandpa/1"; +/// Old name for the notifications protocol, still used for backward compatibility. +pub(crate) const GRANDPA_PROTOCOL_LEGACY: &'static str = "/paritytech/grandpa/1"; // cost scalars for reporting peers. mod cost { diff --git a/client/finality-grandpa/src/lib.rs b/client/finality-grandpa/src/lib.rs index 656d8ea434349..c5bf9c7d45822 100644 --- a/client/finality-grandpa/src/lib.rs +++ b/client/finality-grandpa/src/lib.rs @@ -717,7 +717,7 @@ pub struct GrandpaParams { pub fn grandpa_peers_set_config() -> sc_network::config::NonDefaultSetConfig { sc_network::config::NonDefaultSetConfig { notifications_protocol: communication::GRANDPA_PROTOCOL_NAME.into(), - fallback_names: Vec::new(), + fallback_names: vec![communication::GRANDPA_PROTOCOL_LEGACY.into()], // Notifications reach ~256kiB in size at the time of writing on Kusama and Polkadot. max_notification_size: 1024 * 1024, set_config: sc_network::config::SetConfig { From fbf7cf5adfeda48bd598cffc3f7a3a08dbecede6 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Fri, 10 Dec 2021 11:23:46 +0200 Subject: [PATCH 02/19] grandpa: add chain id prefix to protocol name --- bin/node-template/node/src/service.rs | 8 +++++++- bin/node/cli/src/service.rs | 5 ++++- .../src/communication/gossip.rs | 1 + .../finality-grandpa/src/communication/mod.rs | 12 +++++++---- .../src/communication/tests.rs | 20 +++++++++++-------- client/finality-grandpa/src/lib.rs | 6 ++++-- client/finality-grandpa/src/tests.rs | 13 ++++++++++-- 7 files changed, 47 insertions(+), 18 deletions(-) diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index 92bd059e528a8..5acf8ba81157a 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -169,6 +169,8 @@ pub fn new_full(mut config: Configuration) -> Result transaction_pool, other: (block_import, grandpa_link, mut telemetry), } = new_partial(&config)?; + // TODO: add genesis hash. + let chain_prefix = format!("/{}", config.protocol_id().as_ref()); if let Some(url) = &config.keystore_remote { match remote_keystore(url) { @@ -181,7 +183,10 @@ pub fn new_full(mut config: Configuration) -> Result }; } - config.network.extra_sets.push(sc_finality_grandpa::grandpa_peers_set_config()); + config + .network + .extra_sets + .push(sc_finality_grandpa::grandpa_peers_set_config(&chain_prefix)); let warp_sync = Arc::new(sc_finality_grandpa::warp_proof::NetworkProvider::new( backend.clone(), grandpa_link.shared_authority_set().clone(), @@ -306,6 +311,7 @@ pub fn new_full(mut config: Configuration) -> Result keystore, local_role: role, telemetry: telemetry.as_ref().map(|x| x.handle()), + protocol_name_prefix: chain_prefix, }; if enable_grandpa { diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index fbc91c5f7d2e7..7b3449a7cfb85 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -326,8 +326,10 @@ 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; + // TODO: add genesis hash. + let chain_prefix = format!("/{}", config.protocol_id().as_ref()); - config.network.extra_sets.push(grandpa::grandpa_peers_set_config()); + config.network.extra_sets.push(grandpa::grandpa_peers_set_config(&chain_prefix)); let warp_sync = Arc::new(grandpa::warp_proof::NetworkProvider::new( backend.clone(), import_setup.1.shared_authority_set().clone(), @@ -488,6 +490,7 @@ pub fn new_full_base( keystore, local_role: role, telemetry: telemetry.as_ref().map(|x| x.handle()), + protocol_name_prefix: chain_prefix, }; if enable_grandpa { diff --git a/client/finality-grandpa/src/communication/gossip.rs b/client/finality-grandpa/src/communication/gossip.rs index 74e7cc5300654..37c393f566284 100644 --- a/client/finality-grandpa/src/communication/gossip.rs +++ b/client/finality-grandpa/src/communication/gossip.rs @@ -1682,6 +1682,7 @@ mod tests { local_role: Role::Authority, observer_enabled: true, telemetry: None, + protocol_name_prefix: "/test".into(), } } diff --git a/client/finality-grandpa/src/communication/mod.rs b/client/finality-grandpa/src/communication/mod.rs index 1fd3de2810c96..418ce3b31f76b 100644 --- a/client/finality-grandpa/src/communication/mod.rs +++ b/client/finality-grandpa/src/communication/mod.rs @@ -67,11 +67,14 @@ mod periodic; #[cfg(test)] pub(crate) mod tests; -/// Name of the notifications protocol used by Grandpa. Must be registered towards the networking -/// in order for Grandpa to properly function. -pub(crate) const GRANDPA_PROTOCOL_NAME: &'static str = "/substrate/grandpa/1"; +const GRANDPA_PROTOCOL_NAME: &'static str = "/grandpa/1"; /// Old name for the notifications protocol, still used for backward compatibility. pub(crate) const GRANDPA_PROTOCOL_LEGACY: &'static str = "/paritytech/grandpa/1"; +/// Name of the notifications protocol used by Grandpa. Must be registered towards the networking +/// in order for Grandpa to properly function. +pub(crate) fn grandpa_protocol_name(chain_prefix: &str) -> String { + format!("{}{}", chain_prefix, GRANDPA_PROTOCOL_NAME) +} // cost scalars for reporting peers. mod cost { @@ -222,13 +225,14 @@ impl> NetworkBridge { prometheus_registry: Option<&Registry>, telemetry: Option, ) -> Self { + let protocol = grandpa_protocol_name(&config.protocol_name_prefix); let (validator, report_stream) = GossipValidator::new(config, set_state.clone(), prometheus_registry, telemetry.clone()); let validator = Arc::new(validator); let gossip_engine = Arc::new(Mutex::new(GossipEngine::new( service.clone(), - GRANDPA_PROTOCOL_NAME, + protocol, validator.clone(), prometheus_registry, ))); diff --git a/client/finality-grandpa/src/communication/tests.rs b/client/finality-grandpa/src/communication/tests.rs index 1e88f8a934047..40bcc1dc13bf6 100644 --- a/client/finality-grandpa/src/communication/tests.rs +++ b/client/finality-grandpa/src/communication/tests.rs @@ -22,7 +22,7 @@ use super::{ gossip::{self, GossipValidator}, Round, SetId, VoterSet, }; -use crate::{communication::GRANDPA_PROTOCOL_NAME, environment::SharedVoterSetState}; +use crate::{communication::grandpa_protocol_name, environment::SharedVoterSetState}; use futures::prelude::*; use parity_scale_codec::Encode; use sc_network::{config::Role, Event as NetworkEvent, ObservedRole, PeerId}; @@ -97,7 +97,7 @@ impl sc_network_gossip::ValidatorContext for TestNetwork { >::write_notification( self, who.clone(), - GRANDPA_PROTOCOL_NAME.into(), + grandpa_protocol_name("/test").into(), data, ); } @@ -148,6 +148,7 @@ fn config() -> crate::Config { local_role: Role::Authority, observer_enabled: true, telemetry: None, + protocol_name_prefix: "/test".into(), } } @@ -286,7 +287,7 @@ fn good_commit_leads_to_relay() { // Add the sending peer and send the commit let _ = sender.unbounded_send(NetworkEvent::NotificationStreamOpened { remote: sender_id.clone(), - protocol: GRANDPA_PROTOCOL_NAME.into(), + protocol: grandpa_protocol_name("/test").into(), negotiated_fallback: None, role: ObservedRole::Full, }); @@ -294,7 +295,7 @@ fn good_commit_leads_to_relay() { let _ = sender.unbounded_send(NetworkEvent::NotificationsReceived { remote: sender_id.clone(), messages: vec![( - GRANDPA_PROTOCOL_NAME.into(), + grandpa_protocol_name("/test").into(), commit_to_send.clone().into(), )], }); @@ -303,7 +304,7 @@ fn good_commit_leads_to_relay() { let receiver_id = sc_network::PeerId::random(); let _ = sender.unbounded_send(NetworkEvent::NotificationStreamOpened { remote: receiver_id.clone(), - protocol: GRANDPA_PROTOCOL_NAME.into(), + protocol: grandpa_protocol_name("/test").into(), negotiated_fallback: None, role: ObservedRole::Full, }); @@ -321,7 +322,10 @@ fn good_commit_leads_to_relay() { sender.unbounded_send(NetworkEvent::NotificationsReceived { remote: receiver_id, - messages: vec![(GRANDPA_PROTOCOL_NAME.into(), msg.encode().into())], + messages: vec![( + grandpa_protocol_name("/test").into(), + msg.encode().into(), + )], }) }; @@ -433,14 +437,14 @@ fn bad_commit_leads_to_report() { Event::EventStream(sender) => { let _ = sender.unbounded_send(NetworkEvent::NotificationStreamOpened { remote: sender_id.clone(), - protocol: GRANDPA_PROTOCOL_NAME.into(), + protocol: grandpa_protocol_name("/test").into(), negotiated_fallback: None, role: ObservedRole::Full, }); let _ = sender.unbounded_send(NetworkEvent::NotificationsReceived { remote: sender_id.clone(), messages: vec![( - GRANDPA_PROTOCOL_NAME.into(), + grandpa_protocol_name("/test").into(), commit_to_send.clone().into(), )], }); diff --git a/client/finality-grandpa/src/lib.rs b/client/finality-grandpa/src/lib.rs index c5bf9c7d45822..6fe2ff7aeac44 100644 --- a/client/finality-grandpa/src/lib.rs +++ b/client/finality-grandpa/src/lib.rs @@ -263,6 +263,8 @@ pub struct Config { pub keystore: Option, /// TelemetryHandle instance. pub telemetry: Option, + /// Protocol name prefix - usually chain ID and genesis truncated hash. + pub protocol_name_prefix: String, } impl Config { @@ -714,9 +716,9 @@ pub struct GrandpaParams { /// Returns the configuration value to put in /// [`sc_network::config::NetworkConfiguration::extra_sets`]. -pub fn grandpa_peers_set_config() -> sc_network::config::NonDefaultSetConfig { +pub fn grandpa_peers_set_config(chain_prefix: &str) -> sc_network::config::NonDefaultSetConfig { sc_network::config::NonDefaultSetConfig { - notifications_protocol: communication::GRANDPA_PROTOCOL_NAME.into(), + notifications_protocol: communication::grandpa_protocol_name(chain_prefix).into(), fallback_names: vec![communication::GRANDPA_PROTOCOL_LEGACY.into()], // Notifications reach ~256kiB in size at the time of writing on Kusama and Polkadot. max_notification_size: 1024 * 1024, diff --git a/client/finality-grandpa/src/tests.rs b/client/finality-grandpa/src/tests.rs index 7af02d066be32..ef69d4a92d56a 100644 --- a/client/finality-grandpa/src/tests.rs +++ b/client/finality-grandpa/src/tests.rs @@ -97,7 +97,7 @@ impl GrandpaTestNet { impl GrandpaTestNet { fn add_authority_peer(&mut self) { self.add_full_peer_with_config(FullPeerConfig { - notifications_protocols: vec![communication::GRANDPA_PROTOCOL_NAME.into()], + notifications_protocols: vec![communication::grandpa_protocol_name("/test").into()], is_authority: true, ..Default::default() }) @@ -121,7 +121,7 @@ impl TestNetFactory for GrandpaTestNet { fn add_full_peer(&mut self) { self.add_full_peer_with_config(FullPeerConfig { - notifications_protocols: vec![communication::GRANDPA_PROTOCOL_NAME.into()], + notifications_protocols: vec![communication::grandpa_protocol_name("/test").into()], is_authority: false, ..Default::default() }) @@ -274,6 +274,7 @@ fn initialize_grandpa( local_role: Role::Authority, observer_enabled: true, telemetry: None, + protocol_name_prefix: "/test".into(), }, link, network: net_service, @@ -423,6 +424,7 @@ fn finalize_3_voters_1_full_observer() { local_role: Role::Authority, observer_enabled: true, telemetry: None, + protocol_name_prefix: "/test".into(), }, link, network: net_service, @@ -513,6 +515,7 @@ fn transition_3_voters_twice_1_full_observer() { local_role: Role::Authority, observer_enabled: true, telemetry: None, + protocol_name_prefix: "/test".into(), }, link, network: net_service, @@ -971,6 +974,7 @@ fn voter_persists_its_votes() { local_role: Role::Authority, observer_enabled: true, telemetry: None, + protocol_name_prefix: "/test".into(), }; let set_state = { @@ -1010,6 +1014,7 @@ fn voter_persists_its_votes() { local_role: Role::Authority, observer_enabled: true, telemetry: None, + protocol_name_prefix: "/test".into(), }, link, network: net_service, @@ -1050,6 +1055,7 @@ fn voter_persists_its_votes() { local_role: Role::Authority, observer_enabled: true, telemetry: None, + protocol_name_prefix: "/test".into(), }, link, network: net_service, @@ -1213,6 +1219,7 @@ fn finalize_3_voters_1_light_observer() { local_role: Role::Full, observer_enabled: true, telemetry: None, + protocol_name_prefix: "/test".into(), }, net.peers[3].data.lock().take().expect("link initialized at startup; qed"), net.peers[3].network_service().clone(), @@ -1259,6 +1266,7 @@ fn voter_catches_up_to_latest_round_when_behind() { local_role: Role::Authority, observer_enabled: true, telemetry: None, + protocol_name_prefix: "/test".into(), }, link, network: net.lock().peer(peer_id).network_service().clone(), @@ -1376,6 +1384,7 @@ where local_role: Role::Authority, observer_enabled: true, telemetry: None, + protocol_name_prefix: "/test".into(), }; let network = From 2b2276275f9df49303fe43828c754778a22176bd Mon Sep 17 00:00:00 2001 From: acatangiu Date: Fri, 10 Dec 2021 13:00:22 +0200 Subject: [PATCH 03/19] grandpa: beautify protocol name handling --- .../finality-grandpa/src/communication/mod.rs | 26 +++++++++++++------ .../src/communication/tests.rs | 16 ++++++------ client/finality-grandpa/src/lib.rs | 5 ++-- client/finality-grandpa/src/tests.rs | 4 +-- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/client/finality-grandpa/src/communication/mod.rs b/client/finality-grandpa/src/communication/mod.rs index 418ce3b31f76b..393371eea4dfb 100644 --- a/client/finality-grandpa/src/communication/mod.rs +++ b/client/finality-grandpa/src/communication/mod.rs @@ -67,13 +67,23 @@ mod periodic; #[cfg(test)] pub(crate) mod tests; -const GRANDPA_PROTOCOL_NAME: &'static str = "/grandpa/1"; -/// Old name for the notifications protocol, still used for backward compatibility. -pub(crate) const GRANDPA_PROTOCOL_LEGACY: &'static str = "/paritytech/grandpa/1"; -/// Name of the notifications protocol used by Grandpa. Must be registered towards the networking -/// in order for Grandpa to properly function. -pub(crate) fn grandpa_protocol_name(chain_prefix: &str) -> String { - format!("{}{}", chain_prefix, GRANDPA_PROTOCOL_NAME) +pub(crate) struct GrandpaProtocolName {} +impl GrandpaProtocolName { + const NAME: &'static str = "/grandpa/1"; + /// Old names for the notifications protocol, used for backward compatibility. + pub const LEGACY_NAMES: [&'static str; 1] = ["/paritytech/grandpa/1"]; + + /// Name of the notifications protocol used by Grandpa. + /// Must be registered towards the networking in order for Grandpa to properly function. + pub fn with_prefix(prefix: &str) -> String { + format!("{}{}", prefix, Self::NAME) + } + + #[cfg(test)] + /// Protocol name used in tests. + pub fn test_name() -> String { + format!("/test{}", Self::NAME) + } } // cost scalars for reporting peers. @@ -225,7 +235,7 @@ impl> NetworkBridge { prometheus_registry: Option<&Registry>, telemetry: Option, ) -> Self { - let protocol = grandpa_protocol_name(&config.protocol_name_prefix); + let protocol = GrandpaProtocolName::with_prefix(&config.protocol_name_prefix); let (validator, report_stream) = GossipValidator::new(config, set_state.clone(), prometheus_registry, telemetry.clone()); diff --git a/client/finality-grandpa/src/communication/tests.rs b/client/finality-grandpa/src/communication/tests.rs index 40bcc1dc13bf6..fbb4867e180db 100644 --- a/client/finality-grandpa/src/communication/tests.rs +++ b/client/finality-grandpa/src/communication/tests.rs @@ -22,7 +22,7 @@ use super::{ gossip::{self, GossipValidator}, Round, SetId, VoterSet, }; -use crate::{communication::grandpa_protocol_name, environment::SharedVoterSetState}; +use crate::{communication::GrandpaProtocolName, environment::SharedVoterSetState}; use futures::prelude::*; use parity_scale_codec::Encode; use sc_network::{config::Role, Event as NetworkEvent, ObservedRole, PeerId}; @@ -97,7 +97,7 @@ impl sc_network_gossip::ValidatorContext for TestNetwork { >::write_notification( self, who.clone(), - grandpa_protocol_name("/test").into(), + GrandpaProtocolName::test_name().into(), data, ); } @@ -287,7 +287,7 @@ fn good_commit_leads_to_relay() { // Add the sending peer and send the commit let _ = sender.unbounded_send(NetworkEvent::NotificationStreamOpened { remote: sender_id.clone(), - protocol: grandpa_protocol_name("/test").into(), + protocol: GrandpaProtocolName::test_name().into(), negotiated_fallback: None, role: ObservedRole::Full, }); @@ -295,7 +295,7 @@ fn good_commit_leads_to_relay() { let _ = sender.unbounded_send(NetworkEvent::NotificationsReceived { remote: sender_id.clone(), messages: vec![( - grandpa_protocol_name("/test").into(), + GrandpaProtocolName::test_name().into(), commit_to_send.clone().into(), )], }); @@ -304,7 +304,7 @@ fn good_commit_leads_to_relay() { let receiver_id = sc_network::PeerId::random(); let _ = sender.unbounded_send(NetworkEvent::NotificationStreamOpened { remote: receiver_id.clone(), - protocol: grandpa_protocol_name("/test").into(), + protocol: GrandpaProtocolName::test_name().into(), negotiated_fallback: None, role: ObservedRole::Full, }); @@ -323,7 +323,7 @@ fn good_commit_leads_to_relay() { sender.unbounded_send(NetworkEvent::NotificationsReceived { remote: receiver_id, messages: vec![( - grandpa_protocol_name("/test").into(), + GrandpaProtocolName::test_name().into(), msg.encode().into(), )], }) @@ -437,14 +437,14 @@ fn bad_commit_leads_to_report() { Event::EventStream(sender) => { let _ = sender.unbounded_send(NetworkEvent::NotificationStreamOpened { remote: sender_id.clone(), - protocol: grandpa_protocol_name("/test").into(), + protocol: GrandpaProtocolName::test_name().into(), negotiated_fallback: None, role: ObservedRole::Full, }); let _ = sender.unbounded_send(NetworkEvent::NotificationsReceived { remote: sender_id.clone(), messages: vec![( - grandpa_protocol_name("/test").into(), + GrandpaProtocolName::test_name().into(), commit_to_send.clone().into(), )], }); diff --git a/client/finality-grandpa/src/lib.rs b/client/finality-grandpa/src/lib.rs index 6fe2ff7aeac44..f371d22b76001 100644 --- a/client/finality-grandpa/src/lib.rs +++ b/client/finality-grandpa/src/lib.rs @@ -717,9 +717,10 @@ pub struct GrandpaParams { /// Returns the configuration value to put in /// [`sc_network::config::NetworkConfiguration::extra_sets`]. pub fn grandpa_peers_set_config(chain_prefix: &str) -> sc_network::config::NonDefaultSetConfig { + use communication::GrandpaProtocolName; sc_network::config::NonDefaultSetConfig { - notifications_protocol: communication::grandpa_protocol_name(chain_prefix).into(), - fallback_names: vec![communication::GRANDPA_PROTOCOL_LEGACY.into()], + notifications_protocol: GrandpaProtocolName::with_prefix(chain_prefix).into(), + fallback_names: GrandpaProtocolName::LEGACY_NAMES.iter().map(|&n| n.into()).collect(), // Notifications reach ~256kiB in size at the time of writing on Kusama and Polkadot. max_notification_size: 1024 * 1024, set_config: sc_network::config::SetConfig { diff --git a/client/finality-grandpa/src/tests.rs b/client/finality-grandpa/src/tests.rs index ef69d4a92d56a..87e90d533bb5e 100644 --- a/client/finality-grandpa/src/tests.rs +++ b/client/finality-grandpa/src/tests.rs @@ -97,7 +97,7 @@ impl GrandpaTestNet { impl GrandpaTestNet { fn add_authority_peer(&mut self) { self.add_full_peer_with_config(FullPeerConfig { - notifications_protocols: vec![communication::grandpa_protocol_name("/test").into()], + notifications_protocols: vec![communication::GrandpaProtocolName::test_name().into()], is_authority: true, ..Default::default() }) @@ -121,7 +121,7 @@ impl TestNetFactory for GrandpaTestNet { fn add_full_peer(&mut self) { self.add_full_peer_with_config(FullPeerConfig { - notifications_protocols: vec![communication::grandpa_protocol_name("/test").into()], + notifications_protocols: vec![communication::GrandpaProtocolName::test_name().into()], is_authority: false, ..Default::default() }) From 206beaa2dad44c310a857cf41e6799993007b12e Mon Sep 17 00:00:00 2001 From: acatangiu Date: Fri, 10 Dec 2021 14:00:27 +0200 Subject: [PATCH 04/19] grandpa: prepend genesis hash to protocol name --- bin/node-template/node/src/service.rs | 6 +++--- bin/node/cli/src/service.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index 5acf8ba81157a..5118fe30b5b21 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -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; @@ -169,8 +169,8 @@ pub fn new_full(mut config: Configuration) -> Result transaction_pool, other: (block_import, grandpa_link, mut telemetry), } = new_partial(&config)?; - // TODO: add genesis hash. - let chain_prefix = format!("/{}", config.protocol_id().as_ref()); + let genesis_hash = client.block_hash(0).ok().flatten().unwrap_or_default(); + let chain_prefix = format!("/{}/{}", config.protocol_id().as_ref(), genesis_hash); if let Some(url) = &config.keystore_remote { match remote_keystore(url) { diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index 7b3449a7cfb85..e945ecb868d03 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -326,8 +326,8 @@ 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; - // TODO: add genesis hash. - let chain_prefix = format!("/{}", config.protocol_id().as_ref()); + let genesis_hash = client.block_hash(0).ok().flatten().unwrap_or_default(); + let chain_prefix = format!("/{}/{}", config.protocol_id().as_ref(), genesis_hash); config.network.extra_sets.push(grandpa::grandpa_peers_set_config(&chain_prefix)); let warp_sync = Arc::new(grandpa::warp_proof::NetworkProvider::new( From 952e0a7f7e246f77ec1d74addc9617d2f38bd102 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Mon, 13 Dec 2021 14:15:53 +0200 Subject: [PATCH 05/19] chain-spec: add optional 'fork_id' 'fork_id' is used to uniquely identify forks of the same chain/network 'ChainSpec' trait provides default 'None' implementation, meaning this chain hasn't been forked. --- bin/node-template/node/src/service.rs | 5 ++++- bin/node/cli/src/service.rs | 5 ++++- client/chain-spec/src/lib.rs | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index 5118fe30b5b21..6a816821d2f75 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -170,7 +170,10 @@ pub fn new_full(mut config: Configuration) -> Result other: (block_import, grandpa_link, mut telemetry), } = new_partial(&config)?; let genesis_hash = client.block_hash(0).ok().flatten().unwrap_or_default(); - let chain_prefix = format!("/{}/{}", config.protocol_id().as_ref(), genesis_hash); + let chain_prefix = match config.chain_spec.fork_id() { + Some(fork_id) => format!("/{}/{}", genesis_hash, fork_id), + None => format!("/{}", genesis_hash), + }; if let Some(url) = &config.keystore_remote { match remote_keystore(url) { diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index e945ecb868d03..f412f0a83ae70 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -327,7 +327,10 @@ 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 genesis_hash = client.block_hash(0).ok().flatten().unwrap_or_default(); - let chain_prefix = format!("/{}/{}", config.protocol_id().as_ref(), genesis_hash); + let chain_prefix = match config.chain_spec.fork_id() { + Some(fork_id) => format!("/{}/{}", genesis_hash, fork_id), + None => format!("/{}", genesis_hash), + }; config.network.extra_sets.push(grandpa::grandpa_peers_set_config(&chain_prefix)); let warp_sync = Arc::new(grandpa::warp_proof::NetworkProvider::new( diff --git a/client/chain-spec/src/lib.rs b/client/chain-spec/src/lib.rs index 334d8f8b3d7ac..ee24744b16f9d 100644 --- a/client/chain-spec/src/lib.rs +++ b/client/chain-spec/src/lib.rs @@ -165,6 +165,10 @@ pub trait ChainSpec: BuildStorage + Send + Sync { fn telemetry_endpoints(&self) -> &Option; /// Network protocol id. fn protocol_id(&self) -> Option<&str>; + /// Optional network fork identifier. `None` by default. + fn fork_id(&self) -> Option<&str> { + None + } /// Additional loosly-typed properties of the chain. /// /// Returns an empty JSON object if 'properties' not defined in config From 758ff8483d61e75e07f90ff65f756d6f8d8cddc6 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Mon, 13 Dec 2021 17:44:39 +0200 Subject: [PATCH 06/19] grandpa: protocol_name mod instead of struct --- client/finality-grandpa/src/communication/mod.rs | 9 ++++----- client/finality-grandpa/src/lib.rs | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/client/finality-grandpa/src/communication/mod.rs b/client/finality-grandpa/src/communication/mod.rs index 393371eea4dfb..354feb0bfa2f8 100644 --- a/client/finality-grandpa/src/communication/mod.rs +++ b/client/finality-grandpa/src/communication/mod.rs @@ -67,8 +67,7 @@ mod periodic; #[cfg(test)] pub(crate) mod tests; -pub(crate) struct GrandpaProtocolName {} -impl GrandpaProtocolName { +pub(crate) mod grandpa_protocol_name { const NAME: &'static str = "/grandpa/1"; /// Old names for the notifications protocol, used for backward compatibility. pub const LEGACY_NAMES: [&'static str; 1] = ["/paritytech/grandpa/1"]; @@ -76,13 +75,13 @@ impl GrandpaProtocolName { /// Name of the notifications protocol used by Grandpa. /// Must be registered towards the networking in order for Grandpa to properly function. pub fn with_prefix(prefix: &str) -> String { - format!("{}{}", prefix, Self::NAME) + format!("{}{}", prefix, NAME) } #[cfg(test)] /// Protocol name used in tests. pub fn test_name() -> String { - format!("/test{}", Self::NAME) + format!("/test{}", NAME) } } @@ -235,7 +234,7 @@ impl> NetworkBridge { prometheus_registry: Option<&Registry>, telemetry: Option, ) -> Self { - let protocol = GrandpaProtocolName::with_prefix(&config.protocol_name_prefix); + let protocol = grandpa_protocol_name::with_prefix(&config.protocol_name_prefix); let (validator, report_stream) = GossipValidator::new(config, set_state.clone(), prometheus_registry, telemetry.clone()); diff --git a/client/finality-grandpa/src/lib.rs b/client/finality-grandpa/src/lib.rs index f371d22b76001..02320980557d1 100644 --- a/client/finality-grandpa/src/lib.rs +++ b/client/finality-grandpa/src/lib.rs @@ -263,7 +263,7 @@ pub struct Config { pub keystore: Option, /// TelemetryHandle instance. pub telemetry: Option, - /// Protocol name prefix - usually chain ID and genesis truncated hash. + /// Protocol name prefix - usually genesis hash and optional fork id. pub protocol_name_prefix: String, } @@ -717,10 +717,10 @@ pub struct GrandpaParams { /// Returns the configuration value to put in /// [`sc_network::config::NetworkConfiguration::extra_sets`]. pub fn grandpa_peers_set_config(chain_prefix: &str) -> sc_network::config::NonDefaultSetConfig { - use communication::GrandpaProtocolName; + use communication::grandpa_protocol_name; sc_network::config::NonDefaultSetConfig { - notifications_protocol: GrandpaProtocolName::with_prefix(chain_prefix).into(), - fallback_names: GrandpaProtocolName::LEGACY_NAMES.iter().map(|&n| n.into()).collect(), + notifications_protocol: grandpa_protocol_name::with_prefix(chain_prefix).into(), + fallback_names: grandpa_protocol_name::LEGACY_NAMES.iter().map(|&n| n.into()).collect(), // Notifications reach ~256kiB in size at the time of writing on Kusama and Polkadot. max_notification_size: 1024 * 1024, set_config: sc_network::config::SetConfig { From b3a02437ea8cc96ae009115049bef2839f2a34fc Mon Sep 17 00:00:00 2001 From: acatangiu Date: Mon, 13 Dec 2021 17:45:49 +0200 Subject: [PATCH 07/19] beefy: add genesis hash prefix to protocol name --- client/beefy/src/lib.rs | 29 +++++++++++++++++++++++------ client/network/src/config.rs | 5 +++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/client/beefy/src/lib.rs b/client/beefy/src/lib.rs index b2372b2a6c518..b6be2b4c62601 100644 --- a/client/beefy/src/lib.rs +++ b/client/beefy/src/lib.rs @@ -40,14 +40,28 @@ mod worker; pub mod notification; -pub const BEEFY_PROTOCOL_NAME: &str = "/paritytech/beefy/1"; +pub(crate) mod beefy_protocol_name { + const NAME: &'static str = "/beefy/1"; + /// Old names for the notifications protocol, used for backward compatibility. + pub 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 with_prefix(prefix: &str) -> String { + format!("{}{}", prefix, NAME) + } +} /// 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); +pub fn beefy_peers_set_config(chain_prefix: &str) -> sc_network::config::NonDefaultSetConfig { + let mut cfg = sc_network::config::NonDefaultSetConfig::new( + beefy_protocol_name::with_prefix(chain_prefix).into(), + 1024 * 1024, + ); + cfg.allow_non_reserved(25, 25); + cfg.add_fallback_names(beefy_protocol_name::LEGACY_NAMES.iter().map(|&n| n.into()).collect()); cfg } @@ -101,6 +115,8 @@ where pub min_block_delta: u32, /// Prometheus metric registry pub prometheus_registry: Option, + /// Protocol name prefix - usually genesis hash and optional fork id. + pub protocol_name_prefix: String, } /// Start the BEEFY gadget. @@ -122,11 +138,12 @@ where signed_commitment_sender, min_block_delta, prometheus_registry, + protocol_name_prefix, } = beefy_params; + let protocol_name = beefy_protocol_name::with_prefix(&protocol_name_prefix); 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( diff --git a/client/network/src/config.rs b/client/network/src/config.rs index 8ef52e46fd071..4b022a2ae9829 100644 --- a/client/network/src/config.rs +++ b/client/network/src/config.rs @@ -603,6 +603,11 @@ impl NonDefaultSetConfig { pub fn add_reserved(&mut self, peer: MultiaddrWithPeerId) { self.set_config.reserved_nodes.push(peer); } + + /// Add a list of protocol names used for backward compatibility. + pub fn add_fallback_names(&mut self, fallback_names: Vec>) { + self.fallback_names.extend(fallback_names); + } } /// Configuration for the transport layer. From 44baf42c33440c2778df0dff36d0f1c8ca3f8ea0 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Tue, 14 Dec 2021 11:56:51 +0200 Subject: [PATCH 08/19] chainspec: add fork_id --- bin/node-template/node/src/chain_spec.rs | 2 ++ bin/node/cli/src/chain_spec.rs | 5 +++++ bin/utils/chain-spec-builder/src/main.rs | 1 + client/chain-spec/src/chain_spec.rs | 12 ++++++++++++ client/chain-spec/src/lib.rs | 4 +--- client/cli/src/commands/insert_key.rs | 1 + 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/bin/node-template/node/src/chain_spec.rs b/bin/node-template/node/src/chain_spec.rs index af94a63335e0e..ef34ec369a77f 100644 --- a/bin/node-template/node/src/chain_spec.rs +++ b/bin/node-template/node/src/chain_spec.rs @@ -68,6 +68,7 @@ pub fn development_config() -> Result { None, // Protocol ID None, + None, // Properties None, // Extensions @@ -117,6 +118,7 @@ pub fn local_testnet_config() -> Result { None, // Properties None, + None, // Extensions None, )) diff --git a/bin/node/cli/src/chain_spec.rs b/bin/node/cli/src/chain_spec.rs index b29248519cc08..6b80039559f12 100644 --- a/bin/node/cli/src/chain_spec.rs +++ b/bin/node/cli/src/chain_spec.rs @@ -196,6 +196,7 @@ pub fn staging_testnet_config() -> ChainSpec { ), None, None, + None, Default::default(), ) } @@ -386,6 +387,7 @@ pub fn development_config() -> ChainSpec { None, None, None, + None, Default::default(), ) } @@ -410,6 +412,7 @@ pub fn local_testnet_config() -> ChainSpec { None, None, None, + None, Default::default(), ) } @@ -441,6 +444,7 @@ pub(crate) mod tests { None, None, None, + None, Default::default(), ) } @@ -456,6 +460,7 @@ pub(crate) mod tests { None, None, None, + None, Default::default(), ) } diff --git a/bin/utils/chain-spec-builder/src/main.rs b/bin/utils/chain-spec-builder/src/main.rs index f45031f1eb811..a30ed2e81bb27 100644 --- a/bin/utils/chain-spec-builder/src/main.rs +++ b/bin/utils/chain-spec-builder/src/main.rs @@ -155,6 +155,7 @@ fn generate_chain_spec( None, None, None, + None, Default::default(), ); diff --git a/client/chain-spec/src/chain_spec.rs b/client/chain-spec/src/chain_spec.rs index e8247d7314991..0b9eee9135211 100644 --- a/client/chain-spec/src/chain_spec.rs +++ b/client/chain-spec/src/chain_spec.rs @@ -164,6 +164,7 @@ struct ClientSpec { boot_nodes: Vec, telemetry_endpoints: Option, protocol_id: Option, + fork_id: Option, properties: Option, #[serde(flatten)] extensions: E, @@ -226,6 +227,11 @@ impl ChainSpec { 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 @@ -257,6 +263,7 @@ impl ChainSpec { boot_nodes: Vec, telemetry_endpoints: Option, protocol_id: Option<&str>, + fork_id: Option<&str>, properties: Option, extensions: E, ) -> Self { @@ -267,6 +274,7 @@ impl ChainSpec { boot_nodes, telemetry_endpoints, protocol_id: protocol_id.map(str::to_owned), + fork_id: fork_id.map(str::to_owned), properties, extensions, consensus_engine: (), @@ -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) } diff --git a/client/chain-spec/src/lib.rs b/client/chain-spec/src/lib.rs index ee24744b16f9d..50718ad0cea0b 100644 --- a/client/chain-spec/src/lib.rs +++ b/client/chain-spec/src/lib.rs @@ -166,9 +166,7 @@ pub trait ChainSpec: BuildStorage + Send + Sync { /// Network protocol id. fn protocol_id(&self) -> Option<&str>; /// Optional network fork identifier. `None` by default. - fn fork_id(&self) -> Option<&str> { - None - } + fn fork_id(&self) -> Option<&str>; /// Additional loosly-typed properties of the chain. /// /// Returns an empty JSON object if 'properties' not defined in config diff --git a/client/cli/src/commands/insert_key.rs b/client/cli/src/commands/insert_key.rs index e85b85f111ad5..73fc4a96456bf 100644 --- a/client/cli/src/commands/insert_key.rs +++ b/client/cli/src/commands/insert_key.rs @@ -144,6 +144,7 @@ mod tests { None, None, None, + None, NoExtension::None, ))) } From 0f9d6cc2a9be008c69aaece7586148a890ca7f83 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Tue, 14 Dec 2021 12:07:22 +0200 Subject: [PATCH 09/19] grandpa: simplify protocol name --- client/finality-grandpa/src/communication/mod.rs | 8 +------- .../finality-grandpa/src/communication/tests.rs | 16 ++++++++-------- client/finality-grandpa/src/tests.rs | 4 ++-- client/network/src/config.rs | 2 ++ 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/client/finality-grandpa/src/communication/mod.rs b/client/finality-grandpa/src/communication/mod.rs index 354feb0bfa2f8..575b4c4bb8e49 100644 --- a/client/finality-grandpa/src/communication/mod.rs +++ b/client/finality-grandpa/src/communication/mod.rs @@ -68,7 +68,7 @@ mod periodic; pub(crate) mod tests; pub(crate) mod grandpa_protocol_name { - const NAME: &'static str = "/grandpa/1"; + pub(crate) const NAME: &'static str = "/grandpa/1"; /// Old names for the notifications protocol, used for backward compatibility. pub const LEGACY_NAMES: [&'static str; 1] = ["/paritytech/grandpa/1"]; @@ -77,12 +77,6 @@ pub(crate) mod grandpa_protocol_name { pub fn with_prefix(prefix: &str) -> String { format!("{}{}", prefix, NAME) } - - #[cfg(test)] - /// Protocol name used in tests. - pub fn test_name() -> String { - format!("/test{}", NAME) - } } // cost scalars for reporting peers. diff --git a/client/finality-grandpa/src/communication/tests.rs b/client/finality-grandpa/src/communication/tests.rs index fbb4867e180db..b8970bf332643 100644 --- a/client/finality-grandpa/src/communication/tests.rs +++ b/client/finality-grandpa/src/communication/tests.rs @@ -22,7 +22,7 @@ use super::{ gossip::{self, GossipValidator}, Round, SetId, VoterSet, }; -use crate::{communication::GrandpaProtocolName, environment::SharedVoterSetState}; +use crate::{communication::grandpa_protocol_name, environment::SharedVoterSetState}; use futures::prelude::*; use parity_scale_codec::Encode; use sc_network::{config::Role, Event as NetworkEvent, ObservedRole, PeerId}; @@ -97,7 +97,7 @@ impl sc_network_gossip::ValidatorContext for TestNetwork { >::write_notification( self, who.clone(), - GrandpaProtocolName::test_name().into(), + grandpa_protocol_name::NAME.into(), data, ); } @@ -287,7 +287,7 @@ fn good_commit_leads_to_relay() { // Add the sending peer and send the commit let _ = sender.unbounded_send(NetworkEvent::NotificationStreamOpened { remote: sender_id.clone(), - protocol: GrandpaProtocolName::test_name().into(), + protocol: grandpa_protocol_name::NAME.into(), negotiated_fallback: None, role: ObservedRole::Full, }); @@ -295,7 +295,7 @@ fn good_commit_leads_to_relay() { let _ = sender.unbounded_send(NetworkEvent::NotificationsReceived { remote: sender_id.clone(), messages: vec![( - GrandpaProtocolName::test_name().into(), + grandpa_protocol_name::NAME.into(), commit_to_send.clone().into(), )], }); @@ -304,7 +304,7 @@ fn good_commit_leads_to_relay() { let receiver_id = sc_network::PeerId::random(); let _ = sender.unbounded_send(NetworkEvent::NotificationStreamOpened { remote: receiver_id.clone(), - protocol: GrandpaProtocolName::test_name().into(), + protocol: grandpa_protocol_name::NAME.into(), negotiated_fallback: None, role: ObservedRole::Full, }); @@ -323,7 +323,7 @@ fn good_commit_leads_to_relay() { sender.unbounded_send(NetworkEvent::NotificationsReceived { remote: receiver_id, messages: vec![( - GrandpaProtocolName::test_name().into(), + grandpa_protocol_name::NAME.into(), msg.encode().into(), )], }) @@ -437,14 +437,14 @@ fn bad_commit_leads_to_report() { Event::EventStream(sender) => { let _ = sender.unbounded_send(NetworkEvent::NotificationStreamOpened { remote: sender_id.clone(), - protocol: GrandpaProtocolName::test_name().into(), + protocol: grandpa_protocol_name::NAME.into(), negotiated_fallback: None, role: ObservedRole::Full, }); let _ = sender.unbounded_send(NetworkEvent::NotificationsReceived { remote: sender_id.clone(), messages: vec![( - GrandpaProtocolName::test_name().into(), + grandpa_protocol_name::NAME.into(), commit_to_send.clone().into(), )], }); diff --git a/client/finality-grandpa/src/tests.rs b/client/finality-grandpa/src/tests.rs index 87e90d533bb5e..1c9ea586ae3a7 100644 --- a/client/finality-grandpa/src/tests.rs +++ b/client/finality-grandpa/src/tests.rs @@ -97,7 +97,7 @@ impl GrandpaTestNet { impl GrandpaTestNet { fn add_authority_peer(&mut self) { self.add_full_peer_with_config(FullPeerConfig { - notifications_protocols: vec![communication::GrandpaProtocolName::test_name().into()], + notifications_protocols: vec![communication::grandpa_protocol_name::NAME.into()], is_authority: true, ..Default::default() }) @@ -121,7 +121,7 @@ impl TestNetFactory for GrandpaTestNet { fn add_full_peer(&mut self) { self.add_full_peer_with_config(FullPeerConfig { - notifications_protocols: vec![communication::GrandpaProtocolName::test_name().into()], + notifications_protocols: vec![communication::grandpa_protocol_name::NAME.into()], is_authority: false, ..Default::default() }) diff --git a/client/network/src/config.rs b/client/network/src/config.rs index 4b022a2ae9829..186401f64092d 100644 --- a/client/network/src/config.rs +++ b/client/network/src/config.rs @@ -605,6 +605,8 @@ impl NonDefaultSetConfig { } /// Add a list of protocol names used for backward compatibility. + /// + /// See the explanations in [`NonDefaultSetConfig::fallback_names`]. pub fn add_fallback_names(&mut self, fallback_names: Vec>) { self.fallback_names.extend(fallback_names); } From 482f0bc73400f4d92c14c5a14b75414dd624dd42 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Thu, 16 Dec 2021 10:16:56 +0200 Subject: [PATCH 10/19] grandpa: contain protocol name building logic --- Cargo.lock | 1 + bin/node-template/node/src/service.rs | 13 ++++++------- bin/node/cli/src/service.rs | 16 +++++++++------- client/finality-grandpa/Cargo.toml | 1 + .../finality-grandpa/src/communication/mod.rs | 19 ++++++++++++++----- client/finality-grandpa/src/lib.rs | 12 ++++++++---- 6 files changed, 39 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b576a12ea6f65..e206e191a6634 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8141,6 +8141,7 @@ dependencies = [ "parking_lot 0.11.1", "rand 0.8.4", "sc-block-builder", + "sc-chain-spec", "sc-client-api", "sc-consensus", "sc-keystore", diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index 6a816821d2f75..a575876aced64 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -169,11 +169,6 @@ pub fn new_full(mut config: Configuration) -> Result transaction_pool, other: (block_import, grandpa_link, mut telemetry), } = new_partial(&config)?; - let genesis_hash = client.block_hash(0).ok().flatten().unwrap_or_default(); - let chain_prefix = match config.chain_spec.fork_id() { - Some(fork_id) => format!("/{}/{}", genesis_hash, fork_id), - None => format!("/{}", genesis_hash), - }; if let Some(url) = &config.keystore_remote { match remote_keystore(url) { @@ -185,11 +180,15 @@ pub fn new_full(mut config: Configuration) -> Result ))), }; } + let grandpa_protocol_name = sc_finality_grandpa::protocol_standard_name( + &client.block_hash(0).ok().flatten().unwrap_or_default(), + &config.chain_spec, + ); config .network .extra_sets - .push(sc_finality_grandpa::grandpa_peers_set_config(&chain_prefix)); + .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(), @@ -314,7 +313,7 @@ pub fn new_full(mut config: Configuration) -> Result keystore, local_role: role, telemetry: telemetry.as_ref().map(|x| x.handle()), - protocol_name_prefix: chain_prefix, + protocol_name: grandpa_protocol_name, }; if enable_grandpa { diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index f412f0a83ae70..dbcd501d6683c 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -326,13 +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 genesis_hash = client.block_hash(0).ok().flatten().unwrap_or_default(); - let chain_prefix = match config.chain_spec.fork_id() { - Some(fork_id) => format!("/{}/{}", genesis_hash, fork_id), - None => format!("/{}", genesis_hash), - }; + let grandpa_protocol_name = grandpa::protocol_standard_name( + &client.block_hash(0).ok().flatten().unwrap_or_default(), + &config.chain_spec, + ); - config.network.extra_sets.push(grandpa::grandpa_peers_set_config(&chain_prefix)); + 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(), @@ -493,7 +495,7 @@ pub fn new_full_base( keystore, local_role: role, telemetry: telemetry.as_ref().map(|x| x.handle()), - protocol_name_prefix: chain_prefix, + protocol_name: grandpa_protocol_name, }; if enable_grandpa { diff --git a/client/finality-grandpa/Cargo.toml b/client/finality-grandpa/Cargo.toml index 12aedbfe0143b..e6f4184b4498a 100644 --- a/client/finality-grandpa/Cargo.toml +++ b/client/finality-grandpa/Cargo.toml @@ -27,6 +27,7 @@ parity-scale-codec = { version = "2.3.1", features = ["derive"] } sp-application-crypto = { version = "4.0.0-dev", path = "../../primitives/application-crypto" } sp-arithmetic = { version = "4.0.0-dev", path = "../../primitives/arithmetic" } sp-runtime = { version = "4.0.0-dev", 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" } diff --git a/client/finality-grandpa/src/communication/mod.rs b/client/finality-grandpa/src/communication/mod.rs index 575b4c4bb8e49..f4e7d09992d52 100644 --- a/client/finality-grandpa/src/communication/mod.rs +++ b/client/finality-grandpa/src/communication/mod.rs @@ -67,15 +67,24 @@ mod periodic; #[cfg(test)] pub(crate) mod tests; -pub(crate) mod grandpa_protocol_name { +pub mod grandpa_protocol_name { + use sc_chain_spec::ChainSpec; + pub(crate) const NAME: &'static str = "/grandpa/1"; /// Old names for the notifications protocol, used for backward compatibility. - pub const LEGACY_NAMES: [&'static str; 1] = ["/paritytech/grandpa/1"]; + pub(crate) const LEGACY_NAMES: [&'static str; 1] = ["/paritytech/grandpa/1"]; /// Name of the notifications protocol used by Grandpa. /// Must be registered towards the networking in order for Grandpa to properly function. - pub fn with_prefix(prefix: &str) -> String { - format!("{}{}", prefix, NAME) + pub fn standard_name( + genesis_hash: &Hash, + chain_spec: &Box, + ) -> std::borrow::Cow<'static, str> { + 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() } } @@ -228,7 +237,7 @@ impl> NetworkBridge { prometheus_registry: Option<&Registry>, telemetry: Option, ) -> Self { - let protocol = grandpa_protocol_name::with_prefix(&config.protocol_name_prefix); + let protocol = config.protocol_name.clone(); let (validator, report_stream) = GossipValidator::new(config, set_state.clone(), prometheus_registry, telemetry.clone()); diff --git a/client/finality-grandpa/src/lib.rs b/client/finality-grandpa/src/lib.rs index 02320980557d1..ac5b05d698a6e 100644 --- a/client/finality-grandpa/src/lib.rs +++ b/client/finality-grandpa/src/lib.rs @@ -123,6 +123,7 @@ pub mod warp_proof; pub use authorities::{AuthoritySet, AuthoritySetChanges, SharedAuthoritySet}; pub use aux_schema::best_justification; +pub use communication::grandpa_protocol_name::standard_name as protocol_standard_name; pub use finality_grandpa::voter::report; pub use finality_proof::{FinalityProof, FinalityProofError, FinalityProofProvider}; pub use import::{find_forced_change, find_scheduled_change, GrandpaBlockImport}; @@ -263,8 +264,8 @@ pub struct Config { pub keystore: Option, /// TelemetryHandle instance. pub telemetry: Option, - /// Protocol name prefix - usually genesis hash and optional fork id. - pub protocol_name_prefix: String, + /// Chain specific Grandpa protocol name. See [`communication::grandpa_protocol_name`]. + pub protocol_name: std::borrow::Cow<'static, str>, } impl Config { @@ -716,10 +717,13 @@ pub struct GrandpaParams { /// Returns the configuration value to put in /// [`sc_network::config::NetworkConfiguration::extra_sets`]. -pub fn grandpa_peers_set_config(chain_prefix: &str) -> sc_network::config::NonDefaultSetConfig { +/// For standard protocol name see [`communication::grandpa_protocol_name`]. +pub fn grandpa_peers_set_config( + protocol_name: std::borrow::Cow<'static, str>, +) -> sc_network::config::NonDefaultSetConfig { use communication::grandpa_protocol_name; sc_network::config::NonDefaultSetConfig { - notifications_protocol: grandpa_protocol_name::with_prefix(chain_prefix).into(), + notifications_protocol: protocol_name, fallback_names: grandpa_protocol_name::LEGACY_NAMES.iter().map(|&n| n.into()).collect(), // Notifications reach ~256kiB in size at the time of writing on Kusama and Polkadot. max_notification_size: 1024 * 1024, From 1dda8473dd51b232cac1253ead92fbf3a5dc7534 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Thu, 16 Dec 2021 19:11:50 +0200 Subject: [PATCH 11/19] beefy: contain protocol name building logic --- Cargo.lock | 1 + client/beefy/Cargo.toml | 1 + client/beefy/src/lib.rs | 33 +++++++++++++++++++++------------ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e206e191a6634..fb9861d48b433 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -481,6 +481,7 @@ dependencies = [ "log 0.4.14", "parity-scale-codec", "parking_lot 0.11.1", + "sc-chain-spec", "sc-client-api", "sc-keystore", "sc-network", diff --git a/client/beefy/Cargo.toml b/client/beefy/Cargo.toml index cb561c0dc77a6..a15bc7e252ac8 100644 --- a/client/beefy/Cargo.toml +++ b/client/beefy/Cargo.toml @@ -26,6 +26,7 @@ sp-core = { version = "4.1.0-dev", path = "../../primitives/core" } sp-keystore = { version = "0.10.0-dev", path = "../../primitives/keystore" } sp-runtime = { version = "4.0.0-dev", 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" } diff --git a/client/beefy/src/lib.rs b/client/beefy/src/lib.rs index b6be2b4c62601..5952554662cfe 100644 --- a/client/beefy/src/lib.rs +++ b/client/beefy/src/lib.rs @@ -39,26 +39,36 @@ mod round; mod worker; pub mod notification; +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 const LEGACY_NAMES: [&'static str; 1] = ["/paritytech/beefy/1"]; + 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 with_prefix(prefix: &str) -> String { - format!("{}{}", prefix, NAME) + pub fn standard_name( + genesis_hash: &Hash, + chain_spec: &Box, + ) -> std::borrow::Cow<'static, str> { + 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(chain_prefix: &str) -> sc_network::config::NonDefaultSetConfig { - let mut cfg = sc_network::config::NonDefaultSetConfig::new( - beefy_protocol_name::with_prefix(chain_prefix).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()); @@ -115,8 +125,8 @@ where pub min_block_delta: u32, /// Prometheus metric registry pub prometheus_registry: Option, - /// Protocol name prefix - usually genesis hash and optional fork id. - pub protocol_name_prefix: String, + /// Chain specific Grandpa protocol name. See [`beefy_protocol_name::standard_name`]. + pub protocol_name: std::borrow::Cow<'static, str>, } /// Start the BEEFY gadget. @@ -138,10 +148,9 @@ where signed_commitment_sender, min_block_delta, prometheus_registry, - protocol_name_prefix, + protocol_name, } = beefy_params; - let protocol_name = beefy_protocol_name::with_prefix(&protocol_name_prefix); let gossip_validator = Arc::new(gossip::GossipValidator::new()); let gossip_engine = GossipEngine::new(network, protocol_name, gossip_validator.clone(), None); From 1262cce367c972777d649b6ba7d39fe4c793f9f0 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Thu, 16 Dec 2021 20:07:30 +0200 Subject: [PATCH 12/19] grandpa: fix tests --- .../src/communication/gossip.rs | 41 +++++++++---------- .../src/communication/tests.rs | 2 +- client/finality-grandpa/src/tests.rs | 23 ++++++----- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/client/finality-grandpa/src/communication/gossip.rs b/client/finality-grandpa/src/communication/gossip.rs index 37c393f566284..5ed5ed7b1274a 100644 --- a/client/finality-grandpa/src/communication/gossip.rs +++ b/client/finality-grandpa/src/communication/gossip.rs @@ -1667,6 +1667,7 @@ pub(super) struct PeerReport { #[cfg(test)] mod tests { use super::{environment::SharedVoterSetState, *}; + use crate::communication; use sc_network::config::Role; use sc_network_gossip::Validator as GossipValidatorT; use sc_network_test::Block; @@ -1682,7 +1683,7 @@ mod tests { local_role: Role::Authority, observer_enabled: true, telemetry: None, - protocol_name_prefix: "/test".into(), + protocol_name: communication::grandpa_protocol_name::NAME.into(), } } @@ -1844,13 +1845,13 @@ mod tests { // messages from old rounds are expired. for round_num in 1u64..last_kept_round { - let topic = crate::communication::round_topic::(round_num, 1); + let topic = communication::round_topic::(round_num, 1); assert!(is_expired(topic, &[1, 2, 3])); } // messages from not-too-old rounds are not expired. for round_num in last_kept_round..10 { - let topic = crate::communication::round_topic::(round_num, 1); + let topic = communication::round_topic::(round_num, 1); assert!(!is_expired(topic, &[1, 2, 3])); } } @@ -2266,7 +2267,7 @@ mod tests { // we accept messages from rounds 9, 10 and 11 // therefore neither of those should be considered expired for round in &[9, 10, 11] { - assert!(!is_expired(crate::communication::round_topic::(*round, 1), &[])) + assert!(!is_expired(communication::round_topic::(*round, 1), &[])) } } @@ -2314,7 +2315,7 @@ mod tests { if message_allowed( peer, MessageIntent::Broadcast, - &crate::communication::round_topic::(1, 0), + &communication::round_topic::(1, 0), &[], ) { allowed += 1; @@ -2378,7 +2379,7 @@ mod tests { assert!(!val.message_allowed()( &light_peer, MessageIntent::Broadcast, - &crate::communication::round_topic::(1, 0), + &communication::round_topic::(1, 0), &[], )); @@ -2392,7 +2393,7 @@ mod tests { assert!(!val.message_allowed()( &light_peer, MessageIntent::Broadcast, - &crate::communication::round_topic::(1, 0), + &communication::round_topic::(1, 0), &[], )); @@ -2416,8 +2417,8 @@ mod tests { auth_data: Vec::new(), }; - crate::communication::gossip::GossipMessage::::Commit( - crate::communication::gossip::FullCommitMessage { + communication::gossip::GossipMessage::::Commit( + communication::gossip::FullCommitMessage { round: Round(2), set_id: SetId(0), message: commit, @@ -2430,7 +2431,7 @@ mod tests { assert!(val.message_allowed()( &light_peer, MessageIntent::Broadcast, - &crate::communication::global_topic::(0), + &communication::global_topic::(0), &commit, )); } @@ -2470,8 +2471,8 @@ mod tests { auth_data: Vec::new(), }; - crate::communication::gossip::GossipMessage::::Commit( - crate::communication::gossip::FullCommitMessage { + communication::gossip::GossipMessage::::Commit( + communication::gossip::FullCommitMessage { round: Round(1), set_id: SetId(1), message: commit, @@ -2489,7 +2490,7 @@ mod tests { assert!(message_allowed( &peer1, MessageIntent::Broadcast, - &crate::communication::global_topic::(1), + &communication::global_topic::(1), &commit, )); @@ -2498,7 +2499,7 @@ mod tests { assert!(!message_allowed( &peer2, MessageIntent::Broadcast, - &crate::communication::global_topic::(1), + &communication::global_topic::(1), &commit, )); } @@ -2515,8 +2516,8 @@ mod tests { auth_data: Vec::new(), }; - crate::communication::gossip::GossipMessage::::Commit( - crate::communication::gossip::FullCommitMessage { + communication::gossip::GossipMessage::::Commit( + communication::gossip::FullCommitMessage { round: Round(round), set_id: SetId(set_id), message: commit, @@ -2536,15 +2537,13 @@ mod tests { // a commit message for round 1 that finalizes the same height as we // have observed previously should not be expired - assert!( - !message_expired(crate::communication::global_topic::(1), &commit(1, 1, 2),) - ); + assert!(!message_expired(communication::global_topic::(1), &commit(1, 1, 2),)); // it should be expired if it is for a lower block - assert!(message_expired(crate::communication::global_topic::(1), &commit(1, 1, 1))); + assert!(message_expired(communication::global_topic::(1), &commit(1, 1, 1))); // or the same block height but from the previous round - assert!(message_expired(crate::communication::global_topic::(1), &commit(0, 1, 2))); + assert!(message_expired(communication::global_topic::(1), &commit(0, 1, 2))); } #[test] diff --git a/client/finality-grandpa/src/communication/tests.rs b/client/finality-grandpa/src/communication/tests.rs index b8970bf332643..c27724665b262 100644 --- a/client/finality-grandpa/src/communication/tests.rs +++ b/client/finality-grandpa/src/communication/tests.rs @@ -148,7 +148,7 @@ fn config() -> crate::Config { local_role: Role::Authority, observer_enabled: true, telemetry: None, - protocol_name_prefix: "/test".into(), + protocol_name: grandpa_protocol_name::NAME.into(), } } diff --git a/client/finality-grandpa/src/tests.rs b/client/finality-grandpa/src/tests.rs index 1c9ea586ae3a7..ffa58c9f58f3f 100644 --- a/client/finality-grandpa/src/tests.rs +++ b/client/finality-grandpa/src/tests.rs @@ -56,6 +56,7 @@ use substrate_test_runtime_client::runtime::BlockNumber; use tokio::runtime::{Handle, Runtime}; use authorities::AuthoritySet; +use communication::grandpa_protocol_name; use sc_block_builder::BlockBuilderProvider; use sc_consensus::LongestChain; use sc_keystore::LocalKeystore; @@ -97,7 +98,7 @@ impl GrandpaTestNet { impl GrandpaTestNet { fn add_authority_peer(&mut self) { self.add_full_peer_with_config(FullPeerConfig { - notifications_protocols: vec![communication::grandpa_protocol_name::NAME.into()], + notifications_protocols: vec![grandpa_protocol_name::NAME.into()], is_authority: true, ..Default::default() }) @@ -121,7 +122,7 @@ impl TestNetFactory for GrandpaTestNet { fn add_full_peer(&mut self) { self.add_full_peer_with_config(FullPeerConfig { - notifications_protocols: vec![communication::grandpa_protocol_name::NAME.into()], + notifications_protocols: vec![grandpa_protocol_name::NAME.into()], is_authority: false, ..Default::default() }) @@ -274,7 +275,7 @@ fn initialize_grandpa( local_role: Role::Authority, observer_enabled: true, telemetry: None, - protocol_name_prefix: "/test".into(), + protocol_name: grandpa_protocol_name::NAME.into(), }, link, network: net_service, @@ -424,7 +425,7 @@ fn finalize_3_voters_1_full_observer() { local_role: Role::Authority, observer_enabled: true, telemetry: None, - protocol_name_prefix: "/test".into(), + protocol_name: grandpa_protocol_name::NAME.into(), }, link, network: net_service, @@ -515,7 +516,7 @@ fn transition_3_voters_twice_1_full_observer() { local_role: Role::Authority, observer_enabled: true, telemetry: None, - protocol_name_prefix: "/test".into(), + protocol_name: grandpa_protocol_name::NAME.into(), }, link, network: net_service, @@ -974,7 +975,7 @@ fn voter_persists_its_votes() { local_role: Role::Authority, observer_enabled: true, telemetry: None, - protocol_name_prefix: "/test".into(), + protocol_name: grandpa_protocol_name::NAME.into(), }; let set_state = { @@ -1014,7 +1015,7 @@ fn voter_persists_its_votes() { local_role: Role::Authority, observer_enabled: true, telemetry: None, - protocol_name_prefix: "/test".into(), + protocol_name: grandpa_protocol_name::NAME.into(), }, link, network: net_service, @@ -1055,7 +1056,7 @@ fn voter_persists_its_votes() { local_role: Role::Authority, observer_enabled: true, telemetry: None, - protocol_name_prefix: "/test".into(), + protocol_name: grandpa_protocol_name::NAME.into(), }, link, network: net_service, @@ -1219,7 +1220,7 @@ fn finalize_3_voters_1_light_observer() { local_role: Role::Full, observer_enabled: true, telemetry: None, - protocol_name_prefix: "/test".into(), + protocol_name: grandpa_protocol_name::NAME.into(), }, net.peers[3].data.lock().take().expect("link initialized at startup; qed"), net.peers[3].network_service().clone(), @@ -1266,7 +1267,7 @@ fn voter_catches_up_to_latest_round_when_behind() { local_role: Role::Authority, observer_enabled: true, telemetry: None, - protocol_name_prefix: "/test".into(), + protocol_name: grandpa_protocol_name::NAME.into(), }, link, network: net.lock().peer(peer_id).network_service().clone(), @@ -1384,7 +1385,7 @@ where local_role: Role::Authority, observer_enabled: true, telemetry: None, - protocol_name_prefix: "/test".into(), + protocol_name: grandpa_protocol_name::NAME.into(), }; let network = From b4b8a74c71842a58d1de8186d43d23303c6a5052 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Thu, 16 Dec 2021 20:14:55 +0200 Subject: [PATCH 13/19] fix merge damage --- client/finality-grandpa/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/finality-grandpa/Cargo.toml b/client/finality-grandpa/Cargo.toml index 12355aeaa8509..a2cdaa886686c 100644 --- a/client/finality-grandpa/Cargo.toml +++ b/client/finality-grandpa/Cargo.toml @@ -27,7 +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", path = "../../client/chain-spec" } +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" } From 0de43624879a18a60bf0268e05a61e6f2e6e8415 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Mon, 20 Dec 2021 10:29:49 +0200 Subject: [PATCH 14/19] fix docs reference visibility Signed-off-by: acatangiu --- client/finality-grandpa/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/finality-grandpa/src/lib.rs b/client/finality-grandpa/src/lib.rs index ac5b05d698a6e..005fce411cd9a 100644 --- a/client/finality-grandpa/src/lib.rs +++ b/client/finality-grandpa/src/lib.rs @@ -264,7 +264,7 @@ pub struct Config { pub keystore: Option, /// TelemetryHandle instance. pub telemetry: Option, - /// Chain specific Grandpa protocol name. See [`communication::grandpa_protocol_name`]. + /// Chain specific Grandpa protocol name. See [`crate::protocol_standard_name`]. pub protocol_name: std::borrow::Cow<'static, str>, } @@ -717,7 +717,7 @@ pub struct GrandpaParams { /// Returns the configuration value to put in /// [`sc_network::config::NetworkConfiguration::extra_sets`]. -/// For standard protocol name see [`communication::grandpa_protocol_name`]. +/// For standard protocol name see [`crate::protocol_standard_name`]. pub fn grandpa_peers_set_config( protocol_name: std::borrow::Cow<'static, str>, ) -> sc_network::config::NonDefaultSetConfig { From a07eec69d535d5d0f47262c3c9329765d8da678b Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Mon, 20 Dec 2021 14:58:04 +0200 Subject: [PATCH 15/19] Update client/finality-grandpa/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomasz Drwięga --- client/finality-grandpa/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/finality-grandpa/src/lib.rs b/client/finality-grandpa/src/lib.rs index 005fce411cd9a..0e850eabbd90b 100644 --- a/client/finality-grandpa/src/lib.rs +++ b/client/finality-grandpa/src/lib.rs @@ -264,7 +264,7 @@ pub struct Config { pub keystore: Option, /// TelemetryHandle instance. pub telemetry: Option, - /// Chain specific Grandpa protocol name. See [`crate::protocol_standard_name`]. + /// Chain specific GRANDPA protocol name. See [`crate::protocol_standard_name`]. pub protocol_name: std::borrow::Cow<'static, str>, } From 1aa97534432f00bdcecf5bc6f0f22b81ad6a812c Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Mon, 20 Dec 2021 14:58:13 +0200 Subject: [PATCH 16/19] Update client/finality-grandpa/src/communication/mod.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomasz Drwięga --- client/finality-grandpa/src/communication/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/finality-grandpa/src/communication/mod.rs b/client/finality-grandpa/src/communication/mod.rs index f4e7d09992d52..d44fc4ebc4a4f 100644 --- a/client/finality-grandpa/src/communication/mod.rs +++ b/client/finality-grandpa/src/communication/mod.rs @@ -74,8 +74,9 @@ pub mod grandpa_protocol_name { /// Old names for the notifications protocol, used for backward compatibility. pub(crate) const LEGACY_NAMES: [&'static str; 1] = ["/paritytech/grandpa/1"]; - /// Name of the notifications protocol used by Grandpa. - /// Must be registered towards the networking in order for Grandpa to properly function. + /// Name of the notifications protocol used by GRANDPA. + /// + /// Must be registered towards the networking in order for GRANDPA to properly function. pub fn standard_name( genesis_hash: &Hash, chain_spec: &Box, From 5673f4848b6b21ed27f667d7c798c0502fbcfb39 Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Mon, 20 Dec 2021 14:58:18 +0200 Subject: [PATCH 17/19] Update client/beefy/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomasz Drwięga --- client/beefy/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/beefy/src/lib.rs b/client/beefy/src/lib.rs index 5952554662cfe..09c0738d28d76 100644 --- a/client/beefy/src/lib.rs +++ b/client/beefy/src/lib.rs @@ -125,7 +125,7 @@ where pub min_block_delta: u32, /// Prometheus metric registry pub prometheus_registry: Option, - /// Chain specific Grandpa protocol name. See [`beefy_protocol_name::standard_name`]. + /// Chain specific GRANDPA protocol name. See [`beefy_protocol_name::standard_name`]. pub protocol_name: std::borrow::Cow<'static, str>, } From 5a6a7b2a6e40060b7177fac5b187d5a53c783b22 Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Mon, 20 Dec 2021 14:58:24 +0200 Subject: [PATCH 18/19] Update client/beefy/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomasz Drwięga --- client/beefy/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/beefy/src/lib.rs b/client/beefy/src/lib.rs index 09c0738d28d76..497096d572e9d 100644 --- a/client/beefy/src/lib.rs +++ b/client/beefy/src/lib.rs @@ -48,8 +48,9 @@ pub(crate) mod beefy_protocol_name { /// 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. + /// 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( genesis_hash: &Hash, chain_spec: &Box, From d70ed355b311f6708e93b08644abb1181a8e94a4 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Tue, 4 Jan 2022 16:39:14 +0200 Subject: [PATCH 19/19] avoid using hash default, even for protocol names --- bin/node-template/node/src/service.rs | 2 +- bin/node/cli/src/service.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index a575876aced64..ac1d4d7884657 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -181,7 +181,7 @@ pub fn new_full(mut config: Configuration) -> Result }; } let grandpa_protocol_name = sc_finality_grandpa::protocol_standard_name( - &client.block_hash(0).ok().flatten().unwrap_or_default(), + &client.block_hash(0).ok().flatten().expect("Genesis block exists; qed"), &config.chain_spec, ); diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index dbcd501d6683c..af1ca12c10f69 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -327,7 +327,7 @@ 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().unwrap_or_default(), + &client.block_hash(0).ok().flatten().expect("Genesis block exists; qed"), &config.chain_spec, );