Skip to content

Commit

Permalink
Merge pull request #8 from moonbeam-foundation/tarekkma/pallet-parame…
Browse files Browse the repository at this point in the history
…ters-account-weight
  • Loading branch information
librelois authored and gonzamontiel committed Sep 20, 2024
1 parent f9fdbb3 commit b056710
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 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 @@ -18,6 +18,7 @@ frame-system.workspace = true
sp-core.workspace = true
sp-runtime.workspace = true
frame-benchmarking = { optional = true, workspace = true }
cumulus-primitives-storage-weight-reclaim = { workspace = true, default-features = false}

[dev-dependencies]
sp-core = { features = ["std"], default-features = true, path = "../../primitives/core" }
Expand All @@ -36,6 +37,7 @@ std = [
"serde",
"sp-core/std",
"sp-runtime/std",
"cumulus-primitives-storage-weight-reclaim/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
17 changes: 17 additions & 0 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 @@ -167,6 +168,22 @@ pub mod pallet {
type WeightInfo: WeightInfo;
}

#[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;

let proof_size_after: u64 = get_proof_size().unwrap_or(0);

let proof_size_diff = proof_size_after.saturating_sub(proof_size_before);

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

#[pallet::event]
#[pallet::generate_deposit(pub(crate) fn deposit_event)]
pub enum Event<T: Config> {
Expand Down

0 comments on commit b056710

Please sign in to comment.