difftreelog
feat(configuration) benchmarks
in: master
15 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5846,6 +5846,7 @@
version = "0.1.2"
dependencies = [
"fp-evm",
+ "frame-benchmarking",
"frame-support",
"frame-system",
"parity-scale-codec 3.2.1",
Makefilediffbeforeafterboth--- a/Makefile
+++ b/Makefile
@@ -89,6 +89,10 @@
bench-evm-migration:
make _bench PALLET=evm-migration
+.PHONY: bench-configuration
+bench-configuration:
+ make _bench PALLET=configuration
+
.PHONY: bench-common
bench-common:
make _bench PALLET=common
@@ -143,4 +147,4 @@
.PHONY: bench
# Disabled: bench-scheduler, bench-rmrk-core, bench-rmrk-equip
-bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-foreign-assets bench-collator-selection bench-identity
+bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets bench-collator-selection bench-identity
pallets/collator-selection/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/benchmarking.rs
+++ b/pallets/collator-selection/src/benchmarking.rs
@@ -52,9 +52,6 @@
};
use sp_std::prelude::*;
-/*pub type BalanceOf<T> =
-<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;*/
-
const SEED: u32 = 0;
// TODO: remove if this is given in substrate commit.
@@ -116,14 +113,24 @@
validators.into_iter().map(|(who, _)| who).collect()
}
+fn register_invulnerables<T: Config + configuration::Config>(count: u32) {
+ let candidates = (0..count)
+ .map(|c| account("candidate", c, SEED))
+ .collect::<Vec<_>>();
+
+ for who in candidates {
+ <CollatorSelection<T>>::add_invulnerable(T::UpdateOrigin::successful_origin(), who).unwrap();
+ }
+}
+
fn register_candidates<T: Config + configuration::Config>(count: u32) {
let candidates = (0..count)
.map(|c| account("candidate", c, SEED))
.collect::<Vec<_>>();
- assert!(
+ /*assert!(
<LicenseBond<T>>::get() > 0u32.into(),
"Bond cannot be zero!"
- );
+ );*/
for who in candidates {
T::Currency::make_free_balance_be(&who, <LicenseBond<T>>::get() * 2u32.into());
@@ -132,16 +139,45 @@
}
}
+fn get_licenses<T: Config + configuration::Config>(count: u32) {
+ let candidates = (0..count)
+ .map(|c| account("candidate", c, SEED))
+ .collect::<Vec<_>>();
+ /*assert!(
+ <LicenseBond<T>>::get() > 0u32.into(),
+ "Bond cannot be zero!"
+ );*/
+
+ for who in candidates {
+ T::Currency::make_free_balance_be(&who, <LicenseBond<T>>::get() * 2u32.into());
+ <CollatorSelection<T>>::get_license(RawOrigin::Signed(who.clone()).into()).unwrap();
+ }
+}
+
benchmarks! {
where_clause { where T: pallet_authorship::Config + session::Config + configuration::Config }
add_invulnerable {
- let b in 1 .. T::MaxCollators::get();
- let new_invulnerable = register_validators::<T>(b)[0].clone();
- let origin = T::UpdateOrigin::successful_origin();
+ let b in 1 .. T::MaxCollators::get() - 3;
+ register_validators::<T>(b);
+ register_invulnerables::<T>(b);
+
+ // log::info!("{} {}", <Invulnerables<T>>::get().len(), b);
+
+ let new_invulnerable: T::AccountId = whitelisted_caller();
+ let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();
+ T::Currency::make_free_balance_be(&new_invulnerable, bond.clone());
+
+ <session::Pallet<T>>::set_keys(
+ RawOrigin::Signed(new_invulnerable.clone()).into(),
+ keys::<T>(b + 1),
+ Vec::new()
+ ).unwrap();
+
+ let root_origin = T::UpdateOrigin::successful_origin();
}: {
assert_ok!(
- <CollatorSelection<T>>::add_invulnerable(origin, new_invulnerable.clone())
+ <CollatorSelection<T>>::add_invulnerable(root_origin, new_invulnerable.clone())
);
}
verify {
@@ -150,52 +186,28 @@
remove_invulnerable {
let b in 1 .. T::MaxCollators::get();
- let new_invulnerable = register_validators::<T>(b)[0].clone();
- let origin = T::UpdateOrigin::successful_origin();
- assert_ok!(
- <CollatorSelection<T>>::add_invulnerable(origin.clone(), new_invulnerable.clone())
- );
- }: {
- assert_ok!(
- <CollatorSelection<T>>::remove_invulnerable(origin, new_invulnerable.clone())
- );
- }
- verify {
- assert_last_event::<T>(Event::InvulnerableRemoved{invulnerable: new_invulnerable}.into());
- }
+ register_validators::<T>(b);
+ register_invulnerables::<T>(b);
- /*set_desired_collators {
- let max: u32 = 999;
- let origin = T::UpdateOrigin::successful_origin();
+ let root_origin = T::UpdateOrigin::successful_origin();
+ let leaving = <Invulnerables<T>>::get().last().unwrap().clone();
+ whitelist!(leaving);
}: {
assert_ok!(
- <CollatorSelection<T>>::set_desired_collators(origin, max.clone())
+ <CollatorSelection<T>>::remove_invulnerable(root_origin, leaving.clone())
);
}
verify {
- assert_last_event::<T>(Event::NewDesiredCollators{desired_collators: max}.into());
+ assert_last_event::<T>(Event::InvulnerableRemoved{invulnerable: leaving}.into());
}
- set_license_bond {
- let bond_amount: BalanceOf<T> = T::Currency::minimum_balance() * 10u32.into();
- let origin = T::UpdateOrigin::successful_origin();
- }: {
- assert_ok!(
- <CollatorSelection<T>>::set_license_bond(origin, bond_amount.clone())
- );
- }
- verify {
- assert_last_event::<T>(Event::NewLicenseBond{bond_amount}.into());
- }*/
-
get_license {
let c in 1 .. T::MaxCollators::get();
<LicenseBond<T>>::put(T::Currency::minimum_balance());
- <DesiredCollators<T>>::put(c + 1);
register_validators::<T>(c);
- register_candidates::<T>(c);
+ get_licenses::<T>(c);
let caller: T::AccountId = whitelisted_caller();
let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();
@@ -215,10 +227,10 @@
// worst case is when we have all the max-candidate slots filled except one, and we fill that
// one.
onboard {
- let c in 1 .. T::MaxCollators::get();
+ let c in 1 .. 5;
<LicenseBond<T>>::put(T::Currency::minimum_balance());
- <DesiredCollators<T>>::put(c + 1);
+ <DesiredCollators<T>>::put(c + 2);
register_validators::<T>(c);
register_candidates::<T>(c);
@@ -247,7 +259,7 @@
offboard {
let c in 1 .. T::MaxCollators::get();
<LicenseBond<T>>::put(T::Currency::minimum_balance());
- <DesiredCollators<T>>::put(c);
+ <DesiredCollators<T>>::put(c + 2);
register_validators::<T>(c);
register_candidates::<T>(c);
pallets/collator-selection/src/lib.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/lib.rs
+++ b/pallets/collator-selection/src/lib.rs
@@ -285,7 +285,7 @@
impl<T: Config> Pallet<T> {
/// Add a collator to the list of invulnerable (fixed) collators.
#[pallet::call_index(0)]
- #[pallet::weight(T::WeightInfo::add_invulnerable(T::MaxCollators::get()))]
+ #[pallet::weight(<T as Config>::WeightInfo::add_invulnerable(T::MaxCollators::get()))]
pub fn add_invulnerable(
origin: OriginFor<T>,
new: T::AccountId,
@@ -315,7 +315,7 @@
/// Remove a collator from the list of invulnerable (fixed) collators.
#[pallet::call_index(1)]
- #[pallet::weight(T::WeightInfo::remove_invulnerable(T::MaxCollators::get()))]
+ #[pallet::weight(<T as Config>::WeightInfo::remove_invulnerable(T::MaxCollators::get()))]
pub fn remove_invulnerable(
origin: OriginFor<T>,
who: T::AccountId,
@@ -344,7 +344,7 @@
///
/// This call is not available to `Invulnerable` collators.
#[pallet::call_index(2)]
- #[pallet::weight(T::WeightInfo::get_license(T::MaxCollators::get()))]
+ #[pallet::weight(<T as Config>::WeightInfo::get_license(T::MaxCollators::get()))]
pub fn get_license(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
// register_as_candidate
let who = ensure_signed(origin)?;
@@ -377,7 +377,7 @@
///
/// This call is not available to `Invulnerable` collators.
#[pallet::call_index(3)]
- #[pallet::weight(T::WeightInfo::onboard(T::MaxCollators::get()))]
+ #[pallet::weight(<T as Config>::WeightInfo::onboard(T::MaxCollators::get()))]
pub fn onboard(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
// register_as_candidate
let who = ensure_signed(origin)?;
@@ -417,33 +417,36 @@
})?;
Self::deposit_event(Event::CandidateAdded { account_id: who });
- Ok(Some(T::WeightInfo::onboard(current_count as u32)).into())
+ Ok(Some(<T as Config>::WeightInfo::onboard(current_count as u32)).into())
}
/// Deregister `origin` as a collator candidate. Note that the collator can only leave on
/// session change. The license to `onboard` later at any other time will remain.
#[pallet::call_index(4)]
- #[pallet::weight(T::WeightInfo::offboard(T::MaxCollators::get()))]
+ #[pallet::weight(<T as Config>::WeightInfo::offboard(T::MaxCollators::get()))]
pub fn offboard(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
// leave_intent
let who = ensure_signed(origin)?;
let current_count = Self::try_remove_candidate(&who)?;
- Ok(Some(T::WeightInfo::offboard(current_count as u32)).into())
+ Ok(Some(<T as Config>::WeightInfo::offboard(current_count as u32)).into())
}
/// Forfeit `origin`'s own license. The `LicenseBond` will be unreserved immediately.
///
/// This call is not available to `Invulnerable` collators.
#[pallet::call_index(5)]
- #[pallet::weight(T::WeightInfo::release_license(T::MaxCollators::get()))]
+ #[pallet::weight(<T as Config>::WeightInfo::release_license(T::MaxCollators::get()))]
pub fn release_license(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
// leave_intent
let who = ensure_signed(origin)?;
let current_count = Self::try_remove_candidate_and_release_license(&who, false, true)?;
- Ok(Some(T::WeightInfo::release_license(current_count as u32)).into())
+ Ok(Some(<T as Config>::WeightInfo::release_license(
+ current_count as u32,
+ ))
+ .into())
}
/// Force deregister `origin` as a collator candidate as a governing authority, and revoke its license.
@@ -452,7 +455,7 @@
///
/// This call is, of course, not applicable to `Invulnerable` collators.
#[pallet::call_index(6)]
- #[pallet::weight(T::WeightInfo::force_release_license(T::MaxCollators::get()))]
+ #[pallet::weight(<T as Config>::WeightInfo::force_release_license(T::MaxCollators::get()))]
pub fn force_release_license(
origin: OriginFor<T>,
who: T::AccountId,
@@ -462,7 +465,10 @@
let current_count = Self::try_remove_candidate_and_release_license(&who, false, true)?;
- Ok(Some(T::WeightInfo::force_release_license(current_count as u32)).into())
+ Ok(Some(<T as Config>::WeightInfo::force_release_license(
+ current_count as u32,
+ ))
+ .into())
}
}
@@ -599,7 +605,7 @@
<LastAuthoredBlock<T>>::insert(author, frame_system::Pallet::<T>::block_number());
frame_system::Pallet::<T>::register_extra_weight_unchecked(
- T::WeightInfo::note_author(),
+ <T as Config>::WeightInfo::note_author(),
DispatchClass::Mandatory,
);
}
@@ -625,7 +631,10 @@
let result = Self::assemble_collators(active_candidates);
frame_system::Pallet::<T>::register_extra_weight_unchecked(
- T::WeightInfo::new_session(candidates_len_before as u32, removed as u32),
+ <T as Config>::WeightInfo::new_session(
+ candidates_len_before as u32,
+ removed as u32,
+ ),
DispatchClass::Mandatory,
);
Some(result)
pallets/collator-selection/src/mock.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/mock.rs
+++ b/pallets/collator-selection/src/mock.rs
@@ -225,6 +225,7 @@
type MaxXcmAllowedLocations = MaxXcmAllowedLocations;
type AppPromotionDailyRate = AppPromotionDailyRate;
type DayRelayBlocks = DayRelayBlocks;
+ type WeightInfo = ();
}
ord_parameter_types! {
pallets/configuration/Cargo.tomldiffbeforeafterboth--- a/pallets/configuration/Cargo.toml
+++ b/pallets/configuration/Cargo.toml
@@ -12,6 +12,7 @@
] }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
+frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
@@ -22,10 +23,12 @@
[features]
default = ["std"]
+runtime-benchmarks = ["frame-benchmarking"]
std = [
"parity-scale-codec/std",
"frame-support/std",
"frame-system/std",
+ "frame-benchmarking/std",
"sp-runtime/std",
"sp-std/std",
"sp-core/std",
pallets/configuration/src/benchmarking.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/configuration/src/benchmarking.rs
@@ -0,0 +1,100 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+//! Benchmarking setup for pallet-configuration
+
+use super::*;
+use frame_benchmarking::benchmarks;
+use frame_system::{EventRecord, RawOrigin};
+use frame_support::{assert_ok, BoundedVec, traits::Currency};
+use xcm::v1::MultiLocation;
+
+fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
+ let events = frame_system::Pallet::<T>::events();
+ let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();
+ // compare to the last event record
+ let EventRecord { event, .. } = &events[events.len() - 1];
+ assert_eq!(event, &system_event);
+}
+
+benchmarks! {
+ where_clause { where T: Config }
+
+ set_weight_to_fee_coefficient_override {
+ let coeff: u64 = 999;
+ }: {
+ assert_ok!(
+ <Pallet<T>>::set_weight_to_fee_coefficient_override(RawOrigin::Root.into(), Some(coeff))
+ );
+ }
+
+ set_min_gas_price_override {
+ let coeff: u64 = 999;
+ }: {
+ assert_ok!(
+ <Pallet<T>>::set_min_gas_price_override(RawOrigin::Root.into(), Some(coeff))
+ );
+ }
+
+ set_xcm_allowed_locations {
+ let locations: BoundedVec<MultiLocation, T::MaxXcmAllowedLocations> = Default::default();
+ }: {
+ assert_ok!(
+ <Pallet<T>>::set_xcm_allowed_locations(RawOrigin::Root.into(), Some(locations))
+ );
+ }
+
+ set_app_promotion_configuration_override {
+ let configuration: AppPromotionConfiguration<T::BlockNumber> = Default::default();
+ }: {
+ assert_ok!(
+ <Pallet<T>>::set_app_promotion_configuration_override(RawOrigin::Root.into(), configuration)
+ );
+ }
+
+ set_collator_selection_desired_collators {
+ let max: u32 = 999;
+ }: {
+ assert_ok!(
+ <Pallet<T>>::set_collator_selection_desired_collators(RawOrigin::Root.into(), Some(max.clone()))
+ );
+ }
+ verify {
+ assert_last_event::<T>(Event::NewDesiredCollators{desired_collators: Some(max)}.into());
+ }
+
+ set_collator_selection_license_bond {
+ let bond_cost: Option<BalanceOf<T>> = Some(T::Currency::minimum_balance() * 10u32.into());
+ }: {
+ assert_ok!(
+ <Pallet<T>>::set_collator_selection_license_bond(RawOrigin::Root.into(), bond_cost.clone())
+ );
+ }
+ verify {
+ assert_last_event::<T>(Event::NewCollatorLicenseBond{bond_cost}.into());
+ }
+
+ set_collator_selection_kick_threshold {
+ let threshold: Option<T::BlockNumber> = Some(900u32.into());
+ }: {
+ assert_ok!(
+ <Pallet<T>>::set_collator_selection_kick_threshold(RawOrigin::Root.into(), threshold.clone())
+ );
+ }
+ verify {
+ assert_last_event::<T>(Event::NewCollatorKickThreshold{length_in_blocks: threshold}.into());
+ }
+}
pallets/configuration/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use core::marker::PhantomData;2021use frame_support::{22 pallet,23 weights::{WeightToFeePolynomial, WeightToFeeCoefficients, WeightToFeeCoefficient, Weight},24 traits::Get,25};26use parity_scale_codec::{Decode, Encode, MaxEncodedLen};27use scale_info::TypeInfo;28use sp_arithmetic::{29 per_things::{Perbill, PerThing},30 traits::{BaseArithmetic, Unsigned},31};32use smallvec::smallvec;3334pub use pallet::*;35use sp_core::U256;3637#[cfg(feature = "runtime-benchmarks")]38mod benchmarking;39pub mod weights;4041#[pallet]42mod pallet {43 use super::*;44 use frame_support::{45 traits::{Get, ReservableCurrency, Currency},46 pallet_prelude::{StorageValue, ValueQuery, DispatchResult, IsType, OptionQuery},47 BoundedVec, log,48 };49 use frame_system::{pallet_prelude::OriginFor, ensure_root, Config as SystemConfig};50 use xcm::v1::MultiLocation;5152 pub use crate::weights::WeightInfo;53 pub type BalanceOf<T> =54 <<T as Config>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;5556 #[pallet::config]57 pub trait Config: frame_system::Config {58 /// Overarching event type.59 type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;6061 /// The currency mechanism.62 type Currency: ReservableCurrency<Self::AccountId>;6364 #[pallet::constant]65 type DefaultWeightToFeeCoefficient: Get<u64>;66 #[pallet::constant]67 type DefaultMinGasPrice: Get<u64>;6869 #[pallet::constant]70 type MaxXcmAllowedLocations: Get<u32>;71 #[pallet::constant]72 type AppPromotionDailyRate: Get<Perbill>;73 #[pallet::constant]74 type DayRelayBlocks: Get<Self::BlockNumber>;7576 #[pallet::constant]77 type DefaultCollatorSelectionMaxCollators: Get<u32>;78 #[pallet::constant]79 type DefaultCollatorSelectionLicenseBond: Get<BalanceOf<Self>>;80 #[pallet::constant]81 type DefaultCollatorSelectionKickThreshold: Get<Self::BlockNumber>;8283 /// The weight information of this pallet.84 type WeightInfo: WeightInfo;85 }8687 #[pallet::event]88 #[pallet::generate_deposit(pub(super) fn deposit_event)]89 pub enum Event<T: Config> {90 NewDesiredCollators {91 desired_collators: Option<u32>,92 },93 NewCollatorLicenseBond {94 bond_cost: Option<BalanceOf<T>>,95 },96 NewCollatorKickThreshold {97 length_in_blocks: Option<T::BlockNumber>,98 },99 }100101 #[pallet::error]102 pub enum Error<T> {103 InconsistentConfiguration,104 }105106 #[pallet::storage]107 pub type WeightToFeeCoefficientOverride<T: Config> = StorageValue<108 Value = u64,109 QueryKind = ValueQuery,110 OnEmpty = T::DefaultWeightToFeeCoefficient,111 >;112113 #[pallet::storage]114 pub type MinGasPriceOverride<T: Config> =115 StorageValue<Value = u64, QueryKind = ValueQuery, OnEmpty = T::DefaultMinGasPrice>;116117 #[pallet::storage]118 pub type XcmAllowedLocationsOverride<T: Config> = StorageValue<119 Value = BoundedVec<MultiLocation, T::MaxXcmAllowedLocations>,120 QueryKind = OptionQuery,121 >;122123 #[pallet::storage]124 pub type AppPromomotionConfigurationOverride<T: Config> =125 StorageValue<Value = AppPromotionConfiguration<T::BlockNumber>, QueryKind = ValueQuery>;126127 #[pallet::storage]128 pub type CollatorSelectionDesiredCollatorsOverride<T: Config> = StorageValue<129 Value = u32,130 QueryKind = ValueQuery,131 OnEmpty = T::DefaultCollatorSelectionMaxCollators,132 >;133134 #[pallet::storage]135 pub type CollatorSelectionLicenseBondOverride<T: Config> = StorageValue<136 Value = BalanceOf<T>,137 QueryKind = ValueQuery,138 OnEmpty = T::DefaultCollatorSelectionLicenseBond,139 >;140141 #[pallet::storage]142 pub type CollatorSelectionKickThresholdOverride<T: Config> = StorageValue<143 Value = T::BlockNumber,144 QueryKind = ValueQuery,145 OnEmpty = T::DefaultCollatorSelectionKickThreshold,146 >;147148 #[pallet::call]149 impl<T: Config> Pallet<T> {150 #[pallet::call_index(0)]151 #[pallet::weight(T::WeightInfo::set_weight_to_fee_coefficient_override())]152 pub fn set_weight_to_fee_coefficient_override(153 origin: OriginFor<T>,154 coeff: Option<u64>,155 ) -> DispatchResult {156 ensure_root(origin)?;157 if let Some(coeff) = coeff {158 <WeightToFeeCoefficientOverride<T>>::set(coeff);159 } else {160 <WeightToFeeCoefficientOverride<T>>::kill();161 }162 Ok(())163 }164165 #[pallet::call_index(1)]166 #[pallet::weight(T::WeightInfo::set_min_gas_price_override())]167 pub fn set_min_gas_price_override(168 origin: OriginFor<T>,169 coeff: Option<u64>,170 ) -> DispatchResult {171 ensure_root(origin)?;172 if let Some(coeff) = coeff {173 <MinGasPriceOverride<T>>::set(coeff);174 } else {175 <MinGasPriceOverride<T>>::kill();176 }177 Ok(())178 }179180 #[pallet::call_index(2)]181 #[pallet::weight(T::WeightInfo::set_xcm_allowed_locations())]182 pub fn set_xcm_allowed_locations(183 origin: OriginFor<T>,184 locations: Option<BoundedVec<MultiLocation, T::MaxXcmAllowedLocations>>,185 ) -> DispatchResult {186 ensure_root(origin)?;187 <XcmAllowedLocationsOverride<T>>::set(locations);188 Ok(())189 }190191 #[pallet::call_index(3)]192 #[pallet::weight(T::WeightInfo::set_app_promotion_configuration_override())]193 pub fn set_app_promotion_configuration_override(194 origin: OriginFor<T>,195 mut configuration: AppPromotionConfiguration<T::BlockNumber>,196 ) -> DispatchResult {197 ensure_root(origin)?;198 if configuration.interval_income.is_some() {199 return Err(<Error<T>>::InconsistentConfiguration.into());200 }201202 configuration.interval_income = configuration.recalculation_interval.map(|b| {203 Perbill::from_rational(b, T::DayRelayBlocks::get())204 * T::AppPromotionDailyRate::get()205 });206207 <AppPromomotionConfigurationOverride<T>>::set(configuration);208209 Ok(())210 }211212 #[pallet::call_index(4)]213 #[pallet::weight(T::WeightInfo::set_collator_selection_desired_collators())]214 pub fn set_collator_selection_desired_collators(215 origin: OriginFor<T>,216 max: Option<u32>,217 ) -> DispatchResult {218 ensure_root(origin)?;219 if let Some(max) = max {220 // we trust origin calls, this is just a for more accurate benchmarking221 if max > T::DefaultCollatorSelectionMaxCollators::get() {222 log::warn!("max > T::DefaultCollatorSelectionMaxCollators; you might need to run benchmarks again");223 }224 <CollatorSelectionDesiredCollatorsOverride<T>>::set(max);225 } else {226 <CollatorSelectionDesiredCollatorsOverride<T>>::kill();227 }228 Self::deposit_event(Event::NewDesiredCollators {229 desired_collators: max,230 });231 Ok(())232 }233234 #[pallet::call_index(5)]235 #[pallet::weight(T::WeightInfo::set_collator_selection_license_bond())]236 pub fn set_collator_selection_license_bond(237 origin: OriginFor<T>,238 amount: Option<BalanceOf<T>>,239 ) -> DispatchResult {240 ensure_root(origin)?;241 if let Some(amount) = amount {242 <CollatorSelectionLicenseBondOverride<T>>::set(amount);243 } else {244 <CollatorSelectionLicenseBondOverride<T>>::kill();245 }246 Self::deposit_event(Event::NewCollatorLicenseBond { bond_cost: amount });247 Ok(())248 }249250 #[pallet::call_index(6)]251 #[pallet::weight(T::WeightInfo::set_collator_selection_kick_threshold())]252 pub fn set_collator_selection_kick_threshold(253 origin: OriginFor<T>,254 threshold: Option<T::BlockNumber>,255 ) -> DispatchResult {256 ensure_root(origin)?;257 if let Some(threshold) = threshold {258 <CollatorSelectionKickThresholdOverride<T>>::set(threshold);259 } else {260 <CollatorSelectionKickThresholdOverride<T>>::kill();261 }262 Self::deposit_event(Event::NewCollatorKickThreshold {263 length_in_blocks: threshold,264 });265 Ok(())266 }267 }268269 #[pallet::pallet]270 #[pallet::generate_store(pub(super) trait Store)]271 pub struct Pallet<T>(_);272}273274pub struct WeightToFee<T, B>(PhantomData<(T, B)>);275276impl<T, B> WeightToFeePolynomial for WeightToFee<T, B>277where278 T: Config,279 B: BaseArithmetic + From<u32> + From<u64> + Copy + Unsigned,280{281 type Balance = B;282283 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {284 smallvec!(WeightToFeeCoefficient {285 coeff_integer: (<WeightToFeeCoefficientOverride<T>>::get() / Perbill::ACCURACY as u64)286 .into(),287 coeff_frac: Perbill::from_parts(288 (<WeightToFeeCoefficientOverride<T>>::get() % Perbill::ACCURACY as u64) as u32289 ),290 negative: false,291 degree: 1,292 })293 }294}295296pub struct FeeCalculator<T>(PhantomData<T>);297impl<T: Config> fp_evm::FeeCalculator for FeeCalculator<T> {298 fn min_gas_price() -> (U256, Weight) {299 (300 <MinGasPriceOverride<T>>::get().into(),301 T::DbWeight::get().reads(1),302 )303 }304}305306#[derive(Encode, Decode, Clone, Debug, Default, TypeInfo, MaxEncodedLen, PartialEq, PartialOrd)]307pub struct AppPromotionConfiguration<BlockNumber> {308 /// In relay blocks.309 pub recalculation_interval: Option<BlockNumber>,310 /// In parachain blocks.311 pub pending_interval: Option<BlockNumber>,312 /// Value for `RecalculationInterval` based on 0.05% per 24h.313 pub interval_income: Option<Perbill>,314 /// Maximum allowable number of stakers calculated per call of the `app-promotion::PayoutStakers` extrinsic.315 pub max_stakers_per_calculation: Option<u8>,316}pallets/configuration/src/weights.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/configuration/src/weights.rs
@@ -0,0 +1,123 @@
+// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs
+
+//! Autogenerated weights for pallet_configuration
+//!
+//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
+//! DATE: 2022-12-28, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`
+//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024
+
+// Executed Command:
+// target/release/unique-collator
+// benchmark
+// pallet
+// --pallet
+// pallet-configuration
+// --wasm-execution
+// compiled
+// --extrinsic
+// *
+// --template
+// .maintain/frame-weight-template.hbs
+// --steps=50
+// --repeat=80
+// --heap-pages=4096
+// --output=./pallets/configuration/src/weights.rs
+
+#![cfg_attr(rustfmt, rustfmt_skip)]
+#![allow(unused_parens)]
+#![allow(unused_imports)]
+#![allow(missing_docs)]
+#![allow(clippy::unnecessary_cast)]
+
+use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
+use sp_std::marker::PhantomData;
+
+/// Weight functions needed for pallet_configuration.
+pub trait WeightInfo {
+ fn set_weight_to_fee_coefficient_override() -> Weight;
+ fn set_min_gas_price_override() -> Weight;
+ fn set_xcm_allowed_locations() -> Weight;
+ fn set_app_promotion_configuration_override() -> Weight;
+ fn set_collator_selection_desired_collators() -> Weight;
+ fn set_collator_selection_license_bond() -> Weight;
+ fn set_collator_selection_kick_threshold() -> Weight;
+}
+
+/// Weights for pallet_configuration using the Substrate node and recommended hardware.
+pub struct SubstrateWeight<T>(PhantomData<T>);
+impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
+ // Storage: Configuration WeightToFeeCoefficientOverride (r:0 w:1)
+ fn set_weight_to_fee_coefficient_override() -> Weight {
+ Weight::from_ref_time(5_691_000 as u64)
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Configuration MinGasPriceOverride (r:0 w:1)
+ fn set_min_gas_price_override() -> Weight {
+ Weight::from_ref_time(5_521_000 as u64)
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Configuration XcmAllowedLocationsOverride (r:0 w:1)
+ fn set_xcm_allowed_locations() -> Weight {
+ Weight::from_ref_time(6_091_000 as u64)
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Configuration AppPromomotionConfigurationOverride (r:0 w:1)
+ fn set_app_promotion_configuration_override() -> Weight {
+ Weight::from_ref_time(6_241_000 as u64)
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Configuration CollatorSelectionDesiredCollatorsOverride (r:0 w:1)
+ fn set_collator_selection_desired_collators() -> Weight {
+ Weight::from_ref_time(25_298_000 as u64)
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Configuration CollatorSelectionLicenseBondOverride (r:0 w:1)
+ fn set_collator_selection_license_bond() -> Weight {
+ Weight::from_ref_time(18_675_000 as u64)
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+ // Storage: Configuration CollatorSelectionKickThresholdOverride (r:0 w:1)
+ fn set_collator_selection_kick_threshold() -> Weight {
+ Weight::from_ref_time(18_044_000 as u64)
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
+}
+
+// For backwards compatibility and tests
+impl WeightInfo for () {
+ // Storage: Configuration WeightToFeeCoefficientOverride (r:0 w:1)
+ fn set_weight_to_fee_coefficient_override() -> Weight {
+ Weight::from_ref_time(5_691_000 as u64)
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Configuration MinGasPriceOverride (r:0 w:1)
+ fn set_min_gas_price_override() -> Weight {
+ Weight::from_ref_time(5_521_000 as u64)
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Configuration XcmAllowedLocationsOverride (r:0 w:1)
+ fn set_xcm_allowed_locations() -> Weight {
+ Weight::from_ref_time(6_091_000 as u64)
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Configuration AppPromomotionConfigurationOverride (r:0 w:1)
+ fn set_app_promotion_configuration_override() -> Weight {
+ Weight::from_ref_time(6_241_000 as u64)
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Configuration CollatorSelectionDesiredCollatorsOverride (r:0 w:1)
+ fn set_collator_selection_desired_collators() -> Weight {
+ Weight::from_ref_time(25_298_000 as u64)
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Configuration CollatorSelectionLicenseBondOverride (r:0 w:1)
+ fn set_collator_selection_license_bond() -> Weight {
+ Weight::from_ref_time(18_675_000 as u64)
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+ // Storage: Configuration CollatorSelectionKickThresholdOverride (r:0 w:1)
+ fn set_collator_selection_kick_threshold() -> Weight {
+ Weight::from_ref_time(18_044_000 as u64)
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
+}
runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -121,6 +121,7 @@
type MaxXcmAllowedLocations = ConstU32<16>;
type AppPromotionDailyRate = AppPromotionDailyRate;
type DayRelayBlocks = DayRelayBlocks;
+ type WeightInfo = pallet_configuration::weights::SubstrateWeight<Self>;
}
impl pallet_maintenance::Config for Runtime {
runtime/common/construct_runtime/mod.rsdiffbeforeafterboth--- a/runtime/common/construct_runtime/mod.rs
+++ b/runtime/common/construct_runtime/mod.rs
@@ -32,17 +32,17 @@
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,
ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,
- Aura: pallet_aura::{Pallet, Config<T>} = 22,
- AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,
+ #[runtimes(opal)]
+ Authorship: pallet_authorship::{Pallet, Call, Storage} = 22,
#[runtimes(opal)]
- Authorship: pallet_authorship::{Pallet, Call, Storage} = 24,
+ CollatorSelection: pallet_collator_selection::{Pallet, Call, Storage, Event<T>, Config<T>} = 23,
#[runtimes(opal)]
- CollatorSelection: pallet_collator_selection::{Pallet, Call, Storage, Event<T>, Config<T>} = 25,
+ Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 24,
- #[runtimes(opal)]
- Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 26,
+ Aura: pallet_aura::{Pallet, Config<T>} = 25,
+ AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 26,
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,
runtime/common/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/runtime_apis.rs
+++ b/runtime/common/runtime_apis.rs
@@ -686,6 +686,7 @@
list_benchmark!(list, extra, pallet_unique, Unique);
list_benchmark!(list, extra, pallet_structure, Structure);
list_benchmark!(list, extra, pallet_inflation, Inflation);
+ list_benchmark!(list, extra, pallet_configuration, Configuration);
#[cfg(feature = "app-promotion")]
list_benchmark!(list, extra, pallet_app_promotion, AppPromotion);
@@ -755,6 +756,7 @@
add_benchmark!(params, batches, pallet_unique, Unique);
add_benchmark!(params, batches, pallet_structure, Structure);
add_benchmark!(params, batches, pallet_inflation, Inflation);
+ add_benchmark!(params, batches, pallet_configuration, Configuration);
#[cfg(feature = "app-promotion")]
add_benchmark!(params, batches, pallet_app_promotion, AppPromotion);
runtime/opal/Cargo.tomldiffbeforeafterboth--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -28,6 +28,7 @@
'pallet-evm-coder-substrate/runtime-benchmarks',
'pallet-balances/runtime-benchmarks',
'pallet-timestamp/runtime-benchmarks',
+ 'pallet-configuration/runtime-benchmarks',
'pallet-common/runtime-benchmarks',
'pallet-structure/runtime-benchmarks',
'pallet-fungible/runtime-benchmarks',
runtime/quartz/Cargo.tomldiffbeforeafterboth--- a/runtime/quartz/Cargo.toml
+++ b/runtime/quartz/Cargo.toml
@@ -28,6 +28,7 @@
'pallet-evm-coder-substrate/runtime-benchmarks',
'pallet-balances/runtime-benchmarks',
'pallet-timestamp/runtime-benchmarks',
+ 'pallet-configuration/runtime-benchmarks',
'pallet-common/runtime-benchmarks',
'pallet-structure/runtime-benchmarks',
'pallet-fungible/runtime-benchmarks',
runtime/unique/Cargo.tomldiffbeforeafterboth--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -28,6 +28,7 @@
'pallet-evm-coder-substrate/runtime-benchmarks',
'pallet-balances/runtime-benchmarks',
'pallet-timestamp/runtime-benchmarks',
+ 'pallet-configuration/runtime-benchmarks',
'pallet-common/runtime-benchmarks',
'pallet-structure/runtime-benchmarks',
'pallet-fungible/runtime-benchmarks',