Display warning on try-runtime spec_name mismatch (#9593)

* Display warning on try-runtime version mismatch

* detect spec-name mismatch in try-runtime

* Update utils/frame/try-runtime/cli/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/frame/try-runtime/cli/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/frame/remote-externalities/src/rpc_api.rs

Co-authored-by: Chevdor <chevdor@users.noreply.github.com>

* remove unused import

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Chevdor <chevdor@users.noreply.github.com>
This commit is contained in:
Kian Paimani
2021-08-20 19:41:21 +01:00
committed by GitHub
parent 12bf41d24d
commit 7f53a7f9df
4 changed files with 60 additions and 2 deletions
@@ -179,7 +179,7 @@ async fn on_runtime_upgrade<Block, ExecDispatch>(
config: Configuration,
) -> sc_cli::Result<()>
where
Block: BlockT,
Block: BlockT + serde::de::DeserializeOwned,
Block::Hash: FromStr,
<Block::Hash as FromStr>::Err: Debug,
NumberFor<Block>: FromStr,
@@ -198,6 +198,8 @@ where
max_runtime_instances,
);
check_spec_name::<Block>(shared.url.clone(), config.chain_spec.name().to_string()).await;
let ext = {
let builder = match command.state {
State::Snap { snapshot_path } =>
@@ -254,7 +256,7 @@ async fn offchain_worker<Block, ExecDispatch>(
config: Configuration,
) -> sc_cli::Result<()>
where
Block: BlockT,
Block: BlockT + serde::de::DeserializeOwned,
Block::Hash: FromStr,
Block::Header: serde::de::DeserializeOwned,
<Block::Hash as FromStr>::Err: Debug,
@@ -274,6 +276,8 @@ where
max_runtime_instances,
);
check_spec_name::<Block>(shared.url.clone(), config.chain_spec.name().to_string()).await;
let mode = match command.state {
State::Live { snapshot_path, modules } => {
let at = shared.block_at::<Block>()?;
@@ -361,6 +365,8 @@ where
let block_hash = shared.block_at::<Block>()?;
let block: Block = rpc_api::get_block::<Block, _>(shared.url.clone(), block_hash).await?;
check_spec_name::<Block>(shared.url.clone(), config.chain_spec.name().to_string()).await;
let mode = match command.state {
State::Snap { snapshot_path } => {
let mode =
@@ -484,3 +490,32 @@ fn extract_code(spec: Box<dyn ChainSpec>) -> sc_cli::Result<(StorageKey, Storage
Ok((code_key, code))
}
/// Check the spec_name of an `ext`
///
/// If the version does not exist, or if it does not match with the given, it emits a warning.
async fn check_spec_name<Block: BlockT + serde::de::DeserializeOwned>(
uri: String,
expected_spec_name: String,
) {
let expected_spec_name = expected_spec_name.to_lowercase();
match remote_externalities::rpc_api::get_runtime_version::<Block, _>(uri.clone(), None)
.await
.map(|version| String::from(version.spec_name.clone()))
.map(|spec_name| spec_name.to_lowercase())
{
Ok(spec) if spec == expected_spec_name => {
log::debug!("found matching spec name: {:?}", spec);
},
Ok(spec) => {
log::warn!(
"version mismatch: remote spec name: '{}', expected (local chain spec, aka. `--chain`): '{}'",
spec,
expected_spec_name,
);
},
Err(why) => {
log::error!("failed to fetch runtime version from {}: {:?}", uri, why);
},
}
}