Skip to content

Commit

Permalink
XCM: Deprecate old functions (#1645)
Browse files Browse the repository at this point in the history
Two old functions should be deprecated and have their code altered in
line with capabilities of XCMv2 and above.

This means we can use the proper `Unlimited` form of weight limit rather
than guessing weight from the local chain.
  • Loading branch information
gavofyork authored Sep 20, 2023
1 parent 6f00edb commit e7d29bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 40 deletions.
48 changes: 10 additions & 38 deletions polkadot/xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,8 @@ pub mod pallet {

/// Teleport some assets from the local chain to some destination chain.
///
/// **This function is deprecated: Use `limited_teleport_assets` instead.**
///
/// Fee payment on the destination side is made from the asset in the `assets` vector of
/// index `fee_asset_item`. The weight limit for fees is not provided and thus is unlimited,
/// with all fees taken as needed from the asset.
Expand Down Expand Up @@ -830,12 +832,14 @@ pub mod pallet {
assets: Box<VersionedMultiAssets>,
fee_asset_item: u32,
) -> DispatchResult {
Self::do_teleport_assets(origin, dest, beneficiary, assets, fee_asset_item, None)
Self::do_teleport_assets(origin, dest, beneficiary, assets, fee_asset_item, Unlimited)
}

/// Transfer some assets from the local chain to the sovereign account of a destination
/// chain and forward a notification XCM.
///
/// **This function is deprecated: Use `limited_reserve_transfer_assets` instead.**
///
/// Fee payment on the destination side is made from the asset in the `assets` vector of
/// index `fee_asset_item`. The weight limit for fees is not provided and thus is unlimited,
/// with all fees taken as needed from the asset.
Expand Down Expand Up @@ -879,7 +883,7 @@ pub mod pallet {
beneficiary,
assets,
fee_asset_item,
None,
Unlimited,
)
}

Expand Down Expand Up @@ -1055,7 +1059,7 @@ pub mod pallet {
beneficiary,
assets,
fee_asset_item,
Some(weight_limit),
weight_limit,
)
}

Expand Down Expand Up @@ -1109,7 +1113,7 @@ pub mod pallet {
beneficiary,
assets,
fee_asset_item,
Some(weight_limit),
weight_limit,
)
}

Expand Down Expand Up @@ -1197,7 +1201,7 @@ impl<T: Config> Pallet<T> {
beneficiary: Box<VersionedMultiLocation>,
assets: Box<VersionedMultiAssets>,
fee_asset_item: u32,
maybe_weight_limit: Option<WeightLimit>,
weight_limit: WeightLimit,
) -> DispatchResult {
let origin_location = T::ExecuteXcmOrigin::ensure_origin(origin)?;
let dest = (*dest).try_into().map_err(|()| Error::<T>::BadVersion)?;
Expand All @@ -1218,22 +1222,6 @@ impl<T: Config> Pallet<T> {
.map_err(|_| Error::<T>::CannotReanchor)?;
let max_assets = assets.len() as u32;
let assets: MultiAssets = assets.into();
let weight_limit = match maybe_weight_limit {
Some(weight_limit) => weight_limit,
None => {
let fees = fees.clone();
let mut remote_message = Xcm(vec![
ReserveAssetDeposited(assets.clone()),
ClearOrigin,
BuyExecution { fees, weight_limit: Limited(Weight::zero()) },
DepositAsset { assets: Wild(AllCounted(max_assets)), beneficiary },
]);
// use local weight for remote message and hope for the best.
let remote_weight = T::Weigher::weight(&mut remote_message)
.map_err(|()| Error::<T>::UnweighableMessage)?;
Limited(remote_weight)
},
};
let xcm = Xcm(vec![
BuyExecution { fees, weight_limit },
DepositAsset { assets: Wild(AllCounted(max_assets)), beneficiary },
Expand All @@ -1257,7 +1245,7 @@ impl<T: Config> Pallet<T> {
beneficiary: Box<VersionedMultiLocation>,
assets: Box<VersionedMultiAssets>,
fee_asset_item: u32,
maybe_weight_limit: Option<WeightLimit>,
weight_limit: WeightLimit,
) -> DispatchResult {
let origin_location = T::ExecuteXcmOrigin::ensure_origin(origin)?;
let dest = (*dest).try_into().map_err(|()| Error::<T>::BadVersion)?;
Expand All @@ -1278,22 +1266,6 @@ impl<T: Config> Pallet<T> {
.map_err(|_| Error::<T>::CannotReanchor)?;
let max_assets = assets.len() as u32;
let assets: MultiAssets = assets.into();
let weight_limit = match maybe_weight_limit {
Some(weight_limit) => weight_limit,
None => {
let fees = fees.clone();
let mut remote_message = Xcm(vec![
ReceiveTeleportedAsset(assets.clone()),
ClearOrigin,
BuyExecution { fees, weight_limit: Limited(Weight::zero()) },
DepositAsset { assets: Wild(AllCounted(max_assets)), beneficiary },
]);
// use local weight for remote message and hope for the best.
let remote_weight = T::Weigher::weight(&mut remote_message)
.map_err(|()| Error::<T>::UnweighableMessage)?;
Limited(remote_weight)
},
};
let xcm = Xcm(vec![
BuyExecution { fees, weight_limit },
DepositAsset { assets: Wild(AllCounted(max_assets)), beneficiary },
Expand Down
4 changes: 2 additions & 2 deletions polkadot/xcm/pallet-xcm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ fn teleport_assets_works() {
Xcm(vec![
ReceiveTeleportedAsset((Here, SEND_AMOUNT).into()),
ClearOrigin,
buy_limited_execution((Here, SEND_AMOUNT), Weight::from_parts(4000, 4000)),
buy_execution((Here, SEND_AMOUNT)),
DepositAsset { assets: AllCounted(1).into(), beneficiary: dest },
]),
)]
Expand Down Expand Up @@ -508,7 +508,7 @@ fn reserve_transfer_assets_works() {
Xcm(vec![
ReserveAssetDeposited((Parent, SEND_AMOUNT).into()),
ClearOrigin,
buy_limited_execution((Parent, SEND_AMOUNT), Weight::from_parts(4000, 4000)),
buy_execution((Parent, SEND_AMOUNT)),
DepositAsset { assets: AllCounted(1).into(), beneficiary: dest },
]),
)]
Expand Down

0 comments on commit e7d29bc

Please sign in to comment.