-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pallet parameters account for all parameters read weight #8
Changes from 5 commits
5861a10
60d3b3a
5276bf9
34af46a
f9559c8
3c15d2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)] | ||
|
@@ -167,6 +168,23 @@ 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still do not agree with the need for a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not all parameter usage is captured by our benchmarks. For instance, some parameters may be read within xcm or in other unaccounted areas. As a result, we can't rely solely on benchmark coverage to determine parameter impact. This approach helps us avoid hitting the proof size limit and prevents our chain from stalling, which would otherwise require recovery through relay chain governance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
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)) | ||
TarekkMA marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
#[pallet::event] | ||
#[pallet::generate_deposit(pub(crate) fn deposit_event)] | ||
pub enum Event<T: Config> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the
support/procedural/src/dynamic_params.rs
in polkadot-sdk, I do not see any storage being set for the initial values (it fallbacks to the defaults when storage is not present). Instead we should get the length fromT::RuntimeParameters::default()
, because the storage will be empty in the benchmarks.polkadot-sdk/substrate/frame/support/procedural/src/dynamic_params.rs
Line 345 in ad86209
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to insert initial values in production, only in benchmark setup (for the on_initialize benchmark scenario that still need to be added in this PR)