mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 07:41:08 +00:00
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:
Generated
+1
@@ -7101,6 +7101,7 @@ dependencies = [
|
||||
"sp-core",
|
||||
"sp-io",
|
||||
"sp-runtime",
|
||||
"sp-version",
|
||||
"tokio 0.2.25",
|
||||
]
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ serde = "1.0.126"
|
||||
sp-io = { version = "4.0.0-dev", path = "../../../primitives/io" }
|
||||
sp-core = { version = "4.0.0-dev", path = "../../../primitives/core" }
|
||||
sp-runtime = { version = "4.0.0-dev", path = "../../../primitives/runtime" }
|
||||
sp-version = { version = "4.0.0-dev", path = "../../../primitives/version" }
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "0.2", features = ["macros", "rt-threaded"] }
|
||||
|
||||
@@ -88,3 +88,24 @@ async fn build_client<S: AsRef<str>>(from: S) -> Result<WsClient, String> {
|
||||
.await
|
||||
.map_err(|e| format!("`WsClientBuilder` failed to build: {:?}", e))
|
||||
}
|
||||
|
||||
/// Get the runtime version of a given chain.
|
||||
pub async fn get_runtime_version<Block, S>(
|
||||
from: S,
|
||||
at: Option<Block::Hash>,
|
||||
) -> Result<sp_version::RuntimeVersion, String>
|
||||
where
|
||||
S: AsRef<str>,
|
||||
Block: BlockT + serde::de::DeserializeOwned,
|
||||
Block::Header: HeaderT,
|
||||
{
|
||||
let params = if let Some(at) = at { vec![hash_to_json::<Block>(at)?] } else { vec![] };
|
||||
let client = build_client(from).await?;
|
||||
client
|
||||
.request::<sp_version::RuntimeVersion>(
|
||||
"state_getRuntimeVersion",
|
||||
JsonRpcParams::Array(params),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| format!("state_getRuntimeVersion request failed: {:?}", e))
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user