From 32cdcac8c209df4bc60e3549903621ac0cf9d5ca Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 3 Mar 2022 16:38:42 +0400 Subject: [PATCH 1/6] change grandpa name to `/{genesis_hash}/{fork_id}/grandpa/1` previous value: `/paritytech/grandpa/1` also use fork_id, which was added in https://github.com/paritytech/smoldot/pull/1956 Refs #1955 --- bin/full-node/src/run.rs | 2 ++ bin/full-node/src/run/network_service.rs | 6 ++++++ bin/light-base/src/network_service.rs | 6 ++++++ src/network/service.rs | 14 +++++++++++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/bin/full-node/src/run.rs b/bin/full-node/src/run.rs index 3a847d8d3c..19a4f6e219 100644 --- a/bin/full-node/src/run.rs +++ b/bin/full-node/src/run.rs @@ -223,6 +223,7 @@ pub async fn run(cli_options: cli::CliOptionsRun) { num_events_receivers: 2 + if relay_chain_database.is_some() { 1 } else { 0 }, chains: iter::once(network_service::ChainConfig { protocol_id: chain_spec.protocol_id().to_owned(), + fork_id: chain_spec.fork_id().map(|s| s.to_owned()), database: database.clone(), has_grandpa_protocol: matches!( genesis_chain_information.finality, @@ -260,6 +261,7 @@ pub async fn run(cli_options: cli::CliOptionsRun) { if let Some(relay_chains_specs) = &relay_chain_spec { Some(network_service::ChainConfig { protocol_id: relay_chains_specs.protocol_id().to_owned(), + fork_id: relay_chains_specs.fork_id().map(|s| s.to_owned()), database: relay_chain_database.clone().unwrap(), has_grandpa_protocol: matches!( relay_genesis_chain_information.as_ref().unwrap().finality, diff --git a/bin/full-node/src/run/network_service.rs b/bin/full-node/src/run/network_service.rs index 1dedbb8f37..e091782e76 100644 --- a/bin/full-node/src/run/network_service.rs +++ b/bin/full-node/src/run/network_service.rs @@ -97,6 +97,11 @@ pub struct ChainConfig { /// chain, so as to not introduce conflicts in the networking messages. pub protocol_id: String, + /// Optional fork identifier, used to differentiate between chains with the same genesis hash. + /// + /// This can be a counter (e.g. "1", "2", "3") or some unique identifier (e.g. "classic"). + pub fork_id: Option, + /// If true, the chain uses the GrandPa networking protocol. pub has_grandpa_protocol: bool, } @@ -160,6 +165,7 @@ impl NetworkService { in_slots: 25, out_slots: 25, protocol_id: chain.protocol_id.clone(), + fork_id: chain.fork_id.clone(), best_hash: chain.best_block.1, best_number: chain.best_block.0, genesis_hash: chain.genesis_block_hash, diff --git a/bin/light-base/src/network_service.rs b/bin/light-base/src/network_service.rs index 0fd57d8206..128b30f054 100644 --- a/bin/light-base/src/network_service.rs +++ b/bin/light-base/src/network_service.rs @@ -98,6 +98,11 @@ pub struct ConfigChain { /// chain, so as to not introduce conflicts in the networking messages. pub protocol_id: String, + /// Optional fork identifier, used to differentiate between chains with the same genesis hash. + /// + /// This can be a counter (e.g. "1", "2", "3") or some unique identifier (e.g. "classic"). + pub fork_id: Option, + /// If true, the chain uses the GrandPa networking protocol. pub has_grandpa_protocol: bool, } @@ -153,6 +158,7 @@ impl NetworkService { None }, protocol_id: chain.protocol_id.clone(), + fork_id: chain.fork_id.clone(), best_hash: chain.best_block.1, best_number: chain.best_block.0, genesis_hash: chain.genesis_block_hash, diff --git a/src/network/service.rs b/src/network/service.rs index be828a0066..b3f8c77a9d 100644 --- a/src/network/service.rs +++ b/src/network/service.rs @@ -16,6 +16,7 @@ // along with this program. If not, see . use crate::header; +use crate::informant::HashDisplay; use crate::libp2p::{ connection, multiaddr, peer_id, peers::{self, QueueNotificationError}, @@ -119,6 +120,12 @@ pub struct ChainConfig { /// > "chain spec"). pub protocol_id: String, + /// Optional fork identifier, used to differentiate between chains with the same genesis hash. + /// + /// > **Note**: This value is typically found in the specification of the chain (the + /// > "chain spec"). + pub fork_id: Option, + /// If `Some`, the chain uses the GrandPa networking protocol. pub grandpa_protocol_config: Option, @@ -282,7 +289,12 @@ where // chains, in order to make the rest of the code of this module more // comprehensible. iter::once(peers::NotificationProtocolConfig { - protocol_name: "/paritytech/grandpa/1".to_string(), + protocol_name: match &chain.fork_id { + Some(id) => { + format!("/{}/{}/grandpa/1", HashDisplay(&chain.genesis_hash), id) + } + None => format!("/{}/grandpa/1", HashDisplay(&chain.genesis_hash)), + }, fallback_protocol_names: Vec::new(), max_handshake_size: 4, max_notification_size: 1024 * 1024, From c0e841c26686f7fef8ef0d452fac415eedcc10f4 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 3 Mar 2022 16:47:06 +0400 Subject: [PATCH 2/6] add fork_id to ChainKey Refs #1955 --- bin/light-base/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/light-base/src/lib.rs b/bin/light-base/src/lib.rs index 875165b1f1..3f2fe325e4 100644 --- a/bin/light-base/src/lib.rs +++ b/bin/light-base/src/lib.rs @@ -261,6 +261,11 @@ struct ChainKey { /// Network protocol id, found in the chain specification. protocol_id: String, + + /// Optional fork identifier, used to differentiate between chains with the same genesis hash. + /// + /// This can be a counter (e.g. "1", "2", "3") or some unique identifier (e.g. "classic"). + fork_id: Option, } struct RunningChain { @@ -488,6 +493,7 @@ impl Client { ) }), protocol_id: chain_spec.protocol_id().to_owned(), + fork_id: chain_spec.fork_id().map(|s| s.to_owned()), }; // If the chain we are adding is a parachain, grab the services of the relay chain. @@ -982,6 +988,7 @@ async fn start_services( chain_information.as_ref().finalized_block_header.hash(), ), protocol_id: chain_spec.protocol_id().to_string(), + fork_id: chain_spec.fork_id().map(|s| s.to_string()), }], }) .await; From 88af78ff10870f7d3365aa90c9c00dcfbc760779 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 3 Mar 2022 16:48:28 +0400 Subject: [PATCH 3/6] remove outdated comment --- src/network/service.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/network/service.rs b/src/network/service.rs index b3f8c77a9d..6ad03ed9df 100644 --- a/src/network/service.rs +++ b/src/network/service.rs @@ -284,10 +284,6 @@ where max_notification_size: 16 * 1024 * 1024, })) .chain({ - // The `has_grandpa_protocol` flag controls whether the chain uses GrandPa. - // Note, however, that GrandPa is technically left enabled (but unused) on all - // chains, in order to make the rest of the code of this module more - // comprehensible. iter::once(peers::NotificationProtocolConfig { protocol_name: match &chain.fork_id { Some(id) => { From 0db45759ffdc6e6bae9a7e3f7761eb3af68adb53 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 3 Mar 2022 16:56:26 +0400 Subject: [PATCH 4/6] remove unused import --- src/network/service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/service.rs b/src/network/service.rs index 6ad03ed9df..4af8cdfd77 100644 --- a/src/network/service.rs +++ b/src/network/service.rs @@ -28,7 +28,7 @@ use crate::util::{self, SipHasherBuild}; use alloc::{ borrow::Cow, format, - string::{String, ToString as _}, + string::String, vec::Vec, }; use core::{ From 900b5bff0697aec122e8bda2a895a96ae9150983 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 3 Mar 2022 17:23:03 +0400 Subject: [PATCH 5/6] format code --- src/network/service.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/network/service.rs b/src/network/service.rs index 4af8cdfd77..3c21713214 100644 --- a/src/network/service.rs +++ b/src/network/service.rs @@ -25,12 +25,7 @@ use crate::libp2p::{ use crate::network::{kademlia, protocol}; use crate::util::{self, SipHasherBuild}; -use alloc::{ - borrow::Cow, - format, - string::String, - vec::Vec, -}; +use alloc::{borrow::Cow, format, string::String, vec::Vec}; use core::{ fmt, iter, mem, num::NonZeroUsize, From 53b78a6f231b480e6c9a6ce89510d7a799ed0a05 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Mon, 7 Mar 2022 12:14:44 +0400 Subject: [PATCH 6/6] replace HashDisplay with hex::encode in response to https://github.com/paritytech/substrate/pull/10974/files --- src/network/service.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/network/service.rs b/src/network/service.rs index 2d664c5d7f..a531002b9a 100644 --- a/src/network/service.rs +++ b/src/network/service.rs @@ -16,7 +16,6 @@ // along with this program. If not, see . use crate::header; -use crate::informant::HashDisplay; use crate::libp2p::{ connection, multiaddr, peer_id, peers::{self, QueueNotificationError}, @@ -282,9 +281,9 @@ where iter::once(peers::NotificationProtocolConfig { protocol_name: match &chain.fork_id { Some(id) => { - format!("/{}/{}/grandpa/1", HashDisplay(&chain.genesis_hash), id) + format!("/{}/{}/grandpa/1", hex::encode(&chain.genesis_hash), id) } - None => format!("/{}/grandpa/1", HashDisplay(&chain.genesis_hash)), + None => format!("/{}/grandpa/1", hex::encode(&chain.genesis_hash)), }, fallback_protocol_names: Vec::new(), max_handshake_size: 4,