diff --git a/crates/configuration/src/parachain.rs b/crates/configuration/src/parachain.rs index e09752da73882979198b25157cc6de99ec67fcb6..8d07b7fe4c127d8bef4bd3fddd18b53187df5d16 100644 --- a/crates/configuration/src/parachain.rs +++ b/crates/configuration/src/parachain.rs @@ -1,5 +1,6 @@ use std::{cell::RefCell, error::Error, fmt::Display, marker::PhantomData, rc::Rc}; +use anyhow::anyhow; use multiaddr::Multiaddr; use serde::{ de::{self, Visitor}, @@ -24,6 +25,7 @@ use crate::{ pub enum RegistrationStrategy { InGenesis, UsingExtrinsic, + Manual, } impl Serialize for RegistrationStrategy { @@ -36,6 +38,10 @@ impl Serialize for RegistrationStrategy { match self { Self::InGenesis => state.serialize_field("add_to_genesis", &true)?, Self::UsingExtrinsic => state.serialize_field("register_para", &true)?, + Self::Manual => { + state.serialize_field("add_to_genesis", &false)?; + state.serialize_field("register_para", &false)?; + }, } state.end() @@ -322,7 +328,8 @@ impl ParachainConfigBuilder<Initial, Bootstrap> { } impl ParachainConfigBuilder<WithId, Bootstrap> { - /// Set the registration strategy for the parachain, could be without registration, using extrinsic or in genesis. + /// Set the registration strategy for the parachain, could be Manual (no registered by zombienet) or automatic + /// using an extrinsic or in genesis. pub fn with_registration_strategy(self, strategy: RegistrationStrategy) -> Self { Self::transition( ParachainConfig { @@ -335,6 +342,36 @@ impl ParachainConfigBuilder<WithId, Bootstrap> { } } +impl ParachainConfigBuilder<WithId, Running> { + /// Set the registration strategy for the parachain, could be Manual (no registered by zombienet) or automatic + /// using an extrinsic. Genesis option is not allowed in `Running` context. + pub fn with_registration_strategy(self, strategy: RegistrationStrategy) -> Self { + match strategy { + RegistrationStrategy::InGenesis => Self::transition( + self.config, + self.validation_context, + merge_errors( + self.errors, + FieldError::RegistrationStrategy(anyhow!( + "Can be set to InGenesis in Running context" + )) + .into(), + ), + ), + RegistrationStrategy::Manual | RegistrationStrategy::UsingExtrinsic => { + Self::transition( + ParachainConfig { + registration_strategy: Some(strategy), + ..self.config + }, + self.validation_context, + self.errors, + ) + }, + } + } +} + impl ParachainConfigBuilder<Initial, Running> { /// Start a new builder in the context of a running network pub fn new_with_running( diff --git a/crates/configuration/src/shared/errors.rs b/crates/configuration/src/shared/errors.rs index 1504f0b72b7b41b02ee02e4a8b0388c5de7547c5..89c2e220acf2f3b70b375d5ec75b563b6e50de9e 100644 --- a/crates/configuration/src/shared/errors.rs +++ b/crates/configuration/src/shared/errors.rs @@ -81,6 +81,9 @@ pub enum FieldError { #[error("p2p_port: {0}")] P2pPort(anyhow::Error), + + #[error("registration_strategy: {0}")] + RegistrationStrategy(anyhow::Error), } /// A conversion error for shared types across fields. diff --git a/crates/orchestrator/src/generators/command.rs b/crates/orchestrator/src/generators/command.rs index 7d70678abda5785bebc33d36d38706df1dd0fa1e..9cee572ab2805bcd70772bd746c2529051fe2d98 100644 --- a/crates/orchestrator/src/generators/command.rs +++ b/crates/orchestrator/src/generators/command.rs @@ -232,7 +232,7 @@ pub fn generate_for_node( if *is_validator && !args.contains(&Arg::Flag("--validator".into())) { tmp_args.push("--validator".into()); - // tmp_args.push("--insecure-validator-i-know-what-i-do".into()); + tmp_args.push("--insecure-validator-i-know-what-i-do".into()); } if !bootnodes_addresses.is_empty() { diff --git a/crates/orchestrator/src/lib.rs b/crates/orchestrator/src/lib.rs index d151462c671a332d599303c19265c8f47e5c8b61..a4d8dc0993066fd32d54fdad78e75f24f3a1684a 100644 --- a/crates/orchestrator/src/lib.rs +++ b/crates/orchestrator/src/lib.rs @@ -131,9 +131,13 @@ where let (para_to_register_in_genesis, para_to_register_with_extrinsic): ( Vec<&ParachainSpec>, Vec<&ParachainSpec>, - ) = network_spec.parachains.iter().partition(|para| { - matches!(para.registration_strategy, RegistrationStrategy::InGenesis) - }); + ) = network_spec + .parachains + .iter() + .filter(|para| para.registration_strategy != RegistrationStrategy::Manual) + .partition(|para| { + matches!(para.registration_strategy, RegistrationStrategy::InGenesis) + }); let mut para_artifacts = vec![]; for para in para_to_register_in_genesis { diff --git a/crates/orchestrator/src/network.rs b/crates/orchestrator/src/network.rs index ae0fc3e90546cad5b6c97f2883c504ab6c57a87a..e70c6a26b8ba8c31a2adf2e3b14aa10bdc58ae45 100644 --- a/crates/orchestrator/src/network.rs +++ b/crates/orchestrator/src/network.rs @@ -8,7 +8,7 @@ use configuration::{ para_states::{Initial, Running}, shared::node::EnvVar, types::{Arg, Command, Image, Port}, - ParachainConfig, ParachainConfigBuilder, + ParachainConfig, ParachainConfigBuilder, RegistrationStrategy, }; use provider::{types::TransferedFile, DynNamespace, ProviderError}; use support::fs::FileSystem; @@ -426,30 +426,33 @@ impl<T: FileSystem> Network<T> { "At least one node of the relaychain should be running" ))? .ws_uri(); - let register_para_options = RegisterParachainOptions { - id: parachain.para_id, - // This needs to resolve correctly - wasm_path: para_spec - .genesis_wasm - .artifact_path() - .ok_or(anyhow::anyhow!( - "artifact path for wasm must be set at this point", - ))? - .to_path_buf(), - state_path: para_spec - .genesis_state - .artifact_path() - .ok_or(anyhow::anyhow!( - "artifact path for state must be set at this point", - ))? - .to_path_buf(), - node_ws_url: first_node_url.to_string(), - onboard_as_para: para_spec.onboard_as_parachain, - seed: None, // TODO: Seed is passed by? - finalization: false, - }; - Parachain::register(register_para_options, &scoped_fs).await?; + if para_config.registration_strategy() == Some(&RegistrationStrategy::UsingExtrinsic) { + let register_para_options = RegisterParachainOptions { + id: parachain.para_id, + // This needs to resolve correctly + wasm_path: para_spec + .genesis_wasm + .artifact_path() + .ok_or(anyhow::anyhow!( + "artifact path for wasm must be set at this point", + ))? + .to_path_buf(), + state_path: para_spec + .genesis_state + .artifact_path() + .ok_or(anyhow::anyhow!( + "artifact path for state must be set at this point", + ))? + .to_path_buf(), + node_ws_url: first_node_url.to_string(), + onboard_as_para: para_spec.onboard_as_parachain, + seed: None, // TODO: Seed is passed by? + finalization: false, + }; + + Parachain::register(register_para_options, &scoped_fs).await?; + } // Spawn the nodes let spawning_tasks = para_spec diff --git a/crates/orchestrator/src/spawner.rs b/crates/orchestrator/src/spawner.rs index d5ab43ba7674ae6ba0481816b5c62a0dcac983e3..290c13affd67c63a18cd551dab4b4318ba5b7a3f 100644 --- a/crates/orchestrator/src/spawner.rs +++ b/crates/orchestrator/src/spawner.rs @@ -105,9 +105,9 @@ where NODE_RELAY_DATA_DIR.into(), ) } else { - let cfg_path = format!("{}/{NODE_CONFIG_DIR}", &base_dir); - let data_path = format!("{}/{NODE_DATA_DIR}", &base_dir); - let relay_data_path = format!("{}/{NODE_RELAY_DATA_DIR}", &base_dir); + let cfg_path = format!("{}{NODE_CONFIG_DIR}", &base_dir); + let data_path = format!("{}{NODE_DATA_DIR}", &base_dir); + let relay_data_path = format!("{}{NODE_RELAY_DATA_DIR}", &base_dir); (cfg_path, data_path, relay_data_path) }; @@ -165,6 +165,7 @@ where }; // Drops the port parking listeners before spawn + node.ws_port.drop_listener(); node.p2p_port.drop_listener(); node.rpc_port.drop_listener(); node.prometheus_port.drop_listener(); @@ -183,13 +184,13 @@ where // Create port-forward iff we are not in CI if !running_in_ci() { let ports = futures::future::try_join_all(vec![ - running_node.create_port_forward(node.ws_port.0, RPC_PORT), + running_node.create_port_forward(node.rpc_port.0, RPC_PORT), running_node.create_port_forward(node.prometheus_port.0, PROMETHEUS_PORT), ]) .await?; (rpc_port_external, prometheus_port_external) = ( - ports[0].unwrap_or(node.ws_port.0), + ports[0].unwrap_or(node.rpc_port.0), ports[1].unwrap_or(node.prometheus_port.0), ); } else { diff --git a/crates/provider/src/native/namespace.rs b/crates/provider/src/native/namespace.rs index 966f6d865b1c1acd671b8ac80bff046e82efa2d9..ba31035dc2bbf478146b250052954052f972b4f3 100644 --- a/crates/provider/src/native/namespace.rs +++ b/crates/provider/src/native/namespace.rs @@ -99,6 +99,7 @@ where &options.args, &options.env, &options.injected_files, + &options.created_paths, &self.filesystem, ) .await?; diff --git a/crates/provider/src/native/node.rs b/crates/provider/src/native/node.rs index 078fb805b4000718c05678053b884203c0f05b59..e3866ac5becb5b21573dd32f8e3a07eccc50b800 100644 --- a/crates/provider/src/native/node.rs +++ b/crates/provider/src/native/node.rs @@ -24,6 +24,7 @@ use tokio::{ time::sleep, try_join, }; +use tracing::trace; use super::namespace::NativeNamespace; use crate::{ @@ -67,24 +68,29 @@ where args: &[String], env: &[(String, String)], startup_files: &[TransferedFile], + created_paths: &[PathBuf], filesystem: &FS, ) -> Result<Arc<Self>, ProviderError> { let base_dir = PathBuf::from_iter([&namespace_base_dir, &PathBuf::from(name)]); + trace!("creating base_dir {:?}", base_dir); filesystem.create_dir_all(&base_dir).await?; + trace!("created base_dir {:?}", base_dir); let base_dir_raw = base_dir.to_string_lossy(); let config_dir = PathBuf::from(format!("{}{}", base_dir_raw, NODE_CONFIG_DIR)); let data_dir = PathBuf::from(format!("{}{}", base_dir_raw, NODE_DATA_DIR)); let relay_data_dir = PathBuf::from(format!("{}{}", base_dir_raw, NODE_RELAY_DATA_DIR)); let scripts_dir = PathBuf::from(format!("{}{}", base_dir_raw, NODE_SCRIPTS_DIR)); - let log_path = base_dir.join("node.log"); + let log_path = base_dir.join(format!("{name}.log")); + trace!("creating dirs {:?}", config_dir); try_join!( filesystem.create_dir(&config_dir), filesystem.create_dir(&data_dir), filesystem.create_dir(&relay_data_dir), filesystem.create_dir(&scripts_dir), )?; + trace!("created!"); let node = Arc::new(NativeNode { namespace: namespace.clone(), @@ -105,6 +111,7 @@ where filesystem: filesystem.clone(), }); + node.initialize_startup_paths(created_paths).await?; node.initialize_startup_files(startup_files).await?; let (stdout, stderr) = node.initialize_process().await?; @@ -114,16 +121,31 @@ where Ok(node) } + async fn initialize_startup_paths(&self, paths: &[PathBuf]) -> Result<(), ProviderError> { + trace!("creating paths {:?}", paths); + let base_dir_raw = self.base_dir.to_string_lossy(); + try_join_all(paths.iter().map(|file| { + let full_path = format!("{base_dir_raw}{}", file.to_string_lossy()); + self.filesystem.create_dir_all(full_path) + })) + .await?; + trace!("paths created!"); + + Ok(()) + } + async fn initialize_startup_files( &self, startup_files: &[TransferedFile], ) -> Result<(), ProviderError> { + trace!("creating files {:?}", startup_files); try_join_all( startup_files .iter() .map(|file| self.send_file(&file.local_path, &file.remote_path, &file.mode)), ) .await?; + trace!("files created!"); Ok(()) } diff --git a/crates/sdk/tests/smoke.rs b/crates/sdk/tests/smoke.rs index ce0c2bfae1cac5c13295a877bac3c44fc2eb704b..77844d88e8e1c490c8a38f7c9a92f64acac73cd4 100644 --- a/crates/sdk/tests/smoke.rs +++ b/crates/sdk/tests/smoke.rs @@ -13,7 +13,7 @@ fn small_network() -> NetworkConfig { .with_relaychain(|r| { r.with_chain("rococo-local") .with_default_command("polkadot") - .with_default_image("docker.io/parity/polkadot:v1.4.0") + .with_default_image("docker.io/parity/polkadot:v1.7.0") .with_node(|node| node.with_name("alice")) .with_node(|node| node.with_name("bob")) })