diff --git a/Cargo.lock b/Cargo.lock index e877cd9d2486..b80dbc771382 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11132,6 +11132,7 @@ dependencies = [ name = "pallet-parameters" version = "0.1.0" dependencies = [ + "cumulus-primitives-storage-weight-reclaim", "docify", "frame-benchmarking", "frame-support", diff --git a/substrate/frame/parameters/Cargo.toml b/substrate/frame/parameters/Cargo.toml index b718b391019a..7504e67cedb0 100644 --- a/substrate/frame/parameters/Cargo.toml +++ b/substrate/frame/parameters/Cargo.toml @@ -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] @@ -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", diff --git a/substrate/frame/parameters/src/lib.rs b/substrate/frame/parameters/src/lib.rs index 3f85522a3d6b..773a880f37a3 100644 --- a/substrate/frame/parameters/src/lib.rs +++ b/substrate/frame/parameters/src/lib.rs @@ -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)] @@ -170,9 +171,17 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(_: BlockNumberFor) -> Weight { + let proof_size_before: u64 = get_proof_size().unwrap_or(0); + let items = Parameters::::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)) } } @@ -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