From 27a3e50c7f7507b045bf597be03fbd807a4cf899 Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Fri, 15 Sep 2023 10:06:45 +0200 Subject: [PATCH 1/2] Update smoldot, improve chainspec loading error message --- Cargo.lock | 8 ++++---- cumulus/client/relay-chain-rpc-interface/Cargo.toml | 4 ++-- cumulus/polkadot-parachain/src/command.rs | 4 +++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c254302517f0..85b0c9c82567 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16527,9 +16527,9 @@ dependencies = [ [[package]] name = "smoldot" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0bb30cf57b7b5f6109ce17c3164445e2d6f270af2cb48f6e4d31c2967c9a9f5" +checksum = "4388a7690d9f76320dedc7f97f213160fbe4fb4a38a8b4cc8bb96e0fd05e0971" dependencies = [ "arrayvec 0.7.4", "async-lock", @@ -16581,9 +16581,9 @@ dependencies = [ [[package]] name = "smoldot-light" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "256b5bad1d6b49045e95fe87492ce73d5af81545d8b4d8318a872d2007024c33" +checksum = "bea3d21923cbdb1362205ff8b2adb5da67e6b81b34c4bba1baaef9b88cbd83b8" dependencies = [ "async-channel", "async-lock", diff --git a/cumulus/client/relay-chain-rpc-interface/Cargo.toml b/cumulus/client/relay-chain-rpc-interface/Cargo.toml index 305ab82b064c..89bdd9aa4aab 100644 --- a/cumulus/client/relay-chain-rpc-interface/Cargo.toml +++ b/cumulus/client/relay-chain-rpc-interface/Cargo.toml @@ -35,8 +35,8 @@ url = "2.4.0" serde_json = "1.0.105" serde = "1.0.188" schnellru = "0.2.1" -smoldot = { version = "0.11.0", default_features = false, features = ["std"]} -smoldot-light = { version = "0.9.0", default_features = false, features = ["std"] } +smoldot = { version = "0.12.0", default_features = false, features = ["std"]} +smoldot-light = { version = "0.10.0", default_features = false, features = ["std"] } either = "1.8.1" thiserror = "1.0.48" rand = "0.8.5" diff --git a/cumulus/polkadot-parachain/src/command.rs b/cumulus/polkadot-parachain/src/command.rs index 596b7baf6710..69291d56a455 100644 --- a/cumulus/polkadot-parachain/src/command.rs +++ b/cumulus/polkadot-parachain/src/command.rs @@ -69,7 +69,9 @@ impl RuntimeResolver for PathBuf { id: String, } - let file = std::fs::File::open(self).expect("Failed to open file"); + let file = std::fs::File::open(self) + .unwrap_or_else(|e| panic!("Failed to open chainspec '{}': {e}", self.display())); + let reader = std::io::BufReader::new(file); let chain_spec: EmptyChainSpecWithId = serde_json::from_reader(reader) .expect("Failed to read 'json' file with ChainSpec configuration"); From 0bf9074df06cf0f0067c830f37ed1a6809afa799 Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Mon, 18 Sep 2023 15:46:40 +0200 Subject: [PATCH 2/2] Return Result from RuntimeResolver trait --- cumulus/polkadot-parachain/src/command.rs | 36 ++++++++++++----------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/cumulus/polkadot-parachain/src/command.rs b/cumulus/polkadot-parachain/src/command.rs index 69291d56a455..4fadef7aa412 100644 --- a/cumulus/polkadot-parachain/src/command.rs +++ b/cumulus/polkadot-parachain/src/command.rs @@ -52,31 +52,30 @@ enum Runtime { } trait RuntimeResolver { - fn runtime(&self) -> Runtime; + fn runtime(&self) -> Result; } impl RuntimeResolver for dyn ChainSpec { - fn runtime(&self) -> Runtime { - runtime(self.id()) + fn runtime(&self) -> Result { + Ok(runtime(self.id())) } } /// Implementation, that can resolve [`Runtime`] from any json configuration file impl RuntimeResolver for PathBuf { - fn runtime(&self) -> Runtime { + fn runtime(&self) -> Result { #[derive(Debug, serde::Deserialize)] struct EmptyChainSpecWithId { id: String, } - let file = std::fs::File::open(self) - .unwrap_or_else(|e| panic!("Failed to open chainspec '{}': {e}", self.display())); + let file = std::fs::File::open(self)?; let reader = std::io::BufReader::new(file); let chain_spec: EmptyChainSpecWithId = serde_json::from_reader(reader) .expect("Failed to read 'json' file with ChainSpec configuration"); - runtime(&chain_spec.id) + Ok(runtime(&chain_spec.id)) } } @@ -245,7 +244,10 @@ fn load_spec(id: &str) -> std::result::Result, String> { // -- Loading a specific spec from disk path => { let path: PathBuf = path.into(); - match path.runtime() { + match path + .runtime() + .map_err(|e| format!("Failed to open chainspec '{}': {e}", path.display()))? + { Runtime::AssetHubPolkadot => Box::new( chain_spec::asset_hubs::AssetHubPolkadotChainSpec::from_json_file(path)?, ), @@ -385,7 +387,7 @@ impl SubstrateCli for RelayChainCli { /// Creates partial components for the runtimes that are supported by the benchmarks. macro_rules! construct_benchmark_partials { ($config:expr, |$partials:ident| $code:expr) => { - match $config.chain_spec.runtime() { + match $config.chain_spec.runtime()? { Runtime::AssetHubKusama => { let $partials = new_partial::( &$config, @@ -466,7 +468,7 @@ macro_rules! construct_benchmark_partials { macro_rules! construct_async_run { (|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{ let runner = $cli.create_runner($cmd)?; - match runner.config().chain_spec.runtime() { + match runner.config().chain_spec.runtime()? { Runtime::AssetHubWestend => { runner.async_run(|$config| { let $components = new_partial::( @@ -801,7 +803,7 @@ pub fn run() -> Result<()> { info!("Parachain Account: {}", parachain_account); info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" }); - match config.chain_spec.runtime() { + match config.chain_spec.runtime()? { Runtime::AssetHubPolkadot => crate::service::start_generic_aura_node::< asset_hub_polkadot_runtime::RuntimeApi, AssetHubPolkadotAuraId, @@ -1137,36 +1139,36 @@ mod tests { &temp_dir, Box::new(create_default_with_extensions("shell-1", Extensions1::default())), ); - assert_eq!(Runtime::Shell, path.runtime()); + assert_eq!(Runtime::Shell, path.runtime().unwrap()); let path = store_configuration( &temp_dir, Box::new(create_default_with_extensions("shell-2", Extensions2::default())), ); - assert_eq!(Runtime::Shell, path.runtime()); + assert_eq!(Runtime::Shell, path.runtime().unwrap()); let path = store_configuration( &temp_dir, Box::new(create_default_with_extensions("seedling", Extensions2::default())), ); - assert_eq!(Runtime::Seedling, path.runtime()); + assert_eq!(Runtime::Seedling, path.runtime().unwrap()); let path = store_configuration( &temp_dir, Box::new(crate::chain_spec::rococo_parachain::rococo_parachain_local_config()), ); - assert_eq!(Runtime::Default, path.runtime()); + assert_eq!(Runtime::Default, path.runtime().unwrap()); let path = store_configuration( &temp_dir, Box::new(crate::chain_spec::asset_hubs::asset_hub_kusama_local_config()), ); - assert_eq!(Runtime::AssetHubKusama, path.runtime()); + assert_eq!(Runtime::AssetHubKusama, path.runtime().unwrap()); let path = store_configuration( &temp_dir, Box::new(crate::chain_spec::contracts::contracts_rococo_local_config()), ); - assert_eq!(Runtime::ContractsRococo, path.runtime()); + assert_eq!(Runtime::ContractsRococo, path.runtime().unwrap()); } }