mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +00:00
Benchmarking: Add pov_mode to V2 syntax (#3616)
Changes: - Port the `pov_mode` attribute from the V1 syntax to V2 - Update `pallet-whitelist` and `frame-benchmarking-pallet-pov` Follow up: also allow this attribute on top-level benchmark modules. --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: command-bot <>
This commit is contained in:
committed by
GitHub
parent
430ad2f561
commit
abd3f0c49a
@@ -20,58 +20,57 @@
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use super::*;
|
||||
use frame_benchmarking::v1::{benchmarks, BenchmarkError};
|
||||
use frame_support::{ensure, traits::EnsureOrigin};
|
||||
use frame_benchmarking::v2::*;
|
||||
use frame_support::traits::EnsureOrigin;
|
||||
|
||||
#[cfg(test)]
|
||||
use crate::Pallet as Whitelist;
|
||||
|
||||
benchmarks! {
|
||||
whitelist_call {
|
||||
#[benchmarks]
|
||||
mod benchmarks {
|
||||
use super::*;
|
||||
|
||||
#[benchmark]
|
||||
fn whitelist_call() -> Result<(), BenchmarkError> {
|
||||
let origin =
|
||||
T::WhitelistOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let call_hash = Default::default();
|
||||
}: _<T::RuntimeOrigin>(origin, call_hash)
|
||||
verify {
|
||||
ensure!(
|
||||
WhitelistedCall::<T>::contains_key(call_hash),
|
||||
"call not whitelisted"
|
||||
);
|
||||
ensure!(
|
||||
T::Preimages::is_requested(&call_hash),
|
||||
"preimage not requested"
|
||||
);
|
||||
|
||||
#[extrinsic_call]
|
||||
_(origin as T::RuntimeOrigin, call_hash);
|
||||
|
||||
ensure!(WhitelistedCall::<T>::contains_key(call_hash), "call not whitelisted");
|
||||
ensure!(T::Preimages::is_requested(&call_hash), "preimage not requested");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
remove_whitelisted_call {
|
||||
#[benchmark]
|
||||
fn remove_whitelisted_call() -> Result<(), BenchmarkError> {
|
||||
let origin =
|
||||
T::WhitelistOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let call_hash = Default::default();
|
||||
Pallet::<T>::whitelist_call(origin.clone(), call_hash)
|
||||
.expect("whitelisting call must be successful");
|
||||
}: _<T::RuntimeOrigin>(origin, call_hash)
|
||||
verify {
|
||||
ensure!(
|
||||
!WhitelistedCall::<T>::contains_key(call_hash),
|
||||
"whitelist not removed"
|
||||
);
|
||||
ensure!(
|
||||
!T::Preimages::is_requested(&call_hash),
|
||||
"preimage still requested"
|
||||
);
|
||||
|
||||
#[extrinsic_call]
|
||||
_(origin as T::RuntimeOrigin, call_hash);
|
||||
|
||||
ensure!(!WhitelistedCall::<T>::contains_key(call_hash), "whitelist not removed");
|
||||
ensure!(!T::Preimages::is_requested(&call_hash), "preimage still requested");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// We benchmark with the maximum possible size for a call.
|
||||
// If the resulting weight is too big, maybe it worth having a weight which depends
|
||||
// on the size of the call, with a new witness in parameter.
|
||||
#[pov_mode = MaxEncodedLen {
|
||||
#[benchmark(pov_mode = MaxEncodedLen {
|
||||
// Use measured PoV size for the Preimages since we pass in a length witness.
|
||||
Preimage::PreimageFor: Measured
|
||||
}]
|
||||
dispatch_whitelisted_call {
|
||||
// NOTE: we remove `10` because we need some bytes to encode the variants and vec length
|
||||
let n in 1 .. T::Preimages::MAX_LENGTH as u32 - 10;
|
||||
|
||||
})]
|
||||
// NOTE: we remove `10` because we need some bytes to encode the variants and vec length
|
||||
fn dispatch_whitelisted_call(
|
||||
n: Linear<1, { T::Preimages::MAX_LENGTH as u32 - 10 }>,
|
||||
) -> Result<(), BenchmarkError> {
|
||||
let origin = T::DispatchWhitelistedOrigin::try_successful_origin()
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
let remark = sp_std::vec![1u8; n as usize];
|
||||
@@ -86,21 +85,16 @@ benchmarks! {
|
||||
|
||||
T::Preimages::note(encoded_call.into()).unwrap();
|
||||
|
||||
}: _<T::RuntimeOrigin>(origin, call_hash, call_encoded_len, call_weight)
|
||||
verify {
|
||||
ensure!(
|
||||
!WhitelistedCall::<T>::contains_key(call_hash),
|
||||
"whitelist not removed"
|
||||
);
|
||||
ensure!(
|
||||
!T::Preimages::is_requested(&call_hash),
|
||||
"preimage still requested"
|
||||
);
|
||||
#[extrinsic_call]
|
||||
_(origin as T::RuntimeOrigin, call_hash, call_encoded_len, call_weight);
|
||||
|
||||
ensure!(!WhitelistedCall::<T>::contains_key(call_hash), "whitelist not removed");
|
||||
ensure!(!T::Preimages::is_requested(&call_hash), "preimage still requested");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
dispatch_whitelisted_call_with_preimage {
|
||||
let n in 1 .. 10_000;
|
||||
|
||||
#[benchmark]
|
||||
fn dispatch_whitelisted_call_with_preimage(n: Linear<1, 10_000>) -> Result<(), BenchmarkError> {
|
||||
let origin = T::DispatchWhitelistedOrigin::try_successful_origin()
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
let remark = sp_std::vec![1u8; n as usize];
|
||||
@@ -110,16 +104,13 @@ benchmarks! {
|
||||
|
||||
Pallet::<T>::whitelist_call(origin.clone(), call_hash)
|
||||
.expect("whitelisting call must be successful");
|
||||
}: _<T::RuntimeOrigin>(origin, Box::new(call))
|
||||
verify {
|
||||
ensure!(
|
||||
!WhitelistedCall::<T>::contains_key(call_hash),
|
||||
"whitelist not removed"
|
||||
);
|
||||
ensure!(
|
||||
!T::Preimages::is_requested(&call_hash),
|
||||
"preimage still requested"
|
||||
);
|
||||
|
||||
#[extrinsic_call]
|
||||
_(origin as T::RuntimeOrigin, Box::new(call));
|
||||
|
||||
ensure!(!WhitelistedCall::<T>::contains_key(call_hash), "whitelist not removed");
|
||||
ensure!(!T::Preimages::is_requested(&call_hash), "preimage still requested");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(Whitelist, crate::mock::new_test_ext(), crate::mock::Test);
|
||||
|
||||
Reference in New Issue
Block a user