From 3bcd7f0fd8a18474c78eb64224ae0dc61e495eea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastian=20K=C3=B6cher?= <bkchr@users.noreply.github.com>
Date: Thu, 13 May 2021 23:35:15 +0200
Subject: [PATCH] Fix chain spec handling (#438)

Before when loading a chain spec from a file it was always using the
rococo parachains runtime genesis config. This leaded to problems when
trying to convert a shell chain spec json file to a raw chain spec.
---
 cumulus/polkadot-parachains/src/command.rs | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/cumulus/polkadot-parachains/src/command.rs b/cumulus/polkadot-parachains/src/command.rs
index 69d48520c3c..67ec05935b6 100644
--- a/cumulus/polkadot-parachains/src/command.rs
+++ b/cumulus/polkadot-parachains/src/command.rs
@@ -49,9 +49,17 @@ fn load_spec(
 		)?)),
 		"shell" => Ok(Box::new(chain_spec::get_shell_chain_spec(para_id))),
 		"" => Ok(Box::new(chain_spec::get_chain_spec(para_id))),
-		path => Ok(Box::new(chain_spec::ChainSpec::from_json_file(
+		path => Ok({
+			let chain_spec = chain_spec::ChainSpec::from_json_file(
 			path.into(),
-		)?)),
+		)?;
+
+			if use_shell_runtime(&chain_spec) {
+				Box::new(chain_spec::ShellChainSpec::from_json_file(path.into())?)
+			} else {
+				Box::new(chain_spec)
+			}
+		}),
 	}
 }
 
@@ -91,7 +99,7 @@ impl SubstrateCli for Cli {
 	}
 
 	fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
-		if use_shell_runtime(chain_spec) {
+		if use_shell_runtime(&**chain_spec) {
 			&shell_runtime::VERSION
 		} else {
 			&rococo_parachain_runtime::VERSION
@@ -149,8 +157,8 @@ fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<V
 		.ok_or_else(|| "Could not find wasm file in genesis state!".into())
 }
 
-fn use_shell_runtime(chain_spec: &Box<dyn ChainSpec>) -> bool {
-	chain_spec.id().starts_with("track") || chain_spec.id().starts_with("shell")
+fn use_shell_runtime(chain_spec: &dyn ChainSpec) -> bool {
+	chain_spec.id().starts_with("shell")
 }
 
 use crate::service::{new_partial, RococoParachainRuntimeExecutor, ShellRuntimeExecutor};
@@ -158,7 +166,7 @@ use crate::service::{new_partial, RococoParachainRuntimeExecutor, ShellRuntimeEx
 macro_rules! construct_async_run {
 	(|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{
 		let runner = $cli.create_runner($cmd)?;
-		if use_shell_runtime(&runner.config().chain_spec) {
+		if use_shell_runtime(&*runner.config().chain_spec) {
 			runner.async_run(|$config| {
 				let $components = new_partial::<shell_runtime::RuntimeApi, ShellRuntimeExecutor, _>(
 					&$config,
@@ -284,7 +292,7 @@ pub fn run() -> Result<()> {
 		}
 		None => {
 			let runner = cli.create_runner(&cli.run.normalize())?;
-			let use_shell = use_shell_runtime(&runner.config().chain_spec);
+			let use_shell = use_shell_runtime(&*runner.config().chain_spec);
 
 			runner.run_node_until_exit(|config| async move {
 				// TODO
-- 
GitLab