Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Try-runtime CLI fix weight parsing (#12491)
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
ggwpez authored Oct 14, 2022
1 parent f313987 commit 0ee0327
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions utils/frame/try-runtime/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions utils/frame/try-runtime/cli/src/commands/follow_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 8 additions & 6 deletions utils/frame/try-runtime/cli/src/commands/on_runtime_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 0ee0327

Please sign in to comment.