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(mainnet): include all benchmarks #478

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions pallets/motion/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,42 @@ mod benchmarks {
use super::*;

#[benchmark]
fn simple_majority() {
fn simple_majority() -> Result<(), BenchmarkError> {
let call: <T as Config>::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into();
let origin = <T as Config>::SimpleMajorityOrigin::try_successful_origin().unwrap();
let origin = <T as Config>::SimpleMajorityOrigin::try_successful_origin()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As per the configuration in our runtime, this check will never ensure origin. Hence, the benchamrk needed to be updated such that a possible runtime config won't break it.

I have configure this case to use Weightless. Maybe MAX weight could be a better option.

Same with the rest of changes below.

.map_err(|_| BenchmarkError::Weightless)?;

#[extrinsic_call]
_(origin as T::RuntimeOrigin, Box::new(call));

assert_last_event::<T>(Event::DispatchSimpleMajority { motion_result: Ok(()) }.into())
assert_last_event::<T>(Event::DispatchSimpleMajority { motion_result: Ok(()) }.into());
Ok(())
}

#[benchmark]
fn super_majority() {
fn super_majority() -> Result<(), BenchmarkError> {
let call: <T as Config>::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into();
let origin = <T as Config>::SuperMajorityOrigin::try_successful_origin().unwrap();
let origin = <T as Config>::SuperMajorityOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;

#[extrinsic_call]
_(origin as T::RuntimeOrigin, Box::new(call));

assert_last_event::<T>(Event::DispatchSuperMajority { motion_result: Ok(()) }.into())
assert_last_event::<T>(Event::DispatchSuperMajority { motion_result: Ok(()) }.into());
Ok(())
}

#[benchmark]
fn unanimous() {
fn unanimous() -> Result<(), BenchmarkError> {
let call: <T as Config>::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into();
let origin = <T as Config>::UnanimousOrigin::try_successful_origin().unwrap();
let origin = <T as Config>::UnanimousOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;

#[extrinsic_call]
_(origin as T::RuntimeOrigin, Box::new(call));

assert_last_event::<T>(Event::DispatchUnanimous { motion_result: Ok(()) }.into())
assert_last_event::<T>(Event::DispatchUnanimous { motion_result: Ok(()) }.into());
Ok(())
}

impl_benchmark_test_suite!(Motion, crate::mock::new_test_ext(), crate::mock::Test);
Expand Down
3 changes: 3 additions & 0 deletions runtime/mainnet/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
use frame_benchmarking::{Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;
use frame_system_benchmarking::Pallet as SystemBench;
use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
use super::*;

Expand All @@ -282,8 +283,10 @@
use super::*;

use frame_system_benchmarking::Pallet as SystemBench;
use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;


impl frame_system_benchmarking::Config for Runtime {

Check warning on line 289 in runtime/mainnet/src/apis.rs

View workflow job for this annotation

GitHub Actions / clippy

non-local `impl` definition, `impl` blocks should be written at the same level as their item

warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item --> runtime/mainnet/src/apis.rs:289:4 | 279 | / fn dispatch_benchmark( 280 | | config: frame_benchmarking::BenchmarkConfig 281 | | ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> { | |___________________________________________________________________________________- move the `impl` block outside of this associated function `dispatch_benchmark` ... 289 | impl frame_system_benchmarking::Config for Runtime { | ^^^^^---------------------------------^^^^^------- | | | | | `Runtime` is not local | `Config` is not local | = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` = note: `#[warn(non_local_definitions)]` on by default
fn setup_set_code_requirements(code: &Vec<u8>) -> Result<(), BenchmarkError> {
ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32);
Ok(())
Expand All @@ -295,7 +298,7 @@
}

use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
impl cumulus_pallet_session_benchmarking::Config for Runtime {}

Check warning on line 301 in runtime/mainnet/src/apis.rs

View workflow job for this annotation

GitHub Actions / clippy

non-local `impl` definition, `impl` blocks should be written at the same level as their item

warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item --> runtime/mainnet/src/apis.rs:301:4 | 279 | / fn dispatch_benchmark( 280 | | config: frame_benchmarking::BenchmarkConfig 281 | | ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> { | |___________________________________________________________________________________- move the `impl` block outside of this associated function `dispatch_benchmark` ... 301 | impl cumulus_pallet_session_benchmarking::Config for Runtime {} | ^^^^^-------------------------------------------^^^^^------- | | | | | `Runtime` is not local | `Config` is not local | = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`

use frame_support::traits::WhitelistedStorageKeys;
let whitelist = AllPalletsWithSystem::whitelisted_storage_keys();
Expand Down
44 changes: 44 additions & 0 deletions runtime/mainnet/src/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use crate::{config::assets::TrustBackedAssetsInstance, Runtime};

/// Instance of `pallet_assets` used for benchmarks of trust backed assets.
pub type TrustBackedAssets = pallet_assets::Pallet<Runtime, TrustBackedAssetsInstance>;

frame_benchmarking::define_benchmarks!(
// Ordered as per runtime
Copy link
Collaborator

Choose a reason for hiding this comment

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

🔥

// System
[frame_system, SystemBench::<Runtime>]
[frame_system_extensions, SystemExtensionsBench::<Runtime>]
[cumulus_pallet_parachain_system, ParachainSystem]
[pallet_timestamp, Timestamp]
// Monetary
[pallet_balances, Balances]
[pallet_transaction_payment, TransactionPayment]
[pallet_treasury, Treasury]
// Governance
[pallet_sudo, Sudo]
[pallet_collective, Council]
[pallet_motion, Motion]
// Collation support
[pallet_collator_selection, CollatorSelection]
[pallet_session, SessionBench::<Runtime>]
// Scheduler
[pallet_scheduler, Scheduler]
// Preimage
[pallet_preimage, Preimage]
// XCM
[cumulus_pallet_xcmp_queue, XcmpQueue]
// TODO: intro xcm benchmarks
//[pallet_xcm, PolkadotXcm::<Runtime>]
[pallet_message_queue, MessageQueue]
// Contracts
[pallet_revive, Revive]
// Proxy
[pallet_proxy, Proxy]
// Multisig
[pallet_multisig, Multisig]
// Utility
[pallet_utility, Utility]
// Assets
[pallet_nfts, Nfts]
[pallet_assets, TrustBackedAssets]
);
8 changes: 4 additions & 4 deletions runtime/mainnet/src/config/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use parachains_common::{AssetIdForTrustBackedAssets, CollectionId, ItemId, Signa
use sp_runtime::traits::Verify;

use crate::{
config::monetary::ExistentialDeposit, deposit, AccountId, Balance, Balances, BlockNumber,
Runtime, RuntimeEvent, DAYS,
config::monetary::ExistentialDeposit, deposit, weights, AccountId, Balance, Balances,
BlockNumber, Runtime, RuntimeEvent, DAYS,
};

/// We allow root to execute privileged asset operations.
Expand Down Expand Up @@ -53,7 +53,7 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type RemoveItemsLimit = ConstU32<1000>;
type RuntimeEvent = RuntimeEvent;
type StringLimit = AssetsStringLimit;
type WeightInfo = pallet_assets::weights::SubstrateWeight<Self>;
type WeightInfo = weights::pallet_assets::WeightInfo<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -101,7 +101,7 @@ impl pallet_nfts::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type StringLimit = ConstU32<256>;
type ValueLimit = ConstU32<256>;
type WeightInfo = pallet_nfts::weights::SubstrateWeight<Self>;
type WeightInfo = weights::pallet_nfts::WeightInfo<Runtime>;
}

#[cfg(test)]
Expand Down
18 changes: 14 additions & 4 deletions runtime/mainnet/src/config/collation.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use pop_runtime_common::{HOURS, SLOT_DURATION};

use crate::{
parameter_types, AccountId, Aura, AuraId, Balances, CollatorSelection, ConstBool, ConstU32,
ConstU64, EnsureRoot, PalletId, Runtime, RuntimeEvent, Session, SessionKeys,
parameter_types, weights, AccountId, Aura, AuraId, Balances, CollatorSelection, ConstBool,
ConstU32, ConstU64, EnsureRoot, PalletId, Runtime, RuntimeEvent, Session, SessionKeys,
};

impl pallet_authorship::Config for Runtime {
Expand Down Expand Up @@ -37,6 +37,10 @@ impl pallet_collator_selection::Config for Runtime {
type Currency = Balances;
// Should be a multiple of session or things will get inconsistent.
type KickThreshold = Period;
#[cfg(feature = "runtime-benchmarks")]
// If configured to `0`, benchmarks underflows.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

add_invulnerable extrinsic benchmark breaks with our current non candidates config.

type MaxCandidates = ConstU32<10>;
#[cfg(not(feature = "runtime-benchmarks"))]
type MaxCandidates = ConstU32<0>;
type MaxInvulnerables = ConstU32<20>;
type MinEligibleCollators = ConstU32<3>;
Expand All @@ -46,7 +50,7 @@ impl pallet_collator_selection::Config for Runtime {
type ValidatorId = AccountId;
type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
type ValidatorRegistration = Session;
type WeightInfo = pallet_collator_selection::weights::SubstrateWeight<Runtime>;
type WeightInfo = weights::pallet_collator_selection::WeightInfo<Runtime>;
}

impl cumulus_pallet_aura_ext::Config for Runtime {}
Expand All @@ -61,7 +65,7 @@ impl pallet_session::Config for Runtime {
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
type ValidatorId = AccountId;
type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
type WeightInfo = pallet_session::weights::SubstrateWeight<Runtime>;
type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
}

#[cfg(test)]
Expand Down Expand Up @@ -154,8 +158,14 @@ mod tests {

#[test]
fn candidates_disabled() {
#[cfg(feature = "runtime-benchmarks")]
assert_eq!(
<<Runtime as pallet_collator_selection::Config>::MaxCandidates as Get<u32>>::get(),
10
);
// Disabled to start until sufficient distribution/value to allow candidates to provide
// candidacy bond
#[cfg(not(feature = "runtime-benchmarks"))]
assert_eq!(
<<Runtime as pallet_collator_selection::Config>::MaxCandidates as Get<u32>>::get(),
0
Expand Down
8 changes: 4 additions & 4 deletions runtime/mainnet/src/config/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use sp_core::crypto::Ss58Codec;

use crate::{
config::system::RuntimeBlockWeights, AccountId, Runtime, RuntimeCall, RuntimeEvent,
config::system::RuntimeBlockWeights, weights, AccountId, Runtime, RuntimeCall, RuntimeEvent,
RuntimeOrigin,
};

Expand Down Expand Up @@ -40,7 +40,7 @@
pub SudoAddress: AccountId = AccountId::from_ss58check(SUDO_ADDRESS).expect("sudo address is valid SS58");
}

pub type CouncilCollective = pallet_collective::Instance1;

Check warning on line 43 in runtime/mainnet/src/config/governance.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a type alias

warning: missing documentation for a type alias --> runtime/mainnet/src/config/governance.rs:43:1 | 43 | pub type CouncilCollective = pallet_collective::Instance1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^
impl pallet_collective::Config<CouncilCollective> for Runtime {
type Consideration = ();
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
Expand All @@ -54,7 +54,7 @@
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type SetMembersOrigin = EnsureRoot<AccountId>;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type WeightInfo = weights::pallet_collective::WeightInfo<Runtime>;
}

impl pallet_motion::Config for Runtime {
Expand All @@ -66,13 +66,13 @@
type SuperMajorityOrigin = AtLeastThreeFourthsOfCouncil;
// A unanimous council vote is needed.
type UnanimousOrigin = UnanimousCouncilVote;
type WeightInfo = pallet_motion::weights::SubstrateWeight<Runtime>;
type WeightInfo = weights::pallet_motion::WeightInfo<Runtime>;
}

impl pallet_sudo::Config for Runtime {
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
type WeightInfo = weights::pallet_sudo::WeightInfo<Runtime>;
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion runtime/mainnet/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Assets.
mod assets;
pub(crate) mod assets;
// Collation.
pub(crate) mod collation;
/// Governance.
Expand Down
10 changes: 5 additions & 5 deletions runtime/mainnet/src/config/monetary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use sp_runtime::traits::{AccountIdConversion, IdentityLookup};

use crate::{
parameter_types, AccountId, Balance, Balances, BlockNumber, ConstU32, ConstU8,
parameter_types, weights, AccountId, Balance, Balances, BlockNumber, ConstU32, ConstU8,
ConstantMultiplier, EnsureRoot, PalletId, ResolveTo, Runtime, RuntimeEvent,
RuntimeFreezeReason, RuntimeHoldReason, SlowAdjustingFeeUpdate, System, VariantCountOf, DAYS,
EXISTENTIAL_DEPOSIT,
Expand Down Expand Up @@ -129,7 +129,7 @@
type RuntimeEvent = RuntimeEvent;
type RuntimeFreezeReason = RuntimeFreezeReason;
type RuntimeHoldReason = RuntimeHoldReason;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -164,7 +164,7 @@
type OnChargeTransaction = OnChargeTransaction;
type OperationalFeeMultiplier = ConstU8<5>;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_transaction_payment::weights::SubstrateWeight<Runtime>;
type WeightInfo = weights::pallet_transaction_payment::WeightInfo<Runtime>;
type WeightToFee = fee::WeightToFee;
}

Expand All @@ -180,8 +180,8 @@
pub struct BenchmarkHelper;
#[cfg(feature = "runtime-benchmarks")]
impl pallet_treasury::ArgumentsFactory<(), AccountId> for BenchmarkHelper {
fn create_asset_kind(_seed: u32) -> () {

Check warning on line 183 in runtime/mainnet/src/config/monetary.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded unit return type

warning: unneeded unit return type --> runtime/mainnet/src/config/monetary.rs:183:34 | 183 | fn create_asset_kind(_seed: u32) -> () { | ^^^^^^ help: remove the `-> ()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit = note: `#[warn(clippy::unused_unit)]` on by default
()

Check warning on line 184 in runtime/mainnet/src/config/monetary.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded unit expression

warning: unneeded unit expression --> runtime/mainnet/src/config/monetary.rs:184:3 | 184 | () | ^^ help: remove the final `()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit
}

fn create_beneficiary(seed: [u8; 32]) -> AccountId {
Expand All @@ -189,7 +189,7 @@
Balances::force_set_balance(
crate::RuntimeOrigin::root(),
account_id.clone().into(),
EXISTENTIAL_DEPOSIT,
ExistentialDeposit::get(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Align with mainnet ED.

)
.unwrap();
account_id
Expand All @@ -216,7 +216,7 @@
/// Never allow origins except via the proposals process.
type SpendOrigin = NeverEnsureOrigin<Balance>;
type SpendPeriod = SpendPeriod;
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
type WeightInfo = weights::pallet_treasury::WeightInfo<Runtime>;
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions runtime/mainnet/src/config/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use pallet_nfts_sdk as pallet_nfts;
use pop_runtime_common::proxy::{MaxPending, MaxProxies, ProxyType};

use crate::{
config::assets::TrustBackedAssetsCall, deposit, parameter_types, Balance, Balances,
config::assets::TrustBackedAssetsCall, deposit, parameter_types, weights, Balance, Balances,
BlakeTwo256, Runtime, RuntimeCall, RuntimeEvent,
};

Expand Down Expand Up @@ -115,7 +115,7 @@ impl pallet_proxy::Config for Runtime {
type ProxyType = ProxyType;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_proxy::weights::SubstrateWeight<Self>;
type WeightInfo = weights::pallet_proxy::WeightInfo<Self>;
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions runtime/mainnet/src/config/revive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use frame_support::{
use frame_system::EnsureSigned;

use crate::{
deposit, Balance, Balances, Perbill, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent,
deposit, weights, Balance, Balances, Perbill, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent,
RuntimeHoldReason, Timestamp, TransactionPayment, UNIT,
};

Expand Down Expand Up @@ -46,7 +46,7 @@ impl pallet_revive::Config for Runtime {
// Disables access to unsafe host fns such as xcm_send.
type UnsafeUnstableInterface = ConstBool<false>;
type UploadOrigin = EnsureSigned<Self::AccountId>;
type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
type WeightInfo = weights::pallet_revive::WeightInfo<Self>;
type WeightPrice = TransactionPayment;
type Xcm = PolkadotXcm;
}
Expand Down
11 changes: 5 additions & 6 deletions runtime/mainnet/src/config/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sp_runtime::traits::AccountIdLookup;
#[allow(unused_imports)]
use crate::Executive;
use crate::{
parameter_types,
parameter_types, weights,
weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},
AccountId, AggregateMessageOrigin, Aura, Balance, BlakeTwo256, Block, BlockLength,
BlockWeights, DispatchClass, Hash, MessageQueue, PalletInfo, Runtime, RuntimeCall,
Expand Down Expand Up @@ -87,7 +87,7 @@ impl frame_system::Config for Runtime {
/// The weight of database operations that the runtime can invoke.
type DbWeight = RocksDbWeight;
/// Weight information for the extensions of this pallet.
type ExtensionsWeightInfo = ();
type ExtensionsWeightInfo = weights::frame_system_extensions::WeightInfo<Runtime>;
/// The type for hashing blocks and tries.
type Hash = Hash;
/// The default hashing algorithm used.
Expand Down Expand Up @@ -122,7 +122,7 @@ impl frame_system::Config for Runtime {
type SS58Prefix = SS58Prefix;
type SingleBlockMigrations = ();
/// Weight information for the extrinsics of this pallet.
type SystemWeightInfo = frame_system::weights::SubstrateWeight<Self>;
type SystemWeightInfo = weights::frame_system::WeightInfo<Self>;
/// Runtime version.
type Version = Version;
}
Expand Down Expand Up @@ -159,7 +159,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SelectCore = cumulus_pallet_parachain_system::LookaheadCoreSelector<Runtime>;
type SelfParaId = parachain_info::Pallet<Runtime>;
type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight<Runtime>;
type WeightInfo = weights::cumulus_pallet_parachain_system::WeightInfo<Runtime>;
type XcmpMessageHandler = XcmpQueue;
}

Expand All @@ -168,7 +168,7 @@ impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = u64;
type OnTimestampSet = Aura;
type WeightInfo = pallet_timestamp::weights::SubstrateWeight<Runtime>;
type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
}

impl parachain_info::Config for Runtime {}
Expand Down Expand Up @@ -452,7 +452,6 @@ mod tests {
}

#[test]
#[ignore]
fn extensions_do_not_use_default_weights() {
assert_ne!(
TypeId::of::<<Runtime as frame_system::Config>::ExtensionsWeightInfo>(),
Expand Down
Loading
Loading