Skip to content

Commit

Permalink
Merge pull request #2161 from subspace/domain_bootstrap_nodes
Browse files Browse the repository at this point in the history
Domain bootstrap nodes
  • Loading branch information
vedhavyas authored Oct 25, 2023
2 parents 9b7f434 + 20a3f5c commit 98454bf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
7 changes: 7 additions & 0 deletions crates/sp-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use sp_runtime::{Digest, DigestItem, OpaqueExtrinsic, Percent};
use sp_runtime_interface::pass_by;
use sp_runtime_interface::pass_by::PassBy;
use sp_std::collections::btree_set::BTreeSet;
use sp_std::fmt::{Display, Formatter};
use sp_std::vec::Vec;
use sp_weights::Weight;
use subspace_core_primitives::crypto::blake3_hash;
Expand Down Expand Up @@ -170,6 +171,12 @@ impl DomainId {
}
}

impl Display for DomainId {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
self.0.fmt(f)
}
}

impl PassBy for DomainId {
type PassBy = pass_by::Codec<Self>;
}
Expand Down
32 changes: 31 additions & 1 deletion crates/subspace-node/src/bin/subspace-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,21 @@ fn main() -> Result<(), Error> {
runner.run_node_until_exit(|consensus_chain_config| async move {
let tokio_handle = consensus_chain_config.tokio_handle.clone();
let database_source = consensus_chain_config.database.clone();

let domains_bootstrap_nodes: serde_json::map::Map<String, serde_json::Value> =
consensus_chain_config
.chain_spec
.properties()
.get("domainsBootstrapNodes")
.map(|d| serde_json::from_value(d.clone()))
.transpose()
.map_err(|error| {
sc_service::Error::Other(format!(
"Failed to decode Domains bootstrap nodes: {error:?}"
))
})?
.unwrap_or_default();

let consensus_chain_node = {
let span = sc_tracing::tracing::info_span!(
sc_tracing::logging::PREFIX_LOG_SPAN,
Expand Down Expand Up @@ -556,14 +571,29 @@ fn main() -> Result<(), Error> {
);
let _enter = span.enter();

let domain_cli = DomainCli::new(
let mut domain_cli = DomainCli::new(
cli.run
.base_path()?
.map(|base_path| base_path.path().to_path_buf()),
cli.domain_args.into_iter(),
);

let domain_id = domain_cli.domain_id;

if domain_cli.run.network_params.bootnodes.is_empty() {
domain_cli.run.network_params.bootnodes = domains_bootstrap_nodes
.get(&format!("{}", domain_id))
.map(|d| serde_json::from_value(d.clone()))
.transpose()
.map_err(|error| {
sc_service::Error::Other(format!(
"Failed to decode Domain: {} bootstrap nodes: {error:?}",
domain_id
))
})?
.unwrap_or_default();
}

// start relayer for consensus chain
let mut xdm_gossip_worker_builder = GossipWorkerBuilder::new();
{
Expand Down
7 changes: 7 additions & 0 deletions crates/subspace-node/src/chain_spec_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use frame_support::traits::Get;
use sc_service::Properties;
use serde_json::map::Map;
use serde_json::Value;
use sp_core::crypto::AccountId32;
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::IdentifyAccount;
Expand All @@ -18,6 +20,11 @@ pub(crate) fn chain_spec_properties() -> Properties {
);
properties.insert("tokenDecimals".to_string(), DECIMAL_PLACES.into());
properties.insert("tokenSymbol".to_string(), "tSSC".into());
let domains_bootstrap_nodes = Map::<String, Value>::new();
properties.insert(
"domainsBootstrapNodes".to_string(),
domains_bootstrap_nodes.into(),
);

properties
}
Expand Down

0 comments on commit 98454bf

Please sign in to comment.