From 28a106dc12d46dabb024fdabf8c26721e83e9784 Mon Sep 17 00:00:00 2001 From: wirednkod <wirednkod@gmail.com> Date: Thu, 5 Oct 2023 16:17:57 +0300 Subject: [PATCH] tmp --- crates/configuration/src/network.rs | 2 +- crates/configuration/src/parachain.rs | 12 ++++++--- crates/configuration/src/relaychain.rs | 8 ++++++ crates/examples/examples/0001-simple.toml | 7 ++++- .../examples/simple_network_example.rs | 27 ++++++++++++------- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/crates/configuration/src/network.rs b/crates/configuration/src/network.rs index 9569f6f..6dc9495 100644 --- a/crates/configuration/src/network.rs +++ b/crates/configuration/src/network.rs @@ -82,7 +82,7 @@ impl NetworkConfig { // retrieve the defaults relaychain for assigning to nodes if needed let relaychain_default_command: Option<Command> = - network_config.relaychain().default_command().cloned(); + network_config.relaychain().default_command().cloned() | network_config.relaychain().command().cloned(); let relaychain_default_image: Option<Image> = network_config.relaychain().default_image().cloned(); diff --git a/crates/configuration/src/parachain.rs b/crates/configuration/src/parachain.rs index 8dd9c9b..bc2989b 100644 --- a/crates/configuration/src/parachain.rs +++ b/crates/configuration/src/parachain.rs @@ -119,7 +119,7 @@ pub struct ParachainConfig { genesis_state_generator: Option<Command>, chain_spec_path: Option<AssetLocation>, #[serde(rename = "cumulus_based")] - is_cumulus_based: bool, + is_cumulus_based: Option<bool>, #[serde(skip_serializing_if = "std::vec::Vec::is_empty", default)] bootnodes_addresses: Vec<Multiaddr>, genesis_overrides: Option<serde_json::Value>, @@ -210,7 +210,11 @@ impl ParachainConfig { /// Whether the parachain is based on cumulus. pub fn is_cumulus_based(&self) -> bool { - self.is_cumulus_based + if let Some(true) = self.is_cumulus_based { + true + } else { + false + } } /// The bootnodes addresses the collators will connect to. @@ -258,7 +262,7 @@ impl Default for ParachainConfigBuilder<Initial> { genesis_state_generator: None, genesis_overrides: None, chain_spec_path: None, - is_cumulus_based: true, + is_cumulus_based: Some(true), bootnodes_addresses: vec![], collators: vec![], }, @@ -575,7 +579,7 @@ impl ParachainConfigBuilder<WithId> { pub fn cumulus_based(self, choice: bool) -> Self { Self::transition( ParachainConfig { - is_cumulus_based: choice, + is_cumulus_based: Some(choice), ..self.config }, self.validation_context, diff --git a/crates/configuration/src/relaychain.rs b/crates/configuration/src/relaychain.rs index f226b79..cbf6fa8 100644 --- a/crates/configuration/src/relaychain.rs +++ b/crates/configuration/src/relaychain.rs @@ -28,6 +28,7 @@ pub struct RelaychainConfig { #[serde(skip_serializing_if = "std::vec::Vec::is_empty", default)] nodes: Vec<NodeConfig>, genesis_overrides: Option<serde_json::Value>, + command: Option<Command>, } impl RelaychainConfig { @@ -66,6 +67,12 @@ impl RelaychainConfig { self.chain_spec_path.as_ref() } + /// The non-default command used for nodes. + pub fn command(&self) -> Option<&Command> { + self.command.as_ref() + } + + /// The number of `random nominators` to create for chains using staking, this is used in tandem with `max_nominations` to simulate the amount of nominators and nominations. pub fn random_nominators_count(&self) -> Option<u32> { self.random_nominators_count @@ -118,6 +125,7 @@ impl Default for RelaychainConfigBuilder<Initial> { default_db_snapshot: None, default_args: vec![], chain_spec_path: None, + command: None, random_nominators_count: None, max_nominations: None, genesis_overrides: None, diff --git a/crates/examples/examples/0001-simple.toml b/crates/examples/examples/0001-simple.toml index 53f1bcf..020072c 100644 --- a/crates/examples/examples/0001-simple.toml +++ b/crates/examples/examples/0001-simple.toml @@ -1,22 +1,27 @@ [settings] timeout = 1000 +node_spawn_timeout = 1000 [relaychain] default_image = "docker.io/parity/polkadot-sdk:latest" chain = "rococo-local" -command = "polkadot" +default_command = "polkadot" [[relaychain.nodes]] name = "alice" args = [ "--alice", "-lruntime=debug,parachain=trace" ] + is_bootnode = true [[relaychain.nodes]] name = "bob" args = [ "--bob", "-lruntime=debug,parachain=trace" ] + is_bootnode = true [[parachains]] id = 100 addToGenesis = false +balance = 200000000 +chain="some" [parachains.collator] name = "collator01" diff --git a/crates/examples/examples/simple_network_example.rs b/crates/examples/examples/simple_network_example.rs index dff2f03..d30c043 100644 --- a/crates/examples/examples/simple_network_example.rs +++ b/crates/examples/examples/simple_network_example.rs @@ -1,16 +1,23 @@ +use std::time::Duration; + use configuration::NetworkConfig; +use orchestrator::Orchestrator; +use provider::NativeProvider; +use support::fs::local::LocalFileSystem; -fn main() { +#[tokio::main] +async fn main() -> Result<(), Box<dyn std::error::Error>> { + let config = NetworkConfig::load_from_toml("./crates/examples/examples/0001-simple.toml").expect("errored?"); - let load_from_toml = - NetworkConfig::load_from_toml("./0001-simple.toml").unwrap(); + let fs = LocalFileSystem; + let provider = NativeProvider::new(fs.clone()); + let orchestrator = Orchestrator::new(fs, provider); + orchestrator.spawn(config).await?; + println!("🚀🚀🚀🚀 network deployed"); + // For now let just loop.... + #[allow(clippy::empty_loop)] + loop {} - // let config = NetworkConfigBuilder::new() - // .with_relaychain(|r| { - // r.with_chain("rococo-local") - // .with_node(|node| node.with_name("alice").with_command("polkadot")) - // }) - // .build(); + // Ok(()) - println!("{:?}", load_from_toml); } -- GitLab