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

Commit

Permalink
grandpa: protocol_name mod instead of struct
Browse files Browse the repository at this point in the history
  • Loading branch information
acatangiu committed Dec 13, 2021
1 parent 952e0a7 commit 758ff84
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions client/finality-grandpa/src/communication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,21 @@ 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"];

/// 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)
}
}

Expand Down Expand Up @@ -235,7 +234,7 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
prometheus_registry: Option<&Registry>,
telemetry: Option<TelemetryHandle>,
) -> 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());

Expand Down
8 changes: 4 additions & 4 deletions client/finality-grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ pub struct Config {
pub keystore: Option<SyncCryptoStorePtr>,
/// TelemetryHandle instance.
pub telemetry: Option<TelemetryHandle>,
/// 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,
}

Expand Down Expand Up @@ -717,10 +717,10 @@ pub struct GrandpaParams<Block: BlockT, C, N, SC, VR> {
/// 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 {
Expand Down

0 comments on commit 758ff84

Please sign in to comment.