Skip to content
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

Feat request: Check runtime weights in CI for excess #1781

Open
wischli opened this issue Mar 28, 2024 · 1 comment
Open

Feat request: Check runtime weights in CI for excess #1781

wischli opened this issue Mar 28, 2024 · 1 comment
Labels
I12-ci Issue related to CI P2-nice-to-have Issue is worth doing.

Comments

@wischli
Copy link
Contributor

wischli commented Mar 28, 2024

Description

A recent incident has shown that we need to ensure our generated weights don't lead to excess of the maximum block weight or PoV size. Therefore, we need a CI job which checks that for at least Altair and Centrifuge runtime for every release. It can be coupled with the WASM build trigger as both have the same frequency.

The script needs to through all files inside the weights directory of a runtime, calculate the call weights based on the runtimes parameters (e.g. MaxKeys) and compare it with the maximum block weight and maximum pov size.

Research/based on

  • function update_collection weight having 175% PoV size for MaxKeys = 1000 and MaxFeeders = 10.

How will this affect the code base

  • Improve security

What are foreseen obstacles or hurdles to overcome?

  • Mapping the right parameters from the runtime lib.rs to the generic n, m etc. parameters inside the weight files. The correct parameters can be determined by looking into the corresponding pallet's lib.rs, so we might need manual cases for parametrized calls which then requires maintenance for breaking changes (i.e. renaming of parameters)
// pallets/oracle-collection/src/lib.rs
#[pallet::weight(T::WeightInfo::update_collection(
	T::MaxFeedersPerKey::get(),
	T::MaxCollectionSize::get(),
))]
#[pallet::call_index(2)]
pub fn update_collection(...)

// runtime/centrifuge/src/weights/pallet_oracle_collection.rs
fn update_collection(n: u32, m: u32, ) -> Weight

// runtime/centrifuge/src/lib.rs
parameter_types! {
        // snip
	pub const MaxActiveLoansPerPool: u32 = 1000;
	pub const MaxFeedersPerKey: u32 = 10;
}
impl pallet_oracle_collection::Config for Runtime {
	// snip
	type MaxCollectionSize = MaxActiveLoansPerPool;
	type MaxFeedersPerKey = MaxFeedersPerKey;
}

Whoever tackles this issue, needs to check whether such a tool already exists in the Polkadot Ecosystem as it is agnostic to Centrifuge and needed by every Substrate chain.

@wischli wischli added P2-nice-to-have Issue is worth doing. I12-ci Issue related to CI labels Mar 28, 2024
@lemunozm
Copy link
Contributor

lemunozm commented Apr 1, 2024

The correct parameters can be determined by looking into the corresponding pallet's lib.rs, so we might need manual cases for parametrized calls which then requires maintenance for breaking changes

I think we do not need it. We can get the weight from the DispatchInfo of the extrinsic: extrinsic.get_dispatch_info().weight.

What I think we need is to call all extrinsics manually. But maybe we can create something similar to what currently works for benchmarking. Some kind of macro in the runtime that calls all extrinsics under the hood if they are registered for benchmarks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I12-ci Issue related to CI P2-nice-to-have Issue is worth doing.
Projects
None yet
Development

No branches or pull requests

2 participants