Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
3dd3249
Fixup read/write benchmark
alexggh Mar 10, 2025
4540be0
Address review feedback
alexggh Mar 14, 2025
bd3b0cb
Make clippy happy
alexggh Mar 19, 2025
5c3b0b3
Update substrate/utils/frame/benchmarking-cli/src/storage/cmd.rs
alexggh Mar 27, 2025
6b59fe8
Update substrate/utils/frame/benchmarking-cli/src/storage/read.rs
alexggh Mar 27, 2025
22e4cf4
Update substrate/utils/frame/benchmarking-cli/src/storage/read.rs
alexggh Mar 27, 2025
e38d2ca
Update substrate/utils/frame/benchmarking-cli/src/storage/write.rs
alexggh Mar 27, 2025
b33f629
Apply review feedback
alexggh Mar 27, 2025
9ac3a52
Add prdoc
alexggh Mar 31, 2025
18caf04
Update pr_7867.prdoc
alexggh Mar 31, 2025
022af2d
Fixup prdoc
alexggh Apr 1, 2025
8699d5d
Add dummy test runtime
AndreiEres Mar 27, 2025
dda8492
Run empty validation
AndreiEres Mar 27, 2025
0c2e183
Add the working benchmark but without reading child keys
AndreiEres Apr 1, 2025
1d4f01e
Add dry run correction
AndreiEres Apr 2, 2025
247fb6d
Update params
AndreiEres Apr 3, 2025
427ba86
Merge payload and modes
AndreiEres Apr 3, 2025
73ed34a
Move common function
AndreiEres Apr 3, 2025
71a24d9
Add write bench
AndreiEres Apr 4, 2025
acfb95b
Add on_block_validation
AndreiEres Apr 7, 2025
703675c
Add different measurements
AndreiEres Apr 7, 2025
ce8120a
Update read bench to use on_block_validation
AndreiEres Apr 7, 2025
781e0d3
Remove todo
AndreiEres Apr 7, 2025
5a1da9e
Notify about not processed remainder
AndreiEres Apr 8, 2025
0b99284
Use default config
AndreiEres Apr 8, 2025
4bd6024
Update Cargo.lock after rebase
AndreiEres Apr 8, 2025
2a39c1d
Update Cargo.toml after rebase
AndreiEres Apr 8, 2025
95676fb
Don't change pr_7867.prdoc
AndreiEres Apr 8, 2025
1827238
Add reading of child keys
AndreiEres Apr 8, 2025
e6b4eed
Read remainder even with batch size
AndreiEres Apr 9, 2025
db989a7
Add writing child keys
AndreiEres Apr 9, 2025
f695a52
Merge branch 'master' into AndreiEres/benchmark-storage-access-on-blo…
AndreiEres Apr 9, 2025
f123504
Polish
AndreiEres Apr 9, 2025
94f75ba
Add prdoc
AndreiEres Apr 9, 2025
26ca47b
Add runtime_dev to audience
AndreiEres Apr 10, 2025
8564661
Merge branch 'master' into AndreiEres/benchmark-storage-access-on-blo…
AndreiEres Apr 10, 2025
909730a
Make the output less spammy
AndreiEres Apr 11, 2025
1025b9e
Hide under feature
AndreiEres Apr 11, 2025
d75d998
Extract create_backend
AndreiEres Apr 11, 2025
2ba2bee
Don't run on child nodes if they're empty
AndreiEres Apr 11, 2025
e3a2b83
Extract measure_on_block_validation
AndreiEres Apr 11, 2025
39fece2
Extract write measurements
AndreiEres Apr 11, 2025
d56c948
Fix compile errors
AndreiEres Apr 12, 2025
934068f
Fix errors
AndreiEres Apr 13, 2025
8a4b4d2
Update prdoc
AndreiEres Apr 13, 2025
3d7da55
Use different files to write results
AndreiEres Apr 22, 2025
bf7b7bf
Update config
AndreiEres Apr 23, 2025
7813895
Make frame-storage-access-test-runtime publishable
AndreiEres Apr 23, 2025
0fe7817
Add storage-access-test-runtime to workspace members
AndreiEres Apr 23, 2025
f570b7d
Use config
AndreiEres Apr 23, 2025
c3feabc
Add description
AndreiEres Apr 23, 2025
8950a2e
Update PR doc
AndreiEres Apr 23, 2025
b283212
Fix toml
AndreiEres Apr 23, 2025
9d90eb5
Propogate runtime-benchmarks
AndreiEres Apr 23, 2025
bf69654
Propogate std
AndreiEres Apr 23, 2025
feb3c18
Fix toml
AndreiEres Apr 23, 2025
a7d59f5
Add missing docs
AndreiEres Apr 23, 2025
c13b6ea
Hide proceed_storage_access under runtime-benchmarks
AndreiEres Apr 23, 2025
5371abc
Fix imports
AndreiEres Apr 23, 2025
648e093
Fix missing import
AndreiEres Apr 23, 2025
2d09498
Merge branch 'master' into AndreiEres/benchmark-storage-access-on-blo…
AndreiEres Apr 24, 2025
d1b9e3e
Update substrate/utils/frame/benchmarking-cli/src/storage/write.rs
AndreiEres Apr 30, 2025
08ccd4c
Update substrate/utils/frame/benchmarking-cli/src/storage/weights.hbs
AndreiEres Apr 30, 2025
7f55e39
Decrease extra_heap_pages
AndreiEres Apr 30, 2025
74dfe10
Remove repeating comment
AndreiEres Apr 30, 2025
5e77da0
Remove overrides
AndreiEres Apr 30, 2025
daa0e78
Remove proceed_storage_access from implementation
AndreiEres Apr 30, 2025
de0a0de
Move implementation to frame_storage_access_test_runtime
AndreiEres Apr 30, 2025
e5e1bd7
Merge remote-tracking branch 'origin/master' into AndreiEres/benchmar…
AndreiEres May 15, 2025
10030ae
Revert changes from validate_block
AndreiEres May 15, 2025
7f6c95c
Remove unused deps
AndreiEres May 15, 2025
aace653
Fix compilation errors
AndreiEres May 15, 2025
536ad09
Fix deps
AndreiEres May 15, 2025
a64f972
Add docs
AndreiEres May 15, 2025
fc5c5a8
Add on_block_validation_rounds
AndreiEres May 16, 2025
4993c65
Remove redundant CompactProof encoding
AndreiEres May 16, 2025
7f1552a
Remove runtime-benchmarks from the testing runtime
AndreiEres May 20, 2025
03c12c3
Avoid unwraps
AndreiEres May 20, 2025
62143ee
Use saturating_sub
AndreiEres May 20, 2025
e0505e6
Use 20 on_block_validation_rounds by default
AndreiEres May 20, 2025
3a49743
Remove unnecessary pvf config import
AndreiEres May 20, 2025
34a7171
Fix features
AndreiEres May 20, 2025
df83321
Revert "Fix features"
AndreiEres May 20, 2025
7d68f00
Revert "Remove runtime-benchmarks from the testing runtime"
AndreiEres May 20, 2025
04d22aa
Use enum for storage benchmar mode selection
AndreiEres May 21, 2025
ffc17bd
Fix InMemoryDb name usage
AndreiEres May 21, 2025
0b5f597
Fix names
AndreiEres May 21, 2025
2a318d5
Update substrate/utils/frame/benchmarking-cli/src/storage/cmd.rs
AndreiEres May 22, 2025
ce323e7
Update substrate/utils/frame/benchmarking-cli/src/storage/read.rs
AndreiEres May 22, 2025
a6c7fed
Replace asserts with errors
AndreiEres May 22, 2025
5ecfa34
Merge branch 'master' into AndreiEres/benchmark-storage-access-on-blo…
AndreiEres May 22, 2025
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
16 changes: 16 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ members = [
"substrate/utils/frame/rpc/state-trie-migration-rpc",
"substrate/utils/frame/rpc/support",
"substrate/utils/frame/rpc/system",
"substrate/utils/frame/storage-access-test-runtime",
"substrate/utils/prometheus",
"substrate/utils/substrate-bip39",
"substrate/utils/wasm-builder",
Expand Down Expand Up @@ -806,6 +807,7 @@ frame-election-provider-support = { path = "substrate/frame/election-provider-su
frame-executive = { path = "substrate/frame/executive", default-features = false }
frame-metadata = { version = "23.0.0", default-features = false }
frame-metadata-hash-extension = { path = "substrate/frame/metadata-hash-extension", default-features = false }
frame-storage-access-test-runtime = { path = "substrate/utils/frame/storage-access-test-runtime", default-features = false }
frame-support = { path = "substrate/frame/support", default-features = false }
frame-support-procedural = { path = "substrate/frame/support/procedural", default-features = false }
frame-support-procedural-tools = { path = "substrate/frame/support/procedural/tools", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions cumulus/pallets/parachain-system/src/validate_block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ mod tests;

#[cfg(not(feature = "std"))]
#[doc(hidden)]
mod trie_cache;
pub mod trie_cache;

#[cfg(any(test, not(feature = "std")))]
#[doc(hidden)]
mod trie_recorder;
pub mod trie_recorder;

#[cfg(not(feature = "std"))]
#[doc(hidden)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use trie_db::{node::NodeOwned, Hasher};
/// Special purpose trie cache implementation that is able to cache an unlimited number
/// of values. To be used in `validate_block` to serve values and nodes that
/// have already been loaded and decoded from the storage proof.
pub(crate) struct TrieCache<'a, H: Hasher> {
pub struct TrieCache<'a, H: Hasher> {
node_cache: RefMut<'a, BTreeMap<H::Out, NodeOwned<H::Out>>>,
value_cache: Option<RefMut<'a, BTreeMap<Box<[u8]>, trie_db::CachedValue<H::Out>>>>,
}
Expand Down Expand Up @@ -65,7 +65,7 @@ impl<'a, H: Hasher> trie_db::TrieCache<NodeCodec<H>> for TrieCache<'a, H> {
}

/// Provider of [`TrieCache`] instances.
pub(crate) struct CacheProvider<H: Hasher> {
pub struct CacheProvider<H: Hasher> {
node_cache: RefCell<BTreeMap<H::Out, NodeOwned<H::Out>>>,
/// Cache: `storage_root` => `storage_key` => `value`.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use trie_db::{Hasher, RecordedForKey, TrieAccess};
///
/// The internal size counting logic should align
/// with ['sp_trie::recorder::Recorder'].
pub(crate) struct SizeOnlyRecorder<'a, H: Hasher> {
pub struct SizeOnlyRecorder<'a, H: Hasher> {
seen_nodes: RefMut<'a, BTreeSet<H::Out>>,
encoded_size: RefMut<'a, usize>,
recorded_keys: RefMut<'a, BTreeMap<Rc<[u8]>, RecordedForKey>>,
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<'a, H: trie_db::Hasher> trie_db::TrieRecorder<H::Out> for SizeOnlyRecorder<
}

#[derive(Clone)]
pub(crate) struct SizeOnlyRecorderProvider<H: Hasher> {
pub struct SizeOnlyRecorderProvider<H: Hasher> {
seen_nodes: Rc<RefCell<BTreeSet<H::Out>>>,
encoded_size: Rc<RefCell<usize>>,
recorded_keys: Rc<RefCell<BTreeMap<Rc<[u8]>, RecordedForKey>>>,
Expand Down
17 changes: 17 additions & 0 deletions prdoc/pr_8069.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Benchmark storage access on block validation

doc:
- audience: [Runtime Dev, Node Dev]
description: |
Adds checking storage weights on block validation for both read and write benchmarks.

crates:
- name: cumulus-pallet-parachain-system
bump: minor
- name: frame-benchmarking-cli
bump: minor
- name: frame-storage-access-test-runtime
bump: major
4 changes: 4 additions & 0 deletions substrate/utils/frame/benchmarking-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ comfy-table = { workspace = true }
cumulus-client-parachain-inherent = { workspace = true, default-features = true }
cumulus-primitives-proof-size-hostfunction = { workspace = true, default-features = true }
frame-benchmarking = { workspace = true, default-features = true }
frame-storage-access-test-runtime = { workspace = true, default-features = true }
frame-support = { workspace = true, default-features = true }
frame-system = { workspace = true, default-features = true }
gethostname = { workspace = true }
Expand All @@ -42,6 +43,8 @@ sc-cli = { workspace = true, default-features = false }
sc-client-api = { workspace = true, default-features = true }
sc-client-db = { workspace = true, default-features = false }
sc-executor = { workspace = true, default-features = true }
sc-executor-common = { workspace = true }
sc-executor-wasmtime = { workspace = true }
sc-runtime-utilities = { workspace = true, default-features = true }
sc-service = { workspace = true, default-features = false }
sc-sysinfo = { workspace = true, default-features = true }
Expand Down Expand Up @@ -79,6 +82,7 @@ westend-runtime = { workspace = true, default-features = true }
default = []
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-storage-access-test-runtime/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
Expand Down
37 changes: 35 additions & 2 deletions substrate/utils/frame/benchmarking-cli/src/storage/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use sp_runtime::traits::{Block as BlockT, HashingFor};
use sp_state_machine::Storage;
use sp_storage::{ChildInfo, ChildType, PrefixedStorageKey, StateVersion};

use clap::{Args, Parser};
use clap::{Args, Parser, ValueEnum};
use log::info;
use rand::prelude::*;
use serde::Serialize;
Expand All @@ -36,6 +36,16 @@ use std::{fmt::Debug, path::PathBuf, sync::Arc};
use super::template::TemplateData;
use crate::shared::{new_rng, HostInfoParams, WeightParams};

/// The mode in which to run the storage benchmark.
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, ValueEnum)]
pub enum StorageBenchmarkMode {
/// Run the benchmark for block import.
#[default]
ImportBlock,
/// Run the benchmark for block validation.
ValidateBlock,
}

/// Benchmark the storage speed of a chain snapshot.
#[derive(Debug, Parser)]
pub struct StorageCmd {
Expand Down Expand Up @@ -129,13 +139,36 @@ pub struct StorageParams {
#[arg(long, default_value = "false")]
pub disable_pov_recorder: bool,

/// The batch size for the write benchmark.
/// The batch size for the read/write benchmark.
///
/// Since the write size needs to also include the cost of computing the storage root, which is
/// done once at the end of the block, the batch size is used to simulate multiple writes in a
/// block.
#[arg(long, default_value_t = 100_000)]
pub batch_size: usize,

/// The mode in which to run the storage benchmark.
///
/// PoV recorder must be activated to provide a storage proof for block validation at runtime.
Comment thread
AndreiEres marked this conversation as resolved.
#[arg(long, value_enum, default_value_t = StorageBenchmarkMode::ImportBlock)]
pub mode: StorageBenchmarkMode,

/// Number of rounds to execute block validation during the benchmark.
///
/// We need to run the benchmark several times to avoid fluctuations during runtime setup.
/// This is only used when `mode` is `validate-block`.
#[arg(long, default_value_t = 20)]
pub validate_block_rounds: u32,
}

impl StorageParams {
pub fn is_import_block_mode(&self) -> bool {
matches!(self.mode, StorageBenchmarkMode::ImportBlock)
}

pub fn is_validate_block_mode(&self) -> bool {
matches!(self.mode, StorageBenchmarkMode::ValidateBlock)
}
}

impl StorageCmd {
Expand Down
34 changes: 34 additions & 0 deletions substrate/utils/frame/benchmarking-cli/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,37 @@ pub mod template;
pub mod write;

pub use cmd::StorageCmd;

/// Empirically, the maximum batch size for block validation should be no more than 10,000.
/// Bigger sizes may cause problems with runtime memory allocation.
pub(crate) const MAX_BATCH_SIZE_FOR_BLOCK_VALIDATION: usize = 10_000;

pub(crate) fn get_wasm_module() -> Box<dyn sc_executor_common::wasm_runtime::WasmModule> {
let blob = sc_executor_common::runtime_blob::RuntimeBlob::uncompress_if_needed(
frame_storage_access_test_runtime::WASM_BINARY
.expect("You need to build the WASM binaries to run the benchmark!"),
)
.expect("Failed to create runtime blob");
let config = sc_executor_wasmtime::Config {
Comment thread
AndreiEres marked this conversation as resolved.
allow_missing_func_imports: true,
cache_path: None,
semantics: sc_executor_wasmtime::Semantics {
heap_alloc_strategy: sc_executor_common::wasm_runtime::HeapAllocStrategy::Dynamic {
maximum_pages: Some(4096),
},
instantiation_strategy: sc_executor::WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
deterministic_stack_limit: None,
canonicalize_nans: false,
parallel_compilation: false,
wasm_multi_value: false,
wasm_bulk_memory: false,
wasm_reference_types: false,
wasm_simd: false,
},
};

Box::new(
sc_executor_wasmtime::create_runtime::<sp_io::SubstrateHostFunctions>(blob, config)
.expect("Unable to create wasm module."),
)
}
Loading
Loading