Add benchmarks for Xcmp QueueConfigData setters (#982)

* add benchmarks for xcmp queue config data setters

* add new benchmarks

* cargo fmt

* added newline

* Additional weights for dmp queue for westmint

* include new weights

* Adding WeightInfo trait and friends

* WeightInfo should be on xcmp rather than dmp pallet

* cargo fmt

* update scripts

* mock weightinfo

* cargo fmt

* canvas kusama is substrate weight

* weights from bm2

* expanding to other similar config functions

* updated weights from bm2

* Revert "updated weights from bm2"

This reverts commit b1702780982c278b44f572c2089b1d7ddc564d76.

* Consolidation to one benchmark

* reran weights

* Update pallets/xcmp-queue/src/lib.rs

Co-authored-by: Ignacio Palacios <ignacio.palacios.santos@gmail.com>

* integrating review feedback

* rerun weights

* Add DispatchClass::Operational

Co-authored-by: Squirrel <gilescope@gmail.com>
Co-authored-by: Ignacio Palacios <ignacio.palacios.santos@gmail.com>
This commit is contained in:
Doordashcon
2022-03-07 12:47:24 +01:00
committed by GitHub
parent ca379cf7c8
commit 8d96b8673f
23 changed files with 305 additions and 15 deletions
+9
View File
@@ -23,6 +23,9 @@ xcm-executor = { git = "https://github.com/paritytech/polkadot", default-feature
# Cumulus
cumulus-primitives-core = { path = "../../primitives/core", default-features = false }
# Optional import for benchmarking
frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "master" }
[dev-dependencies]
# Substrate
@@ -50,3 +53,9 @@ std = [
"xcm-executor/std",
"xcm/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
@@ -0,0 +1,28 @@
// Copyright (C) 2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Benchmarking setup for cumulus-pallet-xcmp-queue
use crate::*;
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite};
use frame_system::RawOrigin;
benchmarks! {
set_config_with_u32 {}: update_resume_threshold(RawOrigin::Root, 100)
set_config_with_weight {}: update_weight_restrict_decay(RawOrigin::Root, 3_000_000 as Weight)
}
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
+21 -13
View File
@@ -33,6 +33,11 @@ mod mock;
#[cfg(test)]
mod tests;
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod weights;
pub use weights::WeightInfo;
use codec::{Decode, DecodeLimit, Encode};
use cumulus_primitives_core::{
relay_chain::BlockNumber as RelayBlockNumber, ChannelStatus, GetChannelInfo, MessageSendError,
@@ -93,6 +98,9 @@ pub mod pallet {
/// The conversion function used to attempt to convert an XCM `MultiLocation` origin to a
/// superuser origin.
type ControllerOriginConverter: ConvertOrigin<Self::Origin>;
/// The weight information of this pallet.
type WeightInfo: WeightInfo;
}
#[pallet::hooks]
@@ -122,7 +130,7 @@ pub mod pallet {
///
/// Events:
/// - `OverweightServiced`: On success.
#[pallet::weight(weight_limit.saturating_add(1_000_000))]
#[pallet::weight((weight_limit.saturating_add(1_000_000), DispatchClass::Operational,))]
pub fn service_overweight(
origin: OriginFor<T>,
index: OverweightIndex,
@@ -147,7 +155,7 @@ pub mod pallet {
/// Suspends all XCM executions for the XCMP queue, regardless of the sender's origin.
///
/// - `origin`: Must pass `ControllerOrigin`.
#[pallet::weight(T::DbWeight::get().writes(1))]
#[pallet::weight((T::DbWeight::get().writes(1), DispatchClass::Operational,))]
pub fn suspend_xcm_execution(origin: OriginFor<T>) -> DispatchResult {
T::ControllerOrigin::ensure_origin(origin)?;
@@ -161,7 +169,7 @@ pub mod pallet {
/// Note that this function doesn't change the status of the in/out bound channels.
///
/// - `origin`: Must pass `ControllerOrigin`.
#[pallet::weight(T::DbWeight::get().writes(1))]
#[pallet::weight((T::DbWeight::get().writes(1), DispatchClass::Operational,))]
pub fn resume_xcm_execution(origin: OriginFor<T>) -> DispatchResult {
T::ControllerOrigin::ensure_origin(origin)?;
@@ -175,7 +183,7 @@ pub mod pallet {
///
/// - `origin`: Must pass `Root`.
/// - `new`: Desired value for `QueueConfigData.suspend_value`
#[pallet::weight(10_000_000 as Weight + T::DbWeight::get().reads_writes(1, 1))]
#[pallet::weight((T::WeightInfo::set_config_with_u32(), DispatchClass::Operational,))]
pub fn update_suspend_threshold(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
QueueConfig::<T>::mutate(|data| data.suspend_threshold = new);
@@ -188,7 +196,7 @@ pub mod pallet {
///
/// - `origin`: Must pass `Root`.
/// - `new`: Desired value for `QueueConfigData.drop_threshold`
#[pallet::weight(10_000_000 as Weight + T::DbWeight::get().reads_writes(1, 1))]
#[pallet::weight((T::WeightInfo::set_config_with_u32(),DispatchClass::Operational,))]
pub fn update_drop_threshold(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
QueueConfig::<T>::mutate(|data| data.drop_threshold = new);
@@ -200,8 +208,8 @@ pub mod pallet {
/// message sending may recommence after it has been suspended.
///
/// - `origin`: Must pass `Root`.
/// - `new`: Desired value for `QueueConfigData.resume_threshold`
#[pallet::weight(10_000_000 as Weight + T::DbWeight::get().reads_writes(1, 1))]
/// - `new`: Desired value for `QueueConfigData.resume_threshold`
#[pallet::weight((T::WeightInfo::set_config_with_u32(), DispatchClass::Operational,))]
pub fn update_resume_threshold(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
QueueConfig::<T>::mutate(|data| data.resume_threshold = new);
@@ -212,8 +220,8 @@ pub mod pallet {
/// Overwrites the amount of remaining weight under which we stop processing messages.
///
/// - `origin`: Must pass `Root`.
/// - `new`: Desired value for `QueueConfigData.threshold_weight`
#[pallet::weight(10_000_000 as Weight + T::DbWeight::get().reads_writes(1, 1))]
/// - `new`: Desired value for `QueueConfigData.threshold_weight`
#[pallet::weight((T::WeightInfo::set_config_with_weight(), DispatchClass::Operational,))]
pub fn update_threshold_weight(origin: OriginFor<T>, new: Weight) -> DispatchResult {
ensure_root(origin)?;
QueueConfig::<T>::mutate(|data| data.threshold_weight = new);
@@ -225,8 +233,8 @@ pub mod pallet {
/// A lower number results in a faster progression. A value of 1 makes the entire weight available initially.
///
/// - `origin`: Must pass `Root`.
/// - `new`: Desired value for `QueueConfigData.weight_restrict_decay`.
#[pallet::weight(10_000_000 as Weight + T::DbWeight::get().reads_writes(1, 1))]
/// - `new`: Desired value for `QueueConfigData.weight_restrict_decay`.
#[pallet::weight((T::WeightInfo::set_config_with_weight(), DispatchClass::Operational,))]
pub fn update_weight_restrict_decay(origin: OriginFor<T>, new: Weight) -> DispatchResult {
ensure_root(origin)?;
QueueConfig::<T>::mutate(|data| data.weight_restrict_decay = new);
@@ -238,8 +246,8 @@ pub mod pallet {
/// Messages above this weight go into the overweight queue and may only be serviced explicitly.
///
/// - `origin`: Must pass `Root`.
/// - `new`: Desired value for `QueueConfigData.xcmp_max_individual_weight`.
#[pallet::weight(10_000_000 as Weight + T::DbWeight::get().reads_writes(1, 1))]
/// - `new`: Desired value for `QueueConfigData.xcmp_max_individual_weight`.
#[pallet::weight((T::WeightInfo::set_config_with_weight(), DispatchClass::Operational,))]
pub fn update_xcmp_max_individual_weight(
origin: OriginFor<T>,
new: Weight,
+1
View File
@@ -188,6 +188,7 @@ impl Config for Test {
type ExecuteOverweightOrigin = EnsureRoot<AccountId>;
type ControllerOrigin = EnsureRoot<AccountId>;
type ControllerOriginConverter = SystemParachainAsSuperuser<Origin>;
type WeightInfo = ();
}
pub fn new_test_ext() -> sp_io::TestExternalities {
+48
View File
@@ -0,0 +1,48 @@
#![allow(unused_parens)]
#![allow(unused_imports)]
use frame_support::{
traits::Get,
weights::{constants::RocksDbWeight, Weight},
};
use sp_std::marker::PhantomData;
// Implemented by autogenerated benchmarking code.
pub trait WeightInfo {
fn set_config_with_u32() -> Weight;
fn set_config_with_weight() -> Weight;
}
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: XcmpQueue QueueConfig (r:1 w:1)
fn set_config_with_u32() -> Weight {
(2_717_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: XcmpQueue QueueConfig (r:1 w:1)
fn set_config_with_weight() -> Weight {
(2_717_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
}
impl WeightInfo for () {
// Storage: XcmpQueue QueueConfig (r:1 w:1)
fn set_config_with_u32() -> Weight {
(2_717_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: XcmpQueue QueueConfig (r:1 w:1)
fn set_config_with_weight() -> Weight {
(2_717_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
}