[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:
Branislav Kontur
2024-02-26 09:12:28 +01:00
committed by GitHub
parent b9c792a4b8
commit 3d9439f646
28 changed files with 329 additions and 136 deletions
@@ -170,7 +170,7 @@ impl<
}
fn can_check_out(_dest: &Location, what: &Asset, _context: &XcmContext) -> Result {
log::trace!(target: "xcm::currency_adapter", "check_out dest: {:?}, what: {:?}", _dest, what);
log::trace!(target: "xcm::currency_adapter", "can_check_out dest: {:?}, what: {:?}", _dest, what);
let amount = Matcher::matches_fungible(what).ok_or(Error::AssetNotHandled)?;
match CheckedAccount::get() {
Some((checked_account, MintLocation::Local)) =>
@@ -151,7 +151,7 @@ impl<
fn can_check_out(_dest: &Location, what: &Asset, _context: &XcmContext) -> XcmResult {
log::trace!(
target: "xcm::fungible_adapter",
"check_out dest: {:?}, what: {:?}",
"can_check_out dest: {:?}, what: {:?}",
_dest,
what
);
@@ -235,7 +235,7 @@ impl<
fn can_check_out(_origin: &Location, what: &Asset, _context: &XcmContext) -> XcmResult {
log::trace!(
target: "xcm::fungibles_adapter",
"can_check_in origin: {:?}, what: {:?}",
"can_check_out origin: {:?}, what: {:?}",
_origin, what
);
// Check we handle this asset.
+1 -1
View File
@@ -117,7 +117,7 @@ mod process_xcm_message;
pub use process_xcm_message::ProcessXcmMessage;
mod routing;
pub use routing::{WithTopicSource, WithUniqueTopic};
pub use routing::{EnsureDelivery, WithTopicSource, WithUniqueTopic};
mod transactional;
pub use transactional::FrameTransactionalProcessor;
+35
View File
@@ -20,6 +20,7 @@ use frame_system::unique;
use parity_scale_codec::Encode;
use sp_std::{marker::PhantomData, result::Result};
use xcm::prelude::*;
use xcm_executor::{traits::FeeReason, FeesMode};
/// Wrapper router which, if the message does not already end with a `SetTopic` instruction,
/// appends one to the message filled with a universally unique ID. This ID is returned from a
@@ -104,3 +105,37 @@ impl<Inner: SendXcm, TopicSource: SourceTopic> SendXcm for WithTopicSource<Inner
Ok(unique_id)
}
}
/// Trait for a type which ensures all requirements for successful delivery with XCM transport
/// layers.
pub trait EnsureDelivery {
/// Prepare all requirements for successful `XcmSender: SendXcm` passing (accounts, balances,
/// channels ...). Returns:
/// - possible `FeesMode` which is expected to be set to executor
/// - possible `Assets` which are expected to be subsume to the Holding Register
fn ensure_successful_delivery(
origin_ref: &Location,
dest: &Location,
fee_reason: FeeReason,
) -> (Option<FeesMode>, Option<Assets>);
}
/// Tuple implementation for `EnsureDelivery`.
#[impl_trait_for_tuples::impl_for_tuples(30)]
impl EnsureDelivery for Tuple {
fn ensure_successful_delivery(
origin_ref: &Location,
dest: &Location,
fee_reason: FeeReason,
) -> (Option<FeesMode>, Option<Assets>) {
for_tuples!( #(
// If the implementation returns something, we're done; if not, let others try.
match Tuple::ensure_successful_delivery(origin_ref, dest, fee_reason.clone()) {
r @ (Some(_), Some(_)) | r @ (Some(_), None) | r @ (None, Some(_)) => return r,
(None, None) => (),
}
)* );
// doing nothing
(None, None)
}
}