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

Rework InspectState #7271

Merged
1 commit merged into from
Oct 6, 2020
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
6 changes: 4 additions & 2 deletions bin/node/bench/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ impl core::Benchmark for ImportBenchmark {
let elapsed = start.elapsed();

// Sanity checks.
context.client.state_at(&BlockId::number(1)).expect("state_at failed for block#1")
.inspect_with(|| {
context.client
.state_at(&BlockId::number(1))
.expect("state_at failed for block#1")
.inspect_state(|| {
match self.block_type {
BlockType::RandomTransfersKeepAlive => {
// should be 5 per signed extrinsic + 1 per unsigned
Expand Down
6 changes: 4 additions & 2 deletions primitives/state-machine/src/read_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ pub trait InspectState<H: Hasher, B: Backend<H>> {
///
/// Self will be set as read-only externalities and inspection
/// closure will be run against it.
fn inspect_with<F: FnOnce()>(&self, f: F);
///
/// Returns the result of the closure.
fn inspect_state<F: FnOnce() -> R, R>(&self, f: F) -> R;
}

impl<H: Hasher, B: Backend<H>> InspectState<H, B> for B {
fn inspect_with<F: FnOnce()>(&self, f: F) {
fn inspect_state<F: FnOnce() -> R, R>(&self, f: F) -> R {
ReadOnlyExternalities::from(self).execute_with(f)
}
}
Expand Down