From 2cb1593a93302a1cf0f29b1565c19ebcfff49145 Mon Sep 17 00:00:00 2001 From: acatangiu Date: Mon, 13 Dec 2021 17:44:39 +0200 Subject: [PATCH] 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 {