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

try-runtime: add cli option --export-proof #12539

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -14,6 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
clap = { version = "4.0.9", features = ["derive"] }
hex = { version = "0.4.3", default-features = false }
log = "0.4.17"
parity-scale-codec = "3.0.0"
serde = "1.0.136"
Expand Down
1 change: 1 addition & 0 deletions utils/frame/try-runtime/cli/src/commands/execute_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ where
"TryRuntime_execute_block",
&payload,
full_extensions(),
shared.export_proof,
)?;

log::info!(target: LOG_TARGET, "Core_execute_block executed without errors.");
Expand Down
4 changes: 4 additions & 0 deletions utils/frame/try-runtime/cli/src/commands/follow_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ where
"TryRuntime_execute_block",
(block, command.state_root_check, command.try_state.clone()).encode().as_ref(),
full_extensions(),
shared
.export_proof
.as_ref()
.map(|path| path.as_path().join(&format!("{}-{}", number, hash))),
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
)?;

let consumed_weight = <sp_weights::Weight as Decode>::decode(&mut &*encoded_result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ where
"TryRuntime_on_runtime_upgrade",
&[],
Default::default(), // we don't really need any extensions here.
shared.export_proof,
)?;

let (weight, total_weight) = <(Weight, Weight) as Decode>::decode(&mut &*encoded_result)
Expand Down
16 changes: 15 additions & 1 deletion utils/frame/try-runtime/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
//! added, given the right flag:
//!
//! ```ignore
//!
//!
//! #[cfg(feature = try-runtime)]
//! fn pre_upgrade() -> Result<Vec<u8>, &'static str> {}
//!
Expand Down Expand Up @@ -431,6 +431,12 @@ pub struct SharedParams {
/// State version that is used by the chain.
#[arg(long, default_value_t = StateVersion::V1, value_parser = parse::state_version)]
pub state_version: StateVersion,

/// Path to a file to extract the storage proof
librelois marked this conversation as resolved.
Show resolved Hide resolved
/// If several blocks are executed, the path is interpreted as a folder
/// where one file per block will be written (named `{block_number}-{block_hash}`).
#[clap(long, parse(from_os_str))]
pub export_proof: Option<PathBuf>,
}

/// Our `try-runtime` command.
Expand Down Expand Up @@ -756,6 +762,7 @@ pub(crate) fn state_machine_call_with_proof<Block: BlockT, D: NativeExecutionDis
method: &'static str,
data: &[u8],
extensions: Extensions,
maybe_export_proof: Option<PathBuf>,
) -> sc_cli::Result<(OverlayedChanges, Vec<u8>)> {
use parity_scale_codec::Encode;
use sp_core::hexdisplay::HexDisplay;
Expand Down Expand Up @@ -788,6 +795,13 @@ pub(crate) fn state_machine_call_with_proof<Block: BlockT, D: NativeExecutionDis
let proof = proving_backend
.extract_proof()
.expect("A recorder was set and thus, a storage proof can be extracted; qed");

if let Some(path) = maybe_export_proof {
let mut file = std::fs::File::create(path)?;
use std::io::Write as _;
proof.using_encoded(|encoded_proof| file.write_all(encoded_proof))?;
librelois marked this conversation as resolved.
Show resolved Hide resolved
}

let proof_size = proof.encoded_size();
let compact_proof = proof
.clone()
Expand Down