Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change grandpa name and use fork_id #2116

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
7 changes: 7 additions & 0 deletions bin/light-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
melekes marked this conversation as resolved.
Show resolved Hide resolved
}

struct RunningChain<TPlat: Platform> {
Expand Down Expand Up @@ -488,6 +493,7 @@ impl<TChain, TPlat: Platform> Client<TChain, TPlat> {
)
}),
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.
Expand Down Expand Up @@ -982,6 +988,7 @@ async fn start_services<TPlat: Platform>(
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;
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
25 changes: 14 additions & 11 deletions 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 All @@ -24,12 +25,7 @@ use crate::libp2p::{
use crate::network::{kademlia, protocol};
use crate::util::{self, SipHasherBuild};

use alloc::{
borrow::Cow,
format,
string::{String, ToString as _},
vec::Vec,
};
use alloc::{borrow::Cow, format, string::String, vec::Vec};
use core::{
fmt, iter, mem,
num::NonZeroUsize,
Expand Down Expand Up @@ -119,6 +115,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 @@ -277,12 +279,13 @@ 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: "/paritytech/grandpa/1".to_string(),
protocol_name: match &chain.fork_id {
Some(id) => {
format!("/{}/{}/grandpa/1", HashDisplay(&chain.genesis_hash), id)
melekes marked this conversation as resolved.
Show resolved Hide resolved
}
None => format!("/{}/grandpa/1", HashDisplay(&chain.genesis_hash)),
},
fallback_protocol_names: Vec::new(),
max_handshake_size: 4,
max_notification_size: 1024 * 1024,
Expand Down