From b44a3345fa0805acc6a8afc2a62d166cec26de79 Mon Sep 17 00:00:00 2001 From: bgallois <benjamin@gallois.cc> Date: Fri, 24 Jan 2025 13:34:00 +0100 Subject: [PATCH] move benchmarks to common runtime --- node/src/command.rs | 5 +-- runtime/common/src/benchmarks.rs | 62 ++++++++++++++++++++++++++++++++ runtime/common/src/lib.rs | 1 + runtime/g1/src/lib.rs | 42 +--------------------- runtime/gdev/src/lib.rs | 43 +--------------------- runtime/gtest/src/lib.rs | 42 +--------------------- rustfmt.toml | 1 + 7 files changed, 68 insertions(+), 128 deletions(-) create mode 100644 runtime/common/src/benchmarks.rs diff --git a/node/src/command.rs b/node/src/command.rs index c4c8e4317..c4416c6c5 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -46,10 +46,7 @@ lazy_static! { /// Unwraps a [`crate::service::client::Client`] into the concrete runtime client. #[cfg(feature = "runtime-benchmarks")] macro_rules! unwrap_client { - ( - $client:ident, - $code:expr - ) => { + ($client:ident, $code:expr) => { match $client.as_ref() { crate::service::client::Client::Client($client) => $code, } diff --git a/runtime/common/src/benchmarks.rs b/runtime/common/src/benchmarks.rs new file mode 100644 index 000000000..a4a5cee90 --- /dev/null +++ b/runtime/common/src/benchmarks.rs @@ -0,0 +1,62 @@ +// Copyright 2021 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +#![cfg(feature = "runtime-benchmarks")] + +#[macro_export] +macro_rules! benchmarks_config { + () => { + #[macro_use] + extern crate frame_benchmarking; + pub use pallet_collective::RawOrigin; + + type WorstOrigin = RawOrigin<AccountId, TechnicalCommitteeInstance>; + + mod benches { + define_benchmarks!( + [pallet_certification, Certification] + [pallet_distance, Distance] + [pallet_oneshot_account, OneshotAccount] + [pallet_universal_dividend, UniversalDividend] + [pallet_provide_randomness, ProvideRandomness] + [pallet_upgrade_origin, UpgradeOrigin] + [pallet_duniter_account, Account] + [pallet_quota, Quota] + [pallet_identity, Identity] + [pallet_membership, Membership] + [pallet_smith_members, SmithMembers] + [pallet_authority_members, AuthorityMembers] + // Substrate + [frame_system_extensions, SystemExtensionsBench::<Runtime>] + [pallet_balances, Balances] + [frame_benchmarking::baseline, Baseline::<Runtime>] + [pallet_collective, TechnicalCommittee] + [pallet_session, SessionBench::<Runtime>] + [pallet_im_online, ImOnline] + [pallet_sudo, Sudo] + [pallet_multisig, Multisig] + [pallet_preimage, Preimage] + [pallet_proxy, Proxy] + [pallet_scheduler, Scheduler] + [frame_system, SystemBench::<Runtime>] + [pallet_timestamp, Timestamp] + [pallet_transaction_payment, TransactionPayment] + [pallet_treasury, Treasury] + [pallet_utility, Utility] + ); + } + }; +} diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index e4fac0aa6..6ec878506 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -17,6 +17,7 @@ #![cfg_attr(not(feature = "std"), no_std)] mod apis; +mod benchmarks; pub mod constants; pub mod entities; pub mod fees; diff --git a/runtime/g1/src/lib.rs b/runtime/g1/src/lib.rs index bca13f963..b448658a2 100644 --- a/runtime/g1/src/lib.rs +++ b/runtime/g1/src/lib.rs @@ -22,10 +22,6 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -#[cfg(feature = "runtime-benchmarks")] -#[macro_use] -extern crate frame_benchmarking; - pub mod parameters; pub mod weights; @@ -39,8 +35,6 @@ use frame_support::{traits::Contains, PalletId}; pub use frame_system::Call as SystemCall; use frame_system::EnsureRoot; pub use pallet_balances::Call as BalancesCall; -#[cfg(feature = "runtime-benchmarks")] -pub use pallet_collective::RawOrigin; use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, }; @@ -137,39 +131,7 @@ pub type Executive = frame_executive::Executive< pub type TechnicalCommitteeInstance = Instance2; -#[cfg(feature = "runtime-benchmarks")] -mod benches { - define_benchmarks!( - [pallet_certification, Certification] - [pallet_distance, Distance] - [pallet_oneshot_account, OneshotAccount] - [pallet_universal_dividend, UniversalDividend] - [pallet_provide_randomness, ProvideRandomness] - [pallet_upgrade_origin, UpgradeOrigin] - [pallet_duniter_account, Account] - [pallet_identity, Identity] - [pallet_membership, Membership] - [pallet_smith_members, SmithMembers] - [pallet_authority_members, AuthorityMembers] - // Substrate - [frame_system_extensions, SystemExtensionsBench::<Runtime>] - [pallet_balances, Balances] - [frame_benchmarking::baseline, Baseline::<Runtime>] - [pallet_collective, TechnicalCommittee] - [pallet_sudo, Sudo] - [pallet_session, SessionBench::<Runtime>] - [pallet_im_online, ImOnline] - [pallet_multisig, Multisig] - [pallet_preimage, Preimage] - [pallet_proxy, Proxy] - [pallet_scheduler, Scheduler] - [frame_system, SystemBench::<Runtime>] - [pallet_timestamp, Timestamp] - [pallet_transaction_payment, TransactionPayment] - [pallet_treasury, Treasury] - [pallet_utility, Utility] - ); -} +common_runtime::benchmarks_config!(); pub struct BaseCallFilter; impl Contains<RuntimeCall> for BaseCallFilter { @@ -231,8 +193,6 @@ impl frame_support::traits::InstanceFilter<RuntimeCall> for ProxyType { } } -#[cfg(feature = "runtime-benchmarks")] -type WorstOrigin = RawOrigin<AccountId, TechnicalCommitteeInstance>; // Configure pallets to include in runtime. common_runtime::pallets_config!(); diff --git a/runtime/gdev/src/lib.rs b/runtime/gdev/src/lib.rs index e5d484797..7d2b5a2c7 100644 --- a/runtime/gdev/src/lib.rs +++ b/runtime/gdev/src/lib.rs @@ -22,10 +22,6 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -#[cfg(feature = "runtime-benchmarks")] -#[macro_use] -extern crate frame_benchmarking; - pub mod parameters; pub mod weights; @@ -39,8 +35,6 @@ use frame_support::{traits::Contains, PalletId}; pub use frame_system::Call as SystemCall; use frame_system::EnsureRoot; pub use pallet_balances::Call as BalancesCall; -#[cfg(feature = "runtime-benchmarks")] -pub use pallet_collective::RawOrigin; pub use pallet_duniter_test_parameters::Parameters as GenesisParameters; use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, @@ -138,40 +132,7 @@ pub type Executive = frame_executive::Executive< pub type TechnicalCommitteeInstance = Instance2; -#[cfg(feature = "runtime-benchmarks")] -mod benches { - define_benchmarks!( - [pallet_certification, Certification] - [pallet_distance, Distance] - [pallet_oneshot_account, OneshotAccount] - [pallet_universal_dividend, UniversalDividend] - [pallet_provide_randomness, ProvideRandomness] - [pallet_upgrade_origin, UpgradeOrigin] - [pallet_duniter_account, Account] - [pallet_quota, Quota] - [pallet_identity, Identity] - [pallet_membership, Membership] - [pallet_smith_members, SmithMembers] - [pallet_authority_members, AuthorityMembers] - // Substrate - [frame_system_extensions, SystemExtensionsBench::<Runtime>] - [pallet_balances, Balances] - [frame_benchmarking::baseline, Baseline::<Runtime>] - [pallet_collective, TechnicalCommittee] - [pallet_session, SessionBench::<Runtime>] - [pallet_im_online, ImOnline] - [pallet_sudo, Sudo] - [pallet_multisig, Multisig] - [pallet_preimage, Preimage] - [pallet_proxy, Proxy] - [pallet_scheduler, Scheduler] - [frame_system, SystemBench::<Runtime>] - [pallet_timestamp, Timestamp] - [pallet_transaction_payment, TransactionPayment] - [pallet_treasury, Treasury] - [pallet_utility, Utility] - ); -} +common_runtime::benchmarks_config!(); pub struct BaseCallFilter; impl Contains<RuntimeCall> for BaseCallFilter { @@ -274,8 +235,6 @@ impl pallet_duniter_test_parameters::Config for Runtime { type PeriodCount = Balance; type SessionCount = u32; } -#[cfg(feature = "runtime-benchmarks")] -type WorstOrigin = RawOrigin<AccountId, TechnicalCommitteeInstance>; common_runtime::pallets_config!(); // Create the runtime by composing the pallets that were previously configured. diff --git a/runtime/gtest/src/lib.rs b/runtime/gtest/src/lib.rs index 3144c4c6b..518e9b838 100644 --- a/runtime/gtest/src/lib.rs +++ b/runtime/gtest/src/lib.rs @@ -22,10 +22,6 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -#[cfg(feature = "runtime-benchmarks")] -#[macro_use] -extern crate frame_benchmarking; - pub mod parameters; pub mod weights; @@ -39,8 +35,6 @@ use frame_support::{traits::Contains, PalletId}; pub use frame_system::Call as SystemCall; use frame_system::EnsureRoot; pub use pallet_balances::Call as BalancesCall; -#[cfg(feature = "runtime-benchmarks")] -pub use pallet_collective::RawOrigin; use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, }; @@ -137,39 +131,7 @@ pub type Executive = frame_executive::Executive< pub type TechnicalCommitteeInstance = Instance2; -#[cfg(feature = "runtime-benchmarks")] -mod benches { - define_benchmarks!( - [pallet_certification, Certification] - [pallet_distance, Distance] - [pallet_oneshot_account, OneshotAccount] - [pallet_universal_dividend, UniversalDividend] - [pallet_provide_randomness, ProvideRandomness] - [pallet_upgrade_origin, UpgradeOrigin] - [pallet_duniter_account, Account] - [pallet_identity, Identity] - [pallet_membership, Membership] - [pallet_smith_members, SmithMembers] - [pallet_authority_members, AuthorityMembers] - // Substrate - [frame_system_extensions, SystemExtensionsBench::<Runtime>] - [pallet_balances, Balances] - [frame_benchmarking::baseline, Baseline::<Runtime>] - [pallet_collective, TechnicalCommittee] - [pallet_session, SessionBench::<Runtime>] - [pallet_im_online, ImOnline] - [pallet_multisig, Multisig] - [pallet_preimage, Preimage] - [pallet_proxy, Proxy] - [pallet_sudo, Sudo] - [pallet_scheduler, Scheduler] - [frame_system, SystemBench::<Runtime>] - [pallet_timestamp, Timestamp] - [pallet_transaction_payment, TransactionPayment] - [pallet_treasury, Treasury] - [pallet_utility, Utility] - ); -} +common_runtime::benchmarks_config!(); pub struct BaseCallFilter; impl Contains<RuntimeCall> for BaseCallFilter { @@ -239,8 +201,6 @@ impl frame_support::traits::InstanceFilter<RuntimeCall> for ProxyType { } // Configure pallets to include in runtime. -#[cfg(feature = "runtime-benchmarks")] -type WorstOrigin = RawOrigin<AccountId, TechnicalCommitteeInstance>; common_runtime::pallets_config!(); // Create the runtime by composing the pallets that were previously configured. diff --git a/rustfmt.toml b/rustfmt.toml index 793ece8db..30f99feb8 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,4 @@ imports_granularity = "Crate" reorder_impl_items = true error_on_unformatted = true +format_macro_matchers = true -- GitLab