Skip to content

Commit

Permalink
Fix build with runtime-benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadkaouk committed Dec 14, 2023
1 parent 4bbc605 commit 6f66dd5
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions pallets/moonbeam-xcm-benchmarks/src/generic/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use frame_support::{
traits::{Everything, OriginTrait},
};
use parity_scale_codec::Decode;
use sp_core::H256;
use sp_core::{ConstU64, H256};
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup, TrailingZeroInput},
BuildStorage,
Expand All @@ -44,6 +44,7 @@ frame_support::construct_runtime!(
System: frame_system,
PolkadotXcmBenchmarks: pallet_xcm_benchmarks::generic,
XcmGenericBenchmarks: generic,
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
}
);

Expand Down Expand Up @@ -78,10 +79,27 @@ impl frame_system::Config for Test {
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

impl pallet_balances::Config for Test {
type MaxReserves = ();
type ReserveIdentifier = [u8; 4];
type MaxLocks = ();
type Balance = u64;
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
type ExistentialDeposit = ConstU64<0>;
type AccountStore = System;
type WeightInfo = ();
type RuntimeHoldReason = ();
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
type RuntimeFreezeReason = ();
}

/// The benchmarks in this pallet should never need an asset transactor to begin with.
pub struct NoAssetTransactor;
impl xcm_executor::traits::TransactAsset for NoAssetTransactor {
fn deposit_asset(_: &MultiAsset, _: &MultiLocation, _: &XcmContext) -> Result<(), XcmError> {
fn deposit_asset(_: &MultiAsset, _: &MultiLocation, _: Option<&XcmContext>) -> Result<(), XcmError> {
unreachable!();
}

Expand Down Expand Up @@ -131,6 +149,7 @@ impl xcm_executor::Config for XcmConfig {
impl pallet_xcm_benchmarks::Config for Test {
type XcmConfig = XcmConfig;
type AccountIdConverter = AccountIdConverter;
type DeliveryHelper = ();
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
let valid_destination: MultiLocation = Junction::AccountId32 {
network: None,
Expand All @@ -147,6 +166,7 @@ impl pallet_xcm_benchmarks::Config for Test {

impl pallet_xcm_benchmarks::generic::Config for Test {
type RuntimeCall = RuntimeCall;
type TransactAsset = Balances;

fn worst_case_response() -> (u64, Response) {
let assets: MultiAssets = (Concrete(Here.into()), 100).into();
Expand Down
1 change: 1 addition & 0 deletions precompiles/collective/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ std = [
"sp-std/std",
"xcm-primitives/std",
]
runtime-benchmarks = []
16 changes: 15 additions & 1 deletion precompiles/collective/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use frame_support::{
use frame_support::traits::tokens::{PayFromAccount, UnityAssetBalanceConversion};
use frame_system::pallet_prelude::BlockNumberFor;
use pallet_evm::{EnsureAddressNever, EnsureAddressRoot, SubstrateBlockHashMapping};
use pallet_treasury::ArgumentsFactory;
use precompile_utils::{
precompile_set::*,
testing::{Bob, Charlie, MockAccount},
Expand Down Expand Up @@ -185,6 +186,19 @@ parameter_types! {
pub TreasuryAccount: AccountId = Treasury::account_id();
}

#[cfg(feature = "runtime-benchmarks")]
pub struct BenchmarkHelper;
#[cfg(feature = "runtime-benchmarks")]
impl ArgumentsFactory<(), AccountId> for BenchmarkHelper {
fn create_asset_kind(_seed: u32) -> () {
()
}

fn create_beneficiary(seed: [u8; 32]) -> AccountId {
AccountId::from(H160::from(H256::from(seed)))
}
}

impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryId;
type Currency = Balances;
Expand Down Expand Up @@ -213,7 +227,7 @@ impl pallet_treasury::Config for Runtime {
type BalanceConverter = UnityAssetBalanceConversion;
type PayoutPeriod = ConstU32<0>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type BenchmarkHelper = BenchmarkHelper;
}

parameter_types! {
Expand Down
3 changes: 3 additions & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ xcm = { workspace = true }
xcm-builder = { workspace = true }
xcm-executor = { workspace = true }

account = { workspace = true }

[features]
std = [
"fp-ethereum/std",
Expand All @@ -94,6 +96,7 @@ std = [
"sp-std/std",
"xcm-executor/std",
"xcm/std",
"account/std"
]
runtime-benchmarks = [
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
Expand Down
2 changes: 2 additions & 0 deletions runtime/common/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ macro_rules! impl_runtime_apis_plus_common {
impl pallet_xcm_benchmarks::Config for Runtime {
type XcmConfig = xcm_config::XcmExecutorConfig;
type AccountIdConverter = xcm_config::LocationToAccountId;
type DeliveryHelper = ();
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
Ok(MultiLocation::parent())
}
Expand Down Expand Up @@ -664,6 +665,7 @@ macro_rules! impl_runtime_apis_plus_common {

impl pallet_xcm_benchmarks::generic::Config for Runtime {
type RuntimeCall = RuntimeCall;
type TransactAsset = Balances;

fn worst_case_response() -> (u64, Response) {
(0u64, Response::Version(Default::default()))
Expand Down
30 changes: 30 additions & 0 deletions runtime/common/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2019-2023 PureStake Inc.
// This file is part of Moonbeam.

// Moonbeam 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.

// Moonbeam 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 Moonbeam. If not, see <http://www.gnu.org/licenses/>.

use pallet_treasury::ArgumentsFactory;
use account::AccountId20;

pub struct BenchmarkHelper;

impl ArgumentsFactory<(), AccountId20> for BenchmarkHelper{
fn create_asset_kind(_seed: u32) -> () {
()
}

fn create_beneficiary(seed: [u8; 32]) -> AccountId20 {
AccountId20::from(seed)
}
}
3 changes: 3 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ mod impl_self_contained_call;
mod impl_xcm_evm_runner;
pub mod migrations;
pub mod weights;

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
3 changes: 3 additions & 0 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ impl pallet_treasury::Config for Runtime {
type Paymaster = PayFromAccount<Balances, TreasuryAccount>;
type BalanceConverter = UnityAssetBalanceConversion;
type PayoutPeriod = ConstU32<0>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = BenchmarkHelper;
}

type IdentityForceOrigin = EitherOfDiverse<
Expand Down Expand Up @@ -1478,6 +1480,7 @@ pub type Executive = frame_executive::Executive<
use {
moonbeam_xcm_benchmarks::generic::benchmarking as MoonbeamXcmBenchmarks,
MoonbeamXcmBenchmarks::XcmGenericBenchmarks as MoonbeamXcmGenericBench,
moonbeam_runtime_common::benchmarking::BenchmarkHelper,
};
#[cfg(feature = "runtime-benchmarks")]
mod benches {
Expand Down
4 changes: 2 additions & 2 deletions runtime/moonbase/tests/evm_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod tests {
.build()
.execute_with(|| {
let non_eth_uxt = UncheckedExtrinsic::new_unsigned(
pallet_balances::Call::<Runtime>::transfer {
pallet_balances::Call::<Runtime>::transfer_allow_death {
dest: AccountId::from(BOB),
value: 1 * UNIT,
}
Expand Down Expand Up @@ -75,7 +75,7 @@ mod tests {
.build()
.execute_with(|| {
let non_eth_uxt = UncheckedExtrinsic::new_unsigned(
pallet_balances::Call::<Runtime>::transfer {
pallet_balances::Call::<Runtime>::transfer_allow_death {
dest: AccountId::from(BOB),
value: 1 * UNIT,
}
Expand Down
4 changes: 3 additions & 1 deletion runtime/moonbase/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ use xcm_simulator::{
DmpMessageHandlerT as DmpMessageHandler, XcmpMessageFormat,
XcmpMessageHandlerT as XcmpMessageHandler,
};
#[cfg(feature = "runtime-benchmarks")]
use moonbeam_runtime_common::benchmarking::BenchmarkHelper as ArgumentsBenchmarkHelper;

pub type AccountId = moonbeam_core_primitives::AccountId;
pub type Balance = u128;
Expand Down Expand Up @@ -538,7 +540,7 @@ impl pallet_treasury::Config for Runtime {
type BalanceConverter = UnityAssetBalanceConversion;
type PayoutPeriod = ConstU32<0>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type BenchmarkHelper = ArgumentsBenchmarkHelper;
}

#[frame_support::pallet]
Expand Down
3 changes: 3 additions & 0 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ impl pallet_treasury::Config for Runtime {
type Paymaster = PayFromAccount<Balances, TreasuryAccount>;
type BalanceConverter = UnityAssetBalanceConversion;
type PayoutPeriod = ConstU32<0>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = BenchmarkHelper;
}

type IdentityForceOrigin = EitherOfDiverse<
Expand Down Expand Up @@ -1484,6 +1486,7 @@ construct_runtime! {
use {
moonbeam_xcm_benchmarks::generic::benchmarking as MoonbeamXcmBenchmarks,
MoonbeamXcmBenchmarks::XcmGenericBenchmarks as MoonbeamXcmGenericBench,
moonbeam_runtime_common::benchmarking::BenchmarkHelper,
};
#[cfg(feature = "runtime-benchmarks")]
mod benches {
Expand Down
4 changes: 2 additions & 2 deletions runtime/moonbeam/tests/evm_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod tests {
.build()
.execute_with(|| {
let non_eth_uxt = UncheckedExtrinsic::new_unsigned(
pallet_balances::Call::<Runtime>::transfer {
pallet_balances::Call::<Runtime>::transfer_allow_death {
dest: AccountId::from(BOB),
value: 1 * GLMR,
}
Expand Down Expand Up @@ -75,7 +75,7 @@ mod tests {
.build()
.execute_with(|| {
let non_eth_uxt = UncheckedExtrinsic::new_unsigned(
pallet_balances::Call::<Runtime>::transfer {
pallet_balances::Call::<Runtime>::transfer_allow_death {
dest: AccountId::from(BOB),
value: 1 * GLMR,
}
Expand Down
4 changes: 3 additions & 1 deletion runtime/moonbeam/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ use xcm_simulator::{
DmpMessageHandlerT as DmpMessageHandler, XcmpMessageFormat,
XcmpMessageHandlerT as XcmpMessageHandler,
};
#[cfg(feature = "runtime-benchmarks")]
use moonbeam_runtime_common::benchmarking::BenchmarkHelper as ArgumentsBenchmarkHelper;

pub type AccountId = moonbeam_core_primitives::AccountId;
pub type Balance = u128;
Expand Down Expand Up @@ -519,7 +521,7 @@ impl pallet_treasury::Config for Runtime {
type BalanceConverter = UnityAssetBalanceConversion;
type PayoutPeriod = ConstU32<0>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type BenchmarkHelper = ArgumentsBenchmarkHelper;
}

#[frame_support::pallet]
Expand Down
3 changes: 3 additions & 0 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ impl pallet_treasury::Config for Runtime {
type Paymaster = PayFromAccount<Balances, TreasuryAccount>;
type BalanceConverter = UnityAssetBalanceConversion;
type PayoutPeriod = ConstU32<0>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = BenchmarkHelper;
}

type IdentityForceOrigin = EitherOfDiverse<
Expand Down Expand Up @@ -1486,6 +1488,7 @@ construct_runtime! {
use {
moonbeam_xcm_benchmarks::generic::benchmarking as MoonbeamXcmBenchmarks,
MoonbeamXcmBenchmarks::XcmGenericBenchmarks as MoonbeamXcmGenericBench,
moonbeam_runtime_common::benchmarking::BenchmarkHelper,
};
#[cfg(feature = "runtime-benchmarks")]
mod benches {
Expand Down
4 changes: 2 additions & 2 deletions runtime/moonriver/tests/evm_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod tests {
.build()
.execute_with(|| {
let non_eth_uxt = UncheckedExtrinsic::new_unsigned(
pallet_balances::Call::<Runtime>::transfer {
pallet_balances::Call::<Runtime>::transfer_allow_death {
dest: AccountId::from(BOB),
value: 1 * MOVR,
}
Expand Down Expand Up @@ -75,7 +75,7 @@ mod tests {
.build()
.execute_with(|| {
let non_eth_uxt = UncheckedExtrinsic::new_unsigned(
pallet_balances::Call::<Runtime>::transfer {
pallet_balances::Call::<Runtime>::transfer_allow_death {
dest: AccountId::from(BOB),
value: 1 * MOVR,
}
Expand Down
4 changes: 3 additions & 1 deletion runtime/moonriver/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ use xcm_simulator::{
DmpMessageHandlerT as DmpMessageHandler, XcmpMessageFormat,
XcmpMessageHandlerT as XcmpMessageHandler,
};
#[cfg(feature = "runtime-benchmarks")]
use moonbeam_runtime_common::benchmarking::BenchmarkHelper as ArgumentsBenchmarkHelper;

pub type AccountId = moonbeam_core_primitives::AccountId;
pub type Balance = u128;
Expand Down Expand Up @@ -532,7 +534,7 @@ impl pallet_treasury::Config for Runtime {
type BalanceConverter = UnityAssetBalanceConversion;
type PayoutPeriod = ConstU32<0>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type BenchmarkHelper = ArgumentsBenchmarkHelper;
}

#[frame_support::pallet]
Expand Down

0 comments on commit 6f66dd5

Please sign in to comment.