diff --git a/node/src/command.rs b/node/src/command.rs index c4c8e431790422a1265c42354966b9200548f58c..c4416c6c544c09c41f4cd9b3a09a1b0040e09049 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 0000000000000000000000000000000000000000..a4a5cee903ba2bb4a37abcc043e05f7b6c4820c4 --- /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 e4fac0aa6e84cb9e85410ec6029bb20b166b3751..6ec878506a11ea9fa06b155f9e75c5e4d2a159cd 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 bca13f96315240bcd242fd891d12800233bc729c..b448658a25a4ba7b84ab6987d615fbba2179228c 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 e5d4847979110a65449fb8ecc3cc1bce670340cd..7d2b5a2c7bb6a054ecd40a8d65a51fb2e89d9c0a 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 3144c4c6b5680be1b6af5a10edd8c3382e17633b..518e9b8387277e062e7db2fd8e0573d069abe650 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 793ece8dbcdab0bd62adbc1a5e5b9f4100d1fce2..30f99feb87e79fd4fd1f2eb4cd03555e72064ddd 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