Skip to content
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

pallet-xcm: add new extrinsic for asset transfers using explicit XCM transfer types #3695

Merged
merged 37 commits into from
Apr 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
dda9308
pallet-xcm: deprecate unlimited_* weight extrinsics
acatangiu Mar 13, 2024
1db1cae
pallet-xcm: remove extrinsics guessed weight and rely on runtime benc…
acatangiu Mar 13, 2024
f5e1dfb
pallet-xcm: add new extrinsic for asset transfers using explicit reserve
acatangiu Mar 13, 2024
547eeee
add more trace logging to XCM transport
acatangiu Mar 13, 2024
c7ee1af
minor style fix
acatangiu Mar 13, 2024
ed77fde
integration-tests: add scenario for parachain sending asset over brid…
acatangiu Mar 13, 2024
a7a44c9
make penpal UniversalLocation configurable
acatangiu Mar 14, 2024
ffa6250
penpal: charge XCM delivery fees for accurate real-world testing
acatangiu Mar 22, 2024
4afba95
integration-tests: fix tests for penpal charging delivery fees
acatangiu Mar 22, 2024
210cdd2
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Mar 23, 2024
c918bea
fix test
acatangiu Mar 23, 2024
3db344b
add prdoc
acatangiu Mar 25, 2024
10d2c40
fix clippy
acatangiu Mar 25, 2024
5b48155
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Mar 27, 2024
dbe453d
add test for westend->rococo direction
acatangiu Mar 27, 2024
42e4041
nit
acatangiu Mar 27, 2024
e794df3
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Apr 1, 2024
81dc911
pallet-xcm: specify explicit transfer type
acatangiu Apr 3, 2024
e1dbf7a
add more tests
acatangiu Apr 3, 2024
ef83eab
fix prdoc
acatangiu Apr 4, 2024
a2b8708
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Apr 4, 2024
4250692
refactor tests
acatangiu Apr 4, 2024
888d403
even more tests
acatangiu Apr 4, 2024
1c86e6e
another test
acatangiu Apr 4, 2024
b82d0b9
add teleport test as well
acatangiu Apr 4, 2024
f4e88da
rename xt and update docs
acatangiu Apr 4, 2024
4f2381c
fix weights
acatangiu Apr 4, 2024
36af01f
add tests to westend
acatangiu Apr 4, 2024
bd9233a
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Apr 4, 2024
9c7bd39
remove leftover comment
acatangiu Apr 4, 2024
adf5128
Apply suggestions from code review
acatangiu Apr 11, 2024
1347f0b
fix logs
acatangiu Apr 11, 2024
e3acff2
fix api
acatangiu Apr 11, 2024
4a44194
Merge branch 'master' into transfer-using-explicit-reserve
acatangiu Apr 11, 2024
0d407eb
Update polkadot/xcm/pallet-xcm/src/lib.rs
acatangiu Apr 12, 2024
22093d0
".git/.scripts/commands/fmt/fmt.sh"
Apr 12, 2024
a673792
Merge branch 'master' into transfer-using-explicit-reserve
acatangiu Apr 12, 2024
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
Prev Previous commit
Next Next commit
pallet-xcm: remove extrinsics guessed weight and rely on runtime benc…
…hmarks instead
  • Loading branch information
acatangiu committed Mar 14, 2024
commit 1db1cae089338ee97936d4689649b11308befab3
114 changes: 3 additions & 111 deletions polkadot/xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,10 +898,9 @@ pub mod pallet {
}
}

#[pallet::call]
#[pallet::call(weight(<T as Config>::WeightInfo))]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::send())]
pub fn send(
origin: OriginFor<T>,
dest: Box<VersionedLocation>,
Expand Down Expand Up @@ -930,23 +929,6 @@ pub mod pallet {
/// - `fee_asset_item`: The index into `assets` of the item which should be used to pay
/// fees.
#[pallet::call_index(1)]
#[pallet::weight({
let maybe_assets: Result<Assets, ()> = (*assets.clone()).try_into();
let maybe_dest: Result<Location, ()> = (*dest.clone()).try_into();
match (maybe_assets, maybe_dest) {
(Ok(assets), Ok(dest)) => {
use sp_std::vec;
let count = assets.len() as u32;
let mut message = Xcm(vec![
WithdrawAsset(assets),
SetFeesMode { jit_withdraw: true },
InitiateTeleport { assets: Wild(AllCounted(count)), dest, xcm: Xcm(vec![]) },
]);
T::Weigher::weight(&mut message).map_or(Weight::MAX, |w| T::WeightInfo::teleport_assets().saturating_add(w))
}
_ => Weight::MAX,
}
})]
#[allow(deprecated)]
#[deprecated(
acatangiu marked this conversation as resolved.
Show resolved Hide resolved
note = "This extrinsic uses `WeightLimit::Unlimited`, please migrate to `limited_teleport_assets` or `transfer_assets`"
Expand Down Expand Up @@ -992,23 +974,6 @@ pub mod pallet {
/// - `fee_asset_item`: The index into `assets` of the item which should be used to pay
/// fees.
#[pallet::call_index(2)]
#[pallet::weight({
let maybe_assets: Result<Assets, ()> = (*assets.clone()).try_into();
let maybe_dest: Result<Location, ()> = (*dest.clone()).try_into();
match (maybe_assets, maybe_dest) {
(Ok(assets), Ok(dest)) => {
use sp_std::vec;
// heaviest version of locally executed XCM program: equivalent in weight to
// transfer assets to SA, reanchor them, extend XCM program, and send onward XCM
let mut message = Xcm(vec![
SetFeesMode { jit_withdraw: true },
TransferReserveAsset { assets, dest, xcm: Xcm(vec![]) }
]);
T::Weigher::weight(&mut message).map_or(Weight::MAX, |w| T::WeightInfo::reserve_transfer_assets().saturating_add(w))
}
_ => Weight::MAX,
}
})]
#[allow(deprecated)]
#[deprecated(
note = "This extrinsic uses `WeightLimit::Unlimited`, please migrate to `limited_reserve_transfer_assets` or `transfer_assets`"
Expand Down Expand Up @@ -1057,7 +1022,6 @@ pub mod pallet {
/// - `location`: The destination that is being described.
/// - `xcm_version`: The latest version of XCM that `location` supports.
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::force_xcm_version())]
pub fn force_xcm_version(
origin: OriginFor<T>,
location: Box<Location>,
Expand All @@ -1076,7 +1040,6 @@ pub mod pallet {
/// - `origin`: Must be an origin specified by AdminOrigin.
/// - `maybe_xcm_version`: The default XCM encoding version, or `None` to disable.
#[pallet::call_index(5)]
#[pallet::weight(T::WeightInfo::force_default_xcm_version())]
pub fn force_default_xcm_version(
origin: OriginFor<T>,
maybe_xcm_version: Option<XcmVersion>,
Expand All @@ -1091,7 +1054,6 @@ pub mod pallet {
/// - `origin`: Must be an origin specified by AdminOrigin.
/// - `location`: The location to which we should subscribe for XCM version notifications.
#[pallet::call_index(6)]
#[pallet::weight(T::WeightInfo::force_subscribe_version_notify())]
pub fn force_subscribe_version_notify(
origin: OriginFor<T>,
location: Box<VersionedLocation>,
Expand All @@ -1115,7 +1077,6 @@ pub mod pallet {
/// - `location`: The location to which we are currently subscribed for XCM version
/// notifications which we no longer desire.
#[pallet::call_index(7)]
#[pallet::weight(T::WeightInfo::force_unsubscribe_version_notify())]
pub fn force_unsubscribe_version_notify(
origin: OriginFor<T>,
location: Box<VersionedLocation>,
Expand Down Expand Up @@ -1163,23 +1124,7 @@ pub mod pallet {
/// fees.
/// - `weight_limit`: The remote-side weight limit, if any, for the XCM fee purchase.
#[pallet::call_index(8)]
#[pallet::weight({
let maybe_assets: Result<Assets, ()> = (*assets.clone()).try_into();
let maybe_dest: Result<Location, ()> = (*dest.clone()).try_into();
match (maybe_assets, maybe_dest) {
(Ok(assets), Ok(dest)) => {
use sp_std::vec;
// heaviest version of locally executed XCM program: equivalent in weight to
// transfer assets to SA, reanchor them, extend XCM program, and send onward XCM
let mut message = Xcm(vec![
SetFeesMode { jit_withdraw: true },
TransferReserveAsset { assets, dest, xcm: Xcm(vec![]) }
]);
T::Weigher::weight(&mut message).map_or(Weight::MAX, |w| T::WeightInfo::reserve_transfer_assets().saturating_add(w))
}
_ => Weight::MAX,
}
})]
#[pallet::weight(T::WeightInfo::reserve_transfer_assets())]
pub fn limited_reserve_transfer_assets(
origin: OriginFor<T>,
dest: Box<VersionedLocation>,
Expand Down Expand Up @@ -1217,23 +1162,7 @@ pub mod pallet {
/// fees.
/// - `weight_limit`: The remote-side weight limit, if any, for the XCM fee purchase.
#[pallet::call_index(9)]
#[pallet::weight({
let maybe_assets: Result<Assets, ()> = (*assets.clone()).try_into();
let maybe_dest: Result<Location, ()> = (*dest.clone()).try_into();
match (maybe_assets, maybe_dest) {
(Ok(assets), Ok(dest)) => {
use sp_std::vec;
let count = assets.len() as u32;
let mut message = Xcm(vec![
WithdrawAsset(assets),
SetFeesMode { jit_withdraw: true },
InitiateTeleport { assets: Wild(AllCounted(count)), dest, xcm: Xcm(vec![]) },
]);
T::Weigher::weight(&mut message).map_or(Weight::MAX, |w| T::WeightInfo::teleport_assets().saturating_add(w))
}
_ => Weight::MAX,
}
})]
#[pallet::weight(T::WeightInfo::teleport_assets())]
pub fn limited_teleport_assets(
origin: OriginFor<T>,
dest: Box<VersionedLocation>,
Expand All @@ -1257,7 +1186,6 @@ pub mod pallet {
/// - `origin`: Must be an origin specified by AdminOrigin.
/// - `suspended`: `true` to suspend, `false` to resume.
#[pallet::call_index(10)]
#[pallet::weight(T::WeightInfo::force_suspension())]
pub fn force_suspension(origin: OriginFor<T>, suspended: bool) -> DispatchResult {
T::AdminOrigin::ensure_origin(origin)?;
XcmExecutionSuspended::<T>::set(suspended);
Expand Down Expand Up @@ -1298,26 +1226,6 @@ pub mod pallet {
/// fees.
/// - `weight_limit`: The remote-side weight limit, if any, for the XCM fee purchase.
#[pallet::call_index(11)]
#[pallet::weight({
let maybe_assets: Result<Assets, ()> = (*assets.clone()).try_into();
let maybe_dest: Result<Location, ()> = (*dest.clone()).try_into();
match (maybe_assets, maybe_dest) {
(Ok(assets), Ok(dest)) => {
use sp_std::vec;
// heaviest version of locally executed XCM program: equivalent in weight to withdrawing fees,
// burning them, transferring rest of assets to SA, reanchoring them, extending XCM program,
// and sending onward XCM
let mut message = Xcm(vec![
SetFeesMode { jit_withdraw: true },
WithdrawAsset(assets.clone()),
BurnAsset(assets.clone()),
TransferReserveAsset { assets, dest, xcm: Xcm(vec![]) }
]);
T::Weigher::weight(&mut message).map_or(Weight::MAX, |w| T::WeightInfo::transfer_assets().saturating_add(w))
}
_ => Weight::MAX,
}
})]
pub fn transfer_assets(
origin: OriginFor<T>,
dest: Box<VersionedLocation>,
Expand Down Expand Up @@ -1407,22 +1315,6 @@ pub mod pallet {
/// was the latest when they were trapped.
/// - `beneficiary`: The location/account where the claimed assets will be deposited.
#[pallet::call_index(12)]
#[pallet::weight({
let assets_version = assets.identify_version();
let maybe_assets: Result<Assets, ()> = (*assets.clone()).try_into();
let maybe_beneficiary: Result<Location, ()> = (*beneficiary.clone()).try_into();
match (maybe_assets, maybe_beneficiary) {
(Ok(assets), Ok(beneficiary)) => {
let ticket: Location = GeneralIndex(assets_version as u128).into();
let mut message = Xcm(vec![
ClaimAsset { assets: assets.clone(), ticket },
DepositAsset { assets: AllCounted(assets.len() as u32).into(), beneficiary },
]);
T::Weigher::weight(&mut message).map_or(Weight::MAX, |w| T::WeightInfo::claim_assets().saturating_add(w))
}
_ => Weight::MAX
}
})]
pub fn claim_assets(
origin: OriginFor<T>,
assets: Box<VersionedAssets>,
Expand Down