diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 978dba51ec69..d596769dd2e6 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -1323,7 +1323,7 @@ parameter_types! { /// individual routers. pub type XcmRouter = ( // Only one router so far - use DMP to communicate with child parachains. - xcm_sender::ChildParachainRouter, + xcm_sender::ChildParachainRouter, ); parameter_types! { diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index a7d1014f10c9..6d96591dc9ba 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -636,7 +636,7 @@ parameter_types! { /// individual routers. pub type XcmRouter = ( // Only one router so far - use DMP to communicate with child parachains. - xcm_sender::ChildParachainRouter, + xcm_sender::ChildParachainRouter, ); parameter_types! { diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index fef3560ddf64..55ef0c129c2a 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -958,7 +958,7 @@ type LocalOriginConverter = ( /// individual routers. pub type XcmRouter = ( // Only one router so far - use DMP to communicate with child parachains. - xcm_sender::ChildParachainRouter, + xcm_sender::ChildParachainRouter, ); parameter_types! { diff --git a/xcm/pallet-xcm/src/lib.rs b/xcm/pallet-xcm/src/lib.rs index 0252e22cf450..6456f9ee36b9 100644 --- a/xcm/pallet-xcm/src/lib.rs +++ b/xcm/pallet-xcm/src/lib.rs @@ -526,16 +526,21 @@ pub mod pallet { .map_err(|_| Error::::CannotReanchor)?; let max_assets = assets.len() as u32; let assets = assets.into(); + let mut remote_message = Xcm(vec![ + BuyExecution { fees, weight_limit: Limited(0) }, + DepositAsset { assets: Wild(All), 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::::UnweighableMessage)?; + if let Some(BuyExecution { weight_limit: Limited(ref mut limit), .. }) = + remote_message.0.get_mut(0) + { + *limit = remote_weight; + } let mut message = Xcm(vec![ WithdrawAsset(assets), - InitiateTeleport { - assets: Wild(All), - dest, - xcm: Xcm(vec![ - BuyExecution { fees, weight_limit: Unlimited }, - DepositAsset { assets: Wild(All), max_assets, beneficiary }, - ]), - }, + InitiateTeleport { assets: Wild(All), dest, xcm: remote_message.into() }, ]); let weight = T::Weigher::weight(&mut message).map_err(|()| Error::::UnweighableMessage)?; @@ -597,14 +602,20 @@ pub mod pallet { .map_err(|_| Error::::CannotReanchor)?; let max_assets = assets.len() as u32; let assets = assets.into(); - let mut message = Xcm(vec![TransferReserveAsset { - assets, - dest, - xcm: Xcm(vec![ - BuyExecution { fees, weight_limit: Unlimited }, - DepositAsset { assets: Wild(All), max_assets, beneficiary }, - ]), - }]); + let mut remote_message = Xcm(vec![ + BuyExecution { fees, weight_limit: Limited(0) }, + DepositAsset { assets: Wild(All), 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::::UnweighableMessage)?; + if let Some(BuyExecution { weight_limit: Limited(ref mut limit), .. }) = + remote_message.0.get_mut(0) + { + *limit = remote_weight; + } + let mut message = + Xcm(vec![TransferReserveAsset { assets, dest, xcm: remote_message.into() }]); let weight = T::Weigher::weight(&mut message).map_err(|()| Error::::UnweighableMessage)?; let outcome = diff --git a/xcm/pallet-xcm/src/mock.rs b/xcm/pallet-xcm/src/mock.rs index 7c5a835b7851..8b6174c5b722 100644 --- a/xcm/pallet-xcm/src/mock.rs +++ b/xcm/pallet-xcm/src/mock.rs @@ -310,6 +310,11 @@ pub(crate) fn buy_execution(fees: impl Into) -> Instruction { BuyExecution { fees: fees.into(), weight_limit: Unlimited } } +pub(crate) fn buy_limited_execution(fees: impl Into, weight: u64) -> Instruction { + use xcm::latest::prelude::*; + BuyExecution { fees: fees.into(), weight_limit: Limited(weight) } +} + pub(crate) fn new_test_ext_with_balances( balances: Vec<(AccountId, Balance)>, ) -> sp_io::TestExternalities { diff --git a/xcm/pallet-xcm/src/tests.rs b/xcm/pallet-xcm/src/tests.rs index 5b9a3a177a36..ba5459e2c890 100644 --- a/xcm/pallet-xcm/src/tests.rs +++ b/xcm/pallet-xcm/src/tests.rs @@ -218,14 +218,29 @@ fn teleport_assets_works() { new_test_ext_with_balances(balances).execute_with(|| { let weight = 2 * BaseXcmWeight::get(); assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE); + let dest: MultiLocation = AccountId32 { network: Any, id: BOB.into() }.into(); assert_ok!(XcmPallet::teleport_assets( Origin::signed(ALICE), Box::new(RelayLocation::get().into()), - Box::new(AccountId32 { network: Any, id: BOB.into() }.into().into()), + Box::new(dest.clone().into()), Box::new((Here, SEND_AMOUNT).into()), 0, )); assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE - SEND_AMOUNT); + assert_eq!( + sent_xcm(), + vec![( + RelayLocation::get().into(), + Xcm(vec![ + ReceiveTeleportedAsset((Here, SEND_AMOUNT).into()), + ClearOrigin, + buy_limited_execution((Here, SEND_AMOUNT), 2000), + DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest }, + ]), + )] + ); + let versioned_sent = VersionedXcm::from(sent_xcm().into_iter().next().unwrap().1); + let _check_v0_ok: xcm::v0::Xcm<()> = versioned_sent.try_into().unwrap(); assert_eq!( last_event(), Event::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight))) @@ -265,11 +280,13 @@ fn reserve_transfer_assets_works() { Xcm(vec![ ReserveAssetDeposited((Parent, SEND_AMOUNT).into()), ClearOrigin, - buy_execution((Parent, SEND_AMOUNT)), + buy_limited_execution((Parent, SEND_AMOUNT), 2000), DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest }, ]), )] ); + let versioned_sent = VersionedXcm::from(sent_xcm().into_iter().next().unwrap().1); + let _check_v0_ok: xcm::v0::Xcm<()> = versioned_sent.try_into().unwrap(); assert_eq!( last_event(), Event::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))