Skip to content

fix pallet-xcm benchmarks #2799

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

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 16 additions & 14 deletions Cargo.lock

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

64 changes: 51 additions & 13 deletions runtime/common/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ macro_rules! impl_runtime_apis_plus_common {
use frame_support::traits::StorageInfoTrait;
use MoonbeamXcmBenchmarks::XcmGenericBenchmarks as MoonbeamXcmGenericBench;

use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;

let mut list = Vec::<BenchmarkList>::new();
list_benchmarks!(list, extra);
Expand Down Expand Up @@ -693,8 +693,7 @@ macro_rules! impl_runtime_apis_plus_common {

use pallet_asset_manager::Config as PalletAssetManagerConfig;

use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;
type ExistentialDeposit = ConstU128<0>;
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
parameter_types! {
pub const RandomParaId: ParaId = ParaId::new(43211234);
}
Expand All @@ -705,26 +704,65 @@ macro_rules! impl_runtime_apis_plus_common {
}

fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
// Relay/native token can be teleported between AH and Relay.
Some((
Asset {
fun: Fungible(ExistentialDeposit::get()),
id: AssetId(Parent.into())
},
Parent.into(),
))
None
}

fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
use xcm_config::SelfReserve;

ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
RandomParaId::get().into()
);

Some((
Asset {
fun: Fungible(ExistentialDeposit::get()),
id: AssetId(Parent.into())
fun: Fungible(<Runtime as pallet_balances::Config>::ExistentialDeposit::get()),
id: AssetId(SelfReserve::get().into())
},
// AH can reserve transfer native token to some random parachain.
ParentThen(Parachain(RandomParaId::get().into()).into()).into(),
))
}

fn set_up_complex_asset_transfer(
) -> Option<(XcmAssets, u32, Location, Box<dyn FnOnce()>)> {
use xcm_config::SelfReserve;

let destination: xcm::v4::Location = Parent.into();

let fee_amount: u128 = <Runtime as pallet_balances::Config>::ExistentialDeposit::get();
let fee_asset: Asset = (SelfReserve::get(), fee_amount).into();

// Give some multiple of transferred amount
let balance = fee_amount * 1000;
let who = frame_benchmarking::whitelisted_caller();
let _ =
<Balances as frame_support::traits::Currency<_>>::make_free_balance_be(&who, balance);

// verify initial balance
assert_eq!(Balances::free_balance(&who), balance);

// set up local asset
let asset_amount: u128 = 10u128;
let initial_asset_amount: u128 = asset_amount * 10;

let (asset_id, _, _) = pallet_assets::benchmarking::create_default_minted_asset::<
Runtime,
()
>(true, initial_asset_amount);
let transfer_asset: Asset = (SelfReserve::get(), asset_amount).into();

let assets: XcmAssets = vec![fee_asset.clone(), transfer_asset].into();
let fee_index: u32 = 0;

let verify: Box<dyn FnOnce()> = Box::new(move || {
// verify balance after transfer, decreased by
// transferred amount (and delivery fees)
assert!(Balances::free_balance(&who) <= balance - fee_amount);
});

Some((assets, fee_index, destination, verify))
}
}

impl pallet_xcm_benchmarks::Config for Runtime {
Expand Down
5 changes: 4 additions & 1 deletion runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ impl pallet_balances::Config for Runtime {
/// The ubiquitous event type.
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
#[cfg(not(feature = "runtime-benchmarks"))]
type ExistentialDeposit = ConstU128<0>;
#[cfg(feature = "runtime-benchmarks")]
type ExistentialDeposit = ConstU128<1>;
type AccountStore = System;
type FreezeIdentifier = ();
type MaxFreezes = ConstU32<0>;
Expand Down Expand Up @@ -1468,7 +1471,7 @@ mod benches {
[pallet_proxy, Proxy]
[pallet_identity, Identity]
[cumulus_pallet_xcmp_queue, XcmpQueue]
[pallet_xcm, PalletXcmExtrinsiscsBenchmark::<Runtime>]
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
[pallet_asset_manager, AssetManager]
[pallet_xcm_transactor, XcmTransactor]
[pallet_moonbeam_orbiters, MoonbeamOrbiters]
Expand Down
6 changes: 5 additions & 1 deletion runtime/moonbase/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ pub use moonbase_runtime::{
use nimbus_primitives::{NimbusId, NIMBUS_ENGINE_ID};
use polkadot_parachain::primitives::HeadData;
use sp_consensus_slots::Slot;
use sp_core::{Encode, H160};
use sp_core::{Encode, Get, H160};
use sp_runtime::{traits::Dispatchable, BuildStorage, Digest, DigestItem, Perbill, Percent};

use std::collections::BTreeMap;

use fp_rpc::ConvertTransaction;
use pallet_transaction_payment::Multiplier;

pub fn existential_deposit() -> u128 {
<Runtime as pallet_balances::Config>::ExistentialDeposit::get()
}

// A valid signed Alice transfer.
pub const VALID_ETH_TX: &str =
"02f86d8205018085174876e80085e8d4a5100082520894f24ff3a9cf04c71dbc94d0b566f7a27b9456\
Expand Down
40 changes: 27 additions & 13 deletions runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ fn transfer_ed_0_substrate() {
ExtBuilder::default()
.with_balances(vec![
(AccountId::from(ALICE), (1 * UNIT) + (1 * WEI)),
(AccountId::from(BOB), 0),
(AccountId::from(BOB), existential_deposit()),
])
.build()
.execute_with(|| {
Expand Down Expand Up @@ -1755,7 +1755,7 @@ fn transfer_ed_0_evm() {
AccountId::from(ALICE),
((1 * UNIT) + (21_000 * BASE_FEE_GENISIS)) + (1 * WEI),
),
(AccountId::from(BOB), 0),
(AccountId::from(BOB), existential_deposit()),
])
.build()
.execute_with(|| {
Expand Down Expand Up @@ -1783,9 +1783,9 @@ fn refund_ed_0_evm() {
.with_balances(vec![
(
AccountId::from(ALICE),
((1 * UNIT) + (21_777 * BASE_FEE_GENISIS)),
((1 * UNIT) + (21_777 * BASE_FEE_GENISIS) + existential_deposit()),
),
(AccountId::from(BOB), 0),
(AccountId::from(BOB), existential_deposit()),
])
.build()
.execute_with(|| {
Expand All @@ -1805,7 +1805,7 @@ fn refund_ed_0_evm() {
// ALICE is refunded
assert_eq!(
Balances::free_balance(AccountId::from(ALICE)),
777 * BASE_FEE_GENISIS,
777 * BASE_FEE_GENISIS + existential_deposit(),
);
});
}
Expand Down Expand Up @@ -1847,10 +1847,17 @@ fn author_does_not_receive_priority_fee() {
#[test]
fn total_issuance_after_evm_transaction_with_priority_fee() {
ExtBuilder::default()
.with_balances(vec![(
AccountId::from(BOB),
(1 * UNIT) + (21_000 * (2 * BASE_FEE_GENISIS)),
)])
.with_balances(vec![
(
AccountId::from(BOB),
(1 * UNIT) + (21_000 * (2 * BASE_FEE_GENISIS) + existential_deposit()),
),
(AccountId::from(ALICE), existential_deposit()),
(
<pallet_treasury::TreasuryAccountId<Runtime> as sp_core::TypedGet>::get(),
existential_deposit(),
),
])
.build()
.execute_with(|| {
let issuance_before = <Runtime as pallet_evm::Config>::Currency::total_issuance();
Expand Down Expand Up @@ -1884,10 +1891,17 @@ fn total_issuance_after_evm_transaction_with_priority_fee() {
fn total_issuance_after_evm_transaction_without_priority_fee() {
use fp_evm::FeeCalculator;
ExtBuilder::default()
.with_balances(vec![(
AccountId::from(BOB),
(1 * UNIT) + (21_000 * (2 * BASE_FEE_GENISIS)),
)])
.with_balances(vec![
(
AccountId::from(BOB),
(1 * UNIT) + (21_000 * (2 * BASE_FEE_GENISIS)),
),
(AccountId::from(ALICE), existential_deposit()),
(
<pallet_treasury::TreasuryAccountId<Runtime> as sp_core::TypedGet>::get(),
existential_deposit(),
),
])
.build()
.execute_with(|| {
let issuance_before = <Runtime as pallet_evm::Config>::Currency::total_issuance();
Expand Down
5 changes: 4 additions & 1 deletion runtime/moonbase/tests/runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ fn ethereum_runtime_rpc_api_chain_id() {
#[test]
fn ethereum_runtime_rpc_api_account_basic() {
ExtBuilder::default()
.with_balances(vec![(AccountId::from(ALICE), 2_000 * UNIT)])
.with_balances(vec![(
AccountId::from(ALICE),
2_000 * UNIT + existential_deposit(),
)])
.build()
.execute_with(|| {
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ mod benches {
[pallet_proxy, Proxy]
[pallet_identity, Identity]
[cumulus_pallet_xcmp_queue, XcmpQueue]
[pallet_xcm, PalletXcmExtrinsiscsBenchmark::<Runtime>]
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
[pallet_asset_manager, AssetManager]
[pallet_xcm_transactor, XcmTransactor]
[pallet_moonbeam_orbiters, MoonbeamOrbiters]
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ mod benches {
[pallet_proxy, Proxy]
[pallet_identity, Identity]
[cumulus_pallet_xcmp_queue, XcmpQueue]
[pallet_xcm, PalletXcmExtrinsiscsBenchmark::<Runtime>]
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
[pallet_asset_manager, AssetManager]
[pallet_xcm_transactor, XcmTransactor]
[pallet_moonbeam_orbiters, MoonbeamOrbiters]
Expand Down
Loading