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

Commit

Permalink
chain-spec: add optional 'fork_id'
Browse files Browse the repository at this point in the history
'fork_id' is used to uniquely identify forks of the same chain/network
'ChainSpec' trait provides default 'None' implementation, meaning this
chain hasn't been forked.
  • Loading branch information
acatangiu committed Dec 13, 2021
1 parent ba2dbc0 commit d4b616a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
other: (block_import, grandpa_link, mut telemetry),
} = new_partial(&config)?;
let genesis_hash = client.block_hash(0).ok().flatten().unwrap_or_default();
let chain_prefix = format!("/{}/{}", config.protocol_id().as_ref(), genesis_hash);
let chain_prefix = match config.chain_spec.fork_id() {
Some(fork_id) => format!("/{}/{}", genesis_hash, fork_id),
None => format!("/{}", genesis_hash),
};

if let Some(url) = &config.keystore_remote {
match remote_keystore(url) {
Expand Down
5 changes: 4 additions & 1 deletion bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,10 @@ pub fn new_full_base(
let shared_voter_state = rpc_setup;
let auth_disc_publish_non_global_ips = config.network.allow_non_globals_in_dht;
let genesis_hash = client.block_hash(0).ok().flatten().unwrap_or_default();
let chain_prefix = format!("/{}/{}", config.protocol_id().as_ref(), genesis_hash);
let chain_prefix = match config.chain_spec.fork_id() {
Some(fork_id) => format!("/{}/{}", genesis_hash, fork_id),
None => format!("/{}", genesis_hash),
};

config.network.extra_sets.push(grandpa::grandpa_peers_set_config(&chain_prefix));
let warp_sync = Arc::new(grandpa::warp_proof::NetworkProvider::new(
Expand Down
4 changes: 4 additions & 0 deletions client/chain-spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ pub trait ChainSpec: BuildStorage + Send + Sync {
fn telemetry_endpoints(&self) -> &Option<TelemetryEndpoints>;
/// Network protocol id.
fn protocol_id(&self) -> Option<&str>;
/// Optional network fork identifier. `None` by default.
fn fork_id(&self) -> Option<&str> {
None
}
/// Additional loosly-typed properties of the chain.
///
/// Returns an empty JSON object if 'properties' not defined in config
Expand Down

0 comments on commit d4b616a

Please sign in to comment.