mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +00:00
[pallet-xcm] Adjust benchmarks (teleport_assets/reserve_transfer_assets) not relying on ED (#3464)
## Problem During the bumping of the `polkadot-fellows` repository to `polkadot-sdk@1.6.0`, I encountered a situation where the benchmarks `teleport_assets` and `reserve_transfer_assets` in AssetHubKusama started to fail. This issue arose due to a decreased ED balance for AssetHubs introduced [here](https://github.com/polkadot-fellows/runtimes/pull/158/files#diff-80668ff8e793b64f36a9a3ec512df5cbca4ad448c157a5d81abda1b15f35f1daR213), and also because of a [missing CI pipeline](https://github.com/polkadot-fellows/runtimes/issues/197) to check the benchmarks, which went unnoticed. These benchmarks expect the `caller` to have enough: 1. balance to transfer (BTT) 2. balance for paying delivery (BFPD). So the initial balance was calculated as `ED * 100`, which seems reasonable: ``` const ED_MULTIPLIER: u32 = 100; let balance = existential_deposit.saturating_mul(ED_MULTIPLIER.into());` ``` The problem arises when the price for delivery is 100 times higher than the existential deposit. In other words, when `ED * 100` does not cover `BTT` + `BFPD`. I check AHR/AHW/AHK/AHP and this problem has only AssetHubKusama ``` ED: 3333333 calculated price to parent delivery: 1031666634 (from xcm logs from the benchmark) --- 3333333 * 100 - BTT(3333333) - BFPD(1031666634) = −701666667 ``` which results in the error; ``` 2024-02-23 09:19:42 Unable to charge fee with error Module(ModuleError { index: 31, error: [17, 0, 0, 0], message: Some("FeesNotMet") }) Error: Input("Benchmark pallet_xcm::reserve_transfer_assets failed: FeesNotMet") ``` ## Solution The benchmarks `teleport_assets` and `reserve_transfer_assets` were fixed by removing `ED * 100` and replacing it with `DeliveryHelper` logic, which calculates the (almost real) price for delivery and sets it along with the existential deposit as the initial balance for the account used in the benchmark. ## TODO - [ ] patch for 1.6 - https://github.com/paritytech/polkadot-sdk/pull/3466 - [ ] patch for 1.7 - https://github.com/paritytech/polkadot-sdk/pull/3465 - [ ] patch for 1.8 - TODO: PR --------- Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
This commit is contained in:
@@ -1355,8 +1355,31 @@ impl_runtime_apis! {
|
||||
Config as XcmBridgeHubRouterConfig,
|
||||
};
|
||||
|
||||
parameter_types! {
|
||||
pub ExistentialDepositAsset: Option<Asset> = Some((
|
||||
TokenLocation::get(),
|
||||
ExistentialDeposit::get()
|
||||
).into());
|
||||
pub const RandomParaId: ParaId = ParaId::new(43211234);
|
||||
}
|
||||
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
type DeliveryHelper = (
|
||||
cumulus_primitives_utility::ToParentDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForParentDelivery,
|
||||
>,
|
||||
polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
PriceForSiblingParachainDelivery,
|
||||
RandomParaId,
|
||||
ParachainSystem,
|
||||
>
|
||||
);
|
||||
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
@@ -1365,7 +1388,7 @@ impl_runtime_apis! {
|
||||
// Relay/native token can be teleported between AH and Relay.
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
Parent.into(),
|
||||
@@ -1373,17 +1396,13 @@ impl_runtime_apis! {
|
||||
}
|
||||
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
// AH can reserve transfer native token to some random parachain.
|
||||
let random_para_id = 43211234;
|
||||
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
|
||||
random_para_id.into()
|
||||
);
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
ParentThen(Parachain(random_para_id).into()).into(),
|
||||
// AH can reserve transfer native token to some random parachain.
|
||||
ParentThen(Parachain(RandomParaId::get().into()).into()).into(),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -1469,13 +1488,6 @@ impl_runtime_apis! {
|
||||
use xcm_config::{TokenLocation, MaxAssetsIntoHolding};
|
||||
use pallet_xcm_benchmarks::asset_instance_from;
|
||||
|
||||
parameter_types! {
|
||||
pub ExistentialDepositAsset: Option<Asset> = Some((
|
||||
TokenLocation::get(),
|
||||
ExistentialDeposit::get()
|
||||
).into());
|
||||
}
|
||||
|
||||
impl pallet_xcm_benchmarks::Config for Runtime {
|
||||
type XcmConfig = xcm_config::XcmConfig;
|
||||
type AccountIdConverter = xcm_config::LocationToAccountId;
|
||||
|
||||
@@ -1427,8 +1427,31 @@ impl_runtime_apis! {
|
||||
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
|
||||
impl cumulus_pallet_session_benchmarking::Config for Runtime {}
|
||||
|
||||
parameter_types! {
|
||||
pub ExistentialDepositAsset: Option<Asset> = Some((
|
||||
WestendLocation::get(),
|
||||
ExistentialDeposit::get()
|
||||
).into());
|
||||
pub const RandomParaId: ParaId = ParaId::new(43211234);
|
||||
}
|
||||
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
type DeliveryHelper = (
|
||||
cumulus_primitives_utility::ToParentDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForParentDelivery,
|
||||
>,
|
||||
polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
PriceForSiblingParachainDelivery,
|
||||
RandomParaId,
|
||||
ParachainSystem,
|
||||
>
|
||||
);
|
||||
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
@@ -1437,7 +1460,7 @@ impl_runtime_apis! {
|
||||
// Relay/native token can be teleported between AH and Relay.
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
Parent.into(),
|
||||
@@ -1445,17 +1468,13 @@ impl_runtime_apis! {
|
||||
}
|
||||
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
// AH can reserve transfer native token to some random parachain.
|
||||
let random_para_id = 43211234;
|
||||
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
|
||||
random_para_id.into()
|
||||
);
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
ParentThen(Parachain(random_para_id).into()).into(),
|
||||
// AH can reserve transfer native token to some random parachain.
|
||||
ParentThen(Parachain(RandomParaId::get().into()).into()).into(),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -1546,13 +1565,6 @@ impl_runtime_apis! {
|
||||
use xcm_config::{MaxAssetsIntoHolding, WestendLocation};
|
||||
use pallet_xcm_benchmarks::asset_instance_from;
|
||||
|
||||
parameter_types! {
|
||||
pub ExistentialDepositAsset: Option<Asset> = Some((
|
||||
WestendLocation::get(),
|
||||
ExistentialDeposit::get()
|
||||
).into());
|
||||
}
|
||||
|
||||
impl pallet_xcm_benchmarks::Config for Runtime {
|
||||
type XcmConfig = xcm_config::XcmConfig;
|
||||
type AccountIdConverter = xcm_config::LocationToAccountId;
|
||||
|
||||
@@ -1109,6 +1109,12 @@ impl_runtime_apis! {
|
||||
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForParentDelivery,
|
||||
>;
|
||||
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
@@ -1117,7 +1123,7 @@ impl_runtime_apis! {
|
||||
// Relay/native token can be teleported between BH and Relay.
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
Parent.into(),
|
||||
|
||||
@@ -806,6 +806,12 @@ impl_runtime_apis! {
|
||||
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForParentDelivery,
|
||||
>;
|
||||
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
@@ -814,7 +820,7 @@ impl_runtime_apis! {
|
||||
// Relay/native token can be teleported between BH and Relay.
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
Parent.into(),
|
||||
|
||||
@@ -986,8 +986,21 @@ impl_runtime_apis! {
|
||||
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
|
||||
impl cumulus_pallet_session_benchmarking::Config for Runtime {}
|
||||
|
||||
parameter_types! {
|
||||
pub ExistentialDepositAsset: Option<Asset> = Some((
|
||||
xcm_config::WndLocation::get(),
|
||||
ExistentialDeposit::get()
|
||||
).into());
|
||||
}
|
||||
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForParentDelivery,
|
||||
>;
|
||||
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
@@ -996,7 +1009,7 @@ impl_runtime_apis! {
|
||||
// Relay/native token can be teleported between Collectives and Relay.
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Parent.into())
|
||||
}.into(),
|
||||
Parent.into(),
|
||||
|
||||
@@ -50,7 +50,7 @@ use frame_support::{
|
||||
dispatch::DispatchClass,
|
||||
genesis_builder_helper::{build_config, create_default_config},
|
||||
parameter_types,
|
||||
traits::{ConstBool, ConstU128, ConstU16, ConstU32, ConstU64, ConstU8},
|
||||
traits::{ConstBool, ConstU16, ConstU32, ConstU64, ConstU8},
|
||||
weights::{ConstantMultiplier, Weight},
|
||||
PalletId,
|
||||
};
|
||||
@@ -205,6 +205,10 @@ impl pallet_authorship::Config for Runtime {
|
||||
type EventHandler = (CollatorSelection,);
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
|
||||
}
|
||||
|
||||
impl pallet_balances::Config for Runtime {
|
||||
type MaxLocks = ConstU32<50>;
|
||||
/// The type for recording an account's balance.
|
||||
@@ -212,7 +216,7 @@ impl pallet_balances::Config for Runtime {
|
||||
/// The ubiquitous event type.
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type DustRemoval = ();
|
||||
type ExistentialDeposit = ConstU128<EXISTENTIAL_DEPOSIT>;
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = System;
|
||||
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
|
||||
type MaxReserves = ConstU32<50>;
|
||||
@@ -713,9 +717,22 @@ impl_runtime_apis! {
|
||||
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
|
||||
impl cumulus_pallet_session_benchmarking::Config for Runtime {}
|
||||
|
||||
parameter_types! {
|
||||
pub ExistentialDepositAsset: Option<Asset> = Some((
|
||||
xcm_config::RelayLocation::get(),
|
||||
ExistentialDeposit::get()
|
||||
).into());
|
||||
}
|
||||
|
||||
use xcm::latest::prelude::*;
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForParentDelivery,
|
||||
>;
|
||||
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
@@ -724,7 +741,7 @@ impl_runtime_apis! {
|
||||
// Relay/native token can be teleported between Contracts-System-Para and Relay.
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
Parent.into(),
|
||||
|
||||
@@ -715,6 +715,12 @@ impl_runtime_apis! {
|
||||
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForParentDelivery,
|
||||
>;
|
||||
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
@@ -723,7 +729,7 @@ impl_runtime_apis! {
|
||||
// Relay/native token can be teleported between AH and Relay.
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
Parent.into(),
|
||||
|
||||
@@ -706,6 +706,12 @@ impl_runtime_apis! {
|
||||
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForParentDelivery,
|
||||
>;
|
||||
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
@@ -714,7 +720,7 @@ impl_runtime_apis! {
|
||||
// Relay/native token can be teleported between AH and Relay.
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
Parent.into(),
|
||||
|
||||
@@ -686,6 +686,12 @@ impl_runtime_apis! {
|
||||
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForParentDelivery,
|
||||
>;
|
||||
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
@@ -694,7 +700,7 @@ impl_runtime_apis! {
|
||||
// Relay/native token can be teleported between People and Relay.
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
Parent.into(),
|
||||
|
||||
@@ -686,6 +686,12 @@ impl_runtime_apis! {
|
||||
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForParentDelivery,
|
||||
>;
|
||||
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
@@ -694,7 +700,7 @@ impl_runtime_apis! {
|
||||
// Relay/native token can be teleported between People and Relay.
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
Parent.into(),
|
||||
|
||||
Reference in New Issue
Block a user