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

Try-runtime CLI fix weight decoding #12491

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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