Skip to content

Commit

Permalink
change grandpa name to /{genesis_hash}/{fork_id}/grandpa/1
Browse files Browse the repository at this point in the history
previous value: `/paritytech/grandpa/1`
also use fork_id, which was added in #1956

Refs #1955
  • Loading branch information
melekes committed Mar 3, 2022
1 parent 8b75373 commit 32cdcac
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bin/full-node/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions bin/full-node/src/run/network_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// If true, the chain uses the GrandPa networking protocol.
pub has_grandpa_protocol: bool,
}
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions bin/light-base/src/network_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// If true, the chain uses the GrandPa networking protocol.
pub has_grandpa_protocol: bool,
}
Expand Down Expand Up @@ -153,6 +158,7 @@ impl<TPlat: Platform> NetworkService<TPlat> {
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,
Expand Down
14 changes: 13 additions & 1 deletion src/network/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use crate::header;
use crate::informant::HashDisplay;
use crate::libp2p::{
connection, multiaddr, peer_id,
peers::{self, QueueNotificationError},
Expand Down Expand Up @@ -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<String>,

/// If `Some`, the chain uses the GrandPa networking protocol.
pub grandpa_protocol_config: Option<GrandpaState>,

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 32cdcac

Please sign in to comment.