Skip to content

Commit f646b9b

Browse files
libreloismanuelmauro
authored andcommitted
Merge pull request #8 from moonbeam-foundation/tarekkma/pallet-parameters-account-weight
1 parent 8563066 commit f646b9b

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substrate/frame/parameters/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ frame-system.workspace = true
1818
sp-core.workspace = true
1919
sp-runtime.workspace = true
2020
frame-benchmarking = { optional = true, workspace = true }
21+
cumulus-primitives-storage-weight-reclaim = { workspace = true, default-features = false}
2122

2223
[dev-dependencies]
2324
sp-core = { features = ["std"], default-features = true, path = "../../primitives/core" }
@@ -36,6 +37,7 @@ std = [
3637
"serde",
3738
"sp-core/std",
3839
"sp-runtime/std",
40+
"cumulus-primitives-storage-weight-reclaim/std",
3941
]
4042
runtime-benchmarks = [
4143
"frame-benchmarking/runtime-benchmarks",

substrate/frame/parameters/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ use frame_support::traits::{
125125
dynamic_params::{AggregatedKeyValue, IntoKey, Key, RuntimeParameterStore, TryIntoKey},
126126
EnsureOriginWithArg,
127127
};
128+
use cumulus_primitives_storage_weight_reclaim::get_proof_size;
128129

129130
mod benchmarking;
130131
#[cfg(test)]
@@ -167,6 +168,22 @@ pub mod pallet {
167168
type WeightInfo: WeightInfo;
168169
}
169170

171+
#[pallet::hooks]
172+
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
173+
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
174+
let proof_size_before: u64 = get_proof_size().unwrap_or(0);
175+
176+
let items = Parameters::<T>::iter().count() as u64;
177+
178+
let proof_size_after: u64 = get_proof_size().unwrap_or(0);
179+
180+
let proof_size_diff = proof_size_after.saturating_sub(proof_size_before);
181+
182+
Weight::from_parts(0, proof_size_diff)
183+
.saturating_add(T::DbWeight::get().reads(items))
184+
}
185+
}
186+
170187
#[pallet::event]
171188
#[pallet::generate_deposit(pub(crate) fn deposit_event)]
172189
pub enum Event<T: Config> {

0 commit comments

Comments
 (0)