mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 10:01:02 +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:
@@ -58,8 +58,6 @@ runtime-parachains = { package = "polkadot-runtime-parachains", path = "../parac
|
||||
slot-range-helper = { path = "slot_range_helper", default-features = false }
|
||||
xcm = { package = "staging-xcm", path = "../../xcm", default-features = false }
|
||||
xcm-executor = { package = "staging-xcm-executor", path = "../../xcm/xcm-executor", default-features = false, optional = true }
|
||||
|
||||
pallet-xcm-benchmarks = { path = "../../xcm/pallet-xcm-benchmarks", default-features = false, optional = true }
|
||||
xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
@@ -99,7 +97,6 @@ std = [
|
||||
"pallet-transaction-payment/std",
|
||||
"pallet-treasury/std",
|
||||
"pallet-vesting/std",
|
||||
"pallet-xcm-benchmarks/std",
|
||||
"parity-scale-codec/std",
|
||||
"primitives/std",
|
||||
"runtime-parachains/std",
|
||||
@@ -137,7 +134,6 @@ runtime-benchmarks = [
|
||||
"pallet-timestamp/runtime-benchmarks",
|
||||
"pallet-treasury/runtime-benchmarks",
|
||||
"pallet-vesting/runtime-benchmarks",
|
||||
"pallet-xcm-benchmarks/runtime-benchmarks",
|
||||
"primitives/runtime-benchmarks",
|
||||
"runtime-parachains/runtime-benchmarks",
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
|
||||
@@ -136,7 +136,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Implementation of `pallet_xcm_benchmarks::EnsureDelivery` which helps to ensure delivery to the
|
||||
/// Implementation of `xcm_builder::EnsureDelivery` which helps to ensure delivery to the
|
||||
/// `ParaId` parachain (sibling or child). Deposits existential deposit for origin (if needed).
|
||||
/// Deposits estimated fee to the origin account (if needed).
|
||||
/// Allows to trigger additional logic for specific `ParaId` (e.g. open HRMP channel) (if neeeded).
|
||||
@@ -164,7 +164,7 @@ impl<
|
||||
PriceForDelivery: PriceForMessageDelivery<Id = ParaId>,
|
||||
Parachain: Get<ParaId>,
|
||||
ToParachainHelper: EnsureForParachain,
|
||||
> pallet_xcm_benchmarks::EnsureDelivery
|
||||
> xcm_builder::EnsureDelivery
|
||||
for ToParachainDeliveryHelper<
|
||||
XcmConfig,
|
||||
ExistentialDeposit,
|
||||
@@ -175,7 +175,7 @@ impl<
|
||||
{
|
||||
fn ensure_successful_delivery(
|
||||
origin_ref: &Location,
|
||||
_dest: &Location,
|
||||
dest: &Location,
|
||||
fee_reason: xcm_executor::traits::FeeReason,
|
||||
) -> (Option<xcm_executor::FeesMode>, Option<Assets>) {
|
||||
use xcm_executor::{
|
||||
@@ -183,6 +183,15 @@ impl<
|
||||
FeesMode,
|
||||
};
|
||||
|
||||
// check if the destination matches the expected `Parachain`.
|
||||
if let Some(Parachain(para_id)) = dest.first_interior() {
|
||||
if ParaId::from(*para_id) != Parachain::get().into() {
|
||||
return (None, None)
|
||||
}
|
||||
} else {
|
||||
return (None, None)
|
||||
}
|
||||
|
||||
let mut fees_mode = None;
|
||||
if !XcmConfig::FeeManager::is_waived(Some(origin_ref), fee_reason) {
|
||||
// if not waived, we need to set up accounts for paying and receiving fees
|
||||
|
||||
@@ -2272,12 +2272,30 @@ sp_api::impl_runtime_apis! {
|
||||
TokenLocation::get(),
|
||||
ExistentialDeposit::get()
|
||||
).into());
|
||||
pub ToParachain: ParaId = rococo_runtime_constants::system_parachain::ASSET_HUB_ID.into();
|
||||
pub AssetHubParaId: ParaId = rococo_runtime_constants::system_parachain::ASSET_HUB_ID.into();
|
||||
pub const RandomParaId: ParaId = ParaId::new(43211234);
|
||||
}
|
||||
|
||||
impl frame_system_benchmarking::Config for Runtime {}
|
||||
impl frame_benchmarking::baseline::Config for Runtime {}
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
type DeliveryHelper = (
|
||||
runtime_common::xcm_sender::ToParachainDeliveryHelper<
|
||||
XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForChildParachainDelivery,
|
||||
AssetHubParaId,
|
||||
(),
|
||||
>,
|
||||
runtime_common::xcm_sender::ToParachainDeliveryHelper<
|
||||
XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForChildParachainDelivery,
|
||||
RandomParaId,
|
||||
(),
|
||||
>
|
||||
);
|
||||
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(crate::xcm_config::AssetHub::get())
|
||||
}
|
||||
@@ -2286,7 +2304,7 @@ sp_api::impl_runtime_apis! {
|
||||
// Relay/native token can be teleported to/from AH.
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Here.into())
|
||||
},
|
||||
crate::xcm_config::AssetHub::get(),
|
||||
@@ -2297,10 +2315,10 @@ sp_api::impl_runtime_apis! {
|
||||
// Relay can reserve transfer native token to some random parachain.
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Here.into())
|
||||
},
|
||||
Parachain(43211234).into(),
|
||||
Parachain(RandomParaId::get().into()).into(),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -2325,7 +2343,7 @@ sp_api::impl_runtime_apis! {
|
||||
XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForChildParachainDelivery,
|
||||
ToParachain,
|
||||
AssetHubParaId,
|
||||
(),
|
||||
>;
|
||||
fn valid_destination() -> Result<Location, BenchmarkError> {
|
||||
|
||||
@@ -2344,7 +2344,36 @@ sp_api::impl_runtime_apis! {
|
||||
impl pallet_session_benchmarking::Config for Runtime {}
|
||||
impl pallet_offences_benchmarking::Config for Runtime {}
|
||||
impl pallet_election_provider_support_benchmarking::Config for Runtime {}
|
||||
|
||||
use xcm_config::{AssetHub, TokenLocation};
|
||||
|
||||
parameter_types! {
|
||||
pub ExistentialDepositAsset: Option<Asset> = Some((
|
||||
TokenLocation::get(),
|
||||
ExistentialDeposit::get()
|
||||
).into());
|
||||
pub AssetHubParaId: ParaId = westend_runtime_constants::system_parachain::ASSET_HUB_ID.into();
|
||||
pub const RandomParaId: ParaId = ParaId::new(43211234);
|
||||
}
|
||||
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
type DeliveryHelper = (
|
||||
runtime_common::xcm_sender::ToParachainDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForChildParachainDelivery,
|
||||
AssetHubParaId,
|
||||
(),
|
||||
>,
|
||||
runtime_common::xcm_sender::ToParachainDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForChildParachainDelivery,
|
||||
RandomParaId,
|
||||
(),
|
||||
>
|
||||
);
|
||||
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(crate::xcm_config::AssetHub::get())
|
||||
}
|
||||
@@ -2352,7 +2381,7 @@ sp_api::impl_runtime_apis! {
|
||||
fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
// Relay/native token can be teleported to/from AH.
|
||||
Some((
|
||||
Asset { fun: Fungible(EXISTENTIAL_DEPOSIT), id: AssetId(Here.into()) },
|
||||
Asset { fun: Fungible(ExistentialDeposit::get()), id: AssetId(Here.into()) },
|
||||
crate::xcm_config::AssetHub::get(),
|
||||
))
|
||||
}
|
||||
@@ -2361,10 +2390,10 @@ sp_api::impl_runtime_apis! {
|
||||
// Relay can reserve transfer native token to some random parachain.
|
||||
Some((
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
fun: Fungible(ExistentialDeposit::get()),
|
||||
id: AssetId(Here.into())
|
||||
},
|
||||
crate::Junction::Parachain(43211234).into(),
|
||||
crate::Junction::Parachain(RandomParaId::get().into()).into(),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -2391,15 +2420,6 @@ sp_api::impl_runtime_apis! {
|
||||
AssetId, Fungibility::*, InteriorLocation, Junction, Junctions::*,
|
||||
Asset, Assets, Location, NetworkId, Response,
|
||||
};
|
||||
use xcm_config::{AssetHub, TokenLocation};
|
||||
|
||||
parameter_types! {
|
||||
pub ExistentialDepositAsset: Option<Asset> = Some((
|
||||
TokenLocation::get(),
|
||||
ExistentialDeposit::get()
|
||||
).into());
|
||||
pub ToParachain: ParaId = westend_runtime_constants::system_parachain::ASSET_HUB_ID.into();
|
||||
}
|
||||
|
||||
impl pallet_xcm_benchmarks::Config for Runtime {
|
||||
type XcmConfig = xcm_config::XcmConfig;
|
||||
@@ -2408,7 +2428,7 @@ sp_api::impl_runtime_apis! {
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForChildParachainDelivery,
|
||||
ToParachain,
|
||||
AssetHubParaId,
|
||||
(),
|
||||
>;
|
||||
fn valid_destination() -> Result<Location, BenchmarkError> {
|
||||
|
||||
@@ -262,7 +262,7 @@ pub type LocalPalletOriginToLocation = (
|
||||
StakingAdminToPlurality,
|
||||
// FellowshipAdmin origin to be used in XCM as a corresponding Plurality `Location` value.
|
||||
FellowshipAdminToPlurality,
|
||||
// `Treasurer` origin to be used in XCM as a corresponding Plurality `MultiLocation` value.
|
||||
// `Treasurer` origin to be used in XCM as a corresponding Plurality `Location` value.
|
||||
TreasurerToPlurality,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user