Try-runtime CLI fix weight parsing (#12491)

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Oliver Tale-Yazdi
2022-10-14 13:26:13 +02:00
committed by GitHub
parent 532dd5ecc2
commit 0e729f2327
4 changed files with 13 additions and 8 deletions
+1
View File
@@ -11356,6 +11356,7 @@ dependencies = [
"sp-runtime",
"sp-state-machine",
"sp-version",
"sp-weights",
"tokio",
"zstd",
]
@@ -31,6 +31,7 @@ sp-keystore = { version = "0.12.0", path = "../../../../primitives/keystore" }
sp-runtime = { version = "6.0.0", path = "../../../../primitives/runtime" }
sp-state-machine = { version = "0.12.0", path = "../../../../primitives/state-machine" }
sp-version = { version = "5.0.0", path = "../../../../primitives/version" }
sp-weights = { version = "4.0.0", path = "../../../../primitives/weights" }
frame-try-runtime = { path = "../../../../frame/try-runtime" }
[dev-dependencies]
@@ -33,6 +33,7 @@ use sc_service::Configuration;
use serde::de::DeserializeOwned;
use sp_core::H256;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor};
use sp_weights::Weight;
use std::{collections::VecDeque, fmt::Debug, str::FromStr};
const SUB: &str = "chain_subscribeFinalizedHeads";
@@ -294,8 +295,8 @@ where
full_extensions(),
)?;
let consumed_weight = <u64 as Decode>::decode(&mut &*encoded_result)
.map_err(|e| format!("failed to decode output: {:?}", e))?;
let consumed_weight = <Weight as Decode>::decode(&mut &*encoded_result)
.map_err(|e| format!("failed to decode weight: {:?}", e))?;
let storage_changes = changes
.drain_storage_changes(
@@ -21,6 +21,7 @@ use parity_scale_codec::Decode;
use sc_executor::NativeExecutionDispatch;
use sc_service::Configuration;
use sp_runtime::traits::{Block as BlockT, NumberFor};
use sp_weights::Weight;
use crate::{
build_executor, ensure_matching_spec, extract_code, local_spec, state_machine_call_with_proof,
@@ -78,14 +79,15 @@ where
Default::default(), // we don't really need any extensions here.
)?;
let (weight, total_weight) = <(u64, u64) as Decode>::decode(&mut &*encoded_result)
.map_err(|e| format!("failed to decode output: {:?}", e))?;
let (weight, total_weight) = <(Weight, Weight) as Decode>::decode(&mut &*encoded_result)
.map_err(|e| format!("failed to decode weight: {:?}", e))?;
log::info!(
target: LOG_TARGET,
"TryRuntime_on_runtime_upgrade executed without errors. Consumed weight = {}, total weight = {} ({})",
weight,
total_weight,
weight as f64 / total_weight.max(1) as f64
"TryRuntime_on_runtime_upgrade executed without errors. Consumed weight = ({} ps, {} byte), total weight = ({} ps, {} byte) ({:.2} %, {:.2} %).",
weight.ref_time(), weight.proof_size(),
total_weight.ref_time(), total_weight.proof_size(),
(weight.ref_time() as f64 / total_weight.ref_time().max(1) as f64) * 100.0,
(weight.proof_size() as f64 / total_weight.proof_size().max(1) as f64) * 100.0,
);
Ok(())