Skip to content

Commit

Permalink
add proof size
Browse files Browse the repository at this point in the history
  • Loading branch information
TarekkMA committed Aug 5, 2024
1 parent 5276bf9 commit 34af46a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 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.

2 changes: 2 additions & 0 deletions substrate/frame/parameters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ frame-system = { path = "../system", default-features = false }
sp-core = { path = "../../primitives/core", default-features = false }
sp-runtime = { path = "../../primitives/runtime", default-features = false }
sp-std = { path = "../../primitives/std", default-features = false }
cumulus-primitives-storage-weight-reclaim = { path = "../../../cumulus/primitives/storage-weight-reclaim", default-features = false}
frame-benchmarking = { path = "../benchmarking", default-features = false, optional = true }

[dev-dependencies]
Expand All @@ -39,6 +40,7 @@ std = [
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
"cumulus-primitives-storage-weight-reclaim/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
13 changes: 11 additions & 2 deletions substrate/frame/parameters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ use frame_support::traits::{
dynamic_params::{AggregatedKeyValue, IntoKey, Key, RuntimeParameterStore, TryIntoKey},
EnsureOriginWithArg,
};
use cumulus_primitives_storage_weight_reclaim::get_proof_size;

mod benchmarking;
#[cfg(test)]
Expand Down Expand Up @@ -170,9 +171,17 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
let proof_size_before: u64 = get_proof_size().unwrap_or(0);

let items = Parameters::<T>::iter().count() as u64;

Weight::zero().saturating_add(T::DbWeight::get().reads(items))
let proof_size_after: u64 = get_proof_size().unwrap_or(0);

let proof_size_diff = proof_size_after.saturating_sub(proof_size_before);

Weight::zero()
.saturating_add(T::DbWeight::get().reads(items))
.saturating_add(Weight::from_parts(0, proof_size_diff))
}
}

Expand All @@ -193,7 +202,7 @@ pub mod pallet {
}

/// Stored parameters.
///
///
/// ## Storage Whitelist
/// Since we account for all parameters read weight for each block,
/// don't double count it in other pallet benchmarks
Expand Down

0 comments on commit 34af46a

Please sign in to comment.