Skip to content

Pallet parameters account for all parameters read weight#8

Merged
TarekkMA merged 6 commits intomoonbeam-polkadot-v1.11.0from
tarekkma/pallet-parameters-account-weight
Aug 6, 2024
Merged

Pallet parameters account for all parameters read weight#8
TarekkMA merged 6 commits intomoonbeam-polkadot-v1.11.0from
tarekkma/pallet-parameters-account-weight

Conversation

@TarekkMA
Copy link
Copy Markdown

@TarekkMA TarekkMA commented Aug 2, 2024

Account for all parameters read weight on every block, and whitelist the parameters storage so the weight is not double counted.

@TarekkMA TarekkMA changed the title Tarekkma/pallet parameters account weight Pallet parameters account for all raed weight Aug 2, 2024
@TarekkMA TarekkMA changed the title Pallet parameters account for all raed weight Pallet parameters account for all parameters read weight Aug 2, 2024
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
let items = Parameters::<T>::iter().count() as u64;
Copy link
Copy Markdown

@RomarQ RomarQ Aug 2, 2024

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 from T::RuntimeParameters::default(), because the storage will be empty in the benchmarks.

impl #scrate::__private::Get<#value_types> for #key_names {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see any insert for the initial values

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)

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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still do not agree with the need for a on_initialize hook here. Also Parameters::<T>::iter() will be empty until set_parameter is called.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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.
To mitigate potential issues, we should assume that all parameters stored in each block will be read.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameters::<T>::iter() initially will be empty, but as we add more and more parameters it will report all the stored ones

Co-authored-by: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com>
@RomarQ
Copy link
Copy Markdown

RomarQ commented Aug 5, 2024

The only thing missing is the storage whitelist

@TarekkMA TarekkMA merged commit c086b2d into moonbeam-polkadot-v1.11.0 Aug 6, 2024
librelois added a commit that referenced this pull request Aug 6, 2024
gonzamontiel pushed a commit that referenced this pull request Aug 14, 2024
gonzamontiel pushed a commit that referenced this pull request Aug 16, 2024
gonzamontiel pushed a commit that referenced this pull request Sep 17, 2024
gonzamontiel pushed a commit that referenced this pull request Sep 20, 2024
TarekkMA pushed a commit that referenced this pull request Oct 21, 2024
TarekkMA pushed a commit that referenced this pull request Oct 21, 2024
manuelmauro pushed a commit that referenced this pull request Feb 6, 2025
manuelmauro pushed a commit that referenced this pull request Mar 5, 2025
manuelmauro pushed a commit that referenced this pull request Mar 31, 2025
manuelmauro pushed a commit that referenced this pull request Apr 15, 2025
RomarQ pushed a commit that referenced this pull request May 14, 2025
TarekkMA pushed a commit that referenced this pull request Jul 18, 2025
TarekkMA pushed a commit that referenced this pull request Aug 21, 2025
TarekkMA pushed a commit that referenced this pull request Aug 22, 2025
RomarQ pushed a commit that referenced this pull request Aug 29, 2025
manuelmauro added a commit that referenced this pull request Oct 6, 2025
RomarQ pushed a commit that referenced this pull request Nov 18, 2025
RomarQ pushed a commit that referenced this pull request Nov 18, 2025
arturgontijo pushed a commit that referenced this pull request Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants