From 9fbe24472f0bec1c93834b19f81056798b9fea98 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Wed, 15 Jan 2025 14:24:26 +1300 Subject: [PATCH] update XCM usages --- polkadot/xcm/src/v6/mod.rs | 1 + polkadot/xcm/xcm-builder/src/barriers.rs | 50 +++++++++---------- polkadot/xcm/xcm-builder/src/matcher.rs | 4 +- polkadot/xcm/xcm-builder/src/pay.rs | 18 +++---- .../xcm/xcm-builder/src/universal_exports.rs | 18 +++---- polkadot/xcm/xcm-builder/src/weight.rs | 4 +- 6 files changed, 48 insertions(+), 47 deletions(-) diff --git a/polkadot/xcm/src/v6/mod.rs b/polkadot/xcm/src/v6/mod.rs index b8a6352f1acc..dc6aabf9f681 100644 --- a/polkadot/xcm/src/v6/mod.rs +++ b/polkadot/xcm/src/v6/mod.rs @@ -69,6 +69,7 @@ pub mod prelude { XcmContext, XcmError, XcmHash, XcmResult, XcmWeightInfo, }; } + pub use crate::traits::{ExecuteXcm, SendXcm, SendResult, validate_send, send_xcm}; pub use super::instructions::*; pub use super::{Instruction, Xcm}; pub use contents::*; diff --git a/polkadot/xcm/xcm-builder/src/barriers.rs b/polkadot/xcm/xcm-builder/src/barriers.rs index adba9a3ef79f..bc8d57e7bf80 100644 --- a/polkadot/xcm/xcm-builder/src/barriers.rs +++ b/polkadot/xcm/xcm-builder/src/barriers.rs @@ -82,10 +82,10 @@ impl> ShouldExecute for AllowTopLevelPaidExecutionFrom instructions[..end] .matcher() .match_next_inst(|inst| match inst { - WithdrawAsset(ref assets) | - ReceiveTeleportedAsset(ref assets) | - ReserveAssetDeposited(ref assets) | - ClaimAsset { ref assets, .. } => + Instruction::WithdrawAsset(WithdrawAsset(ref assets)) | + Instruction::ReceiveTeleportedAsset(ReceiveTeleportedAsset(ref assets)) | + Instruction::ReserveAssetDeposited(ReserveAssetDeposited(ref assets)) | + Instruction::ClaimAsset(ClaimAsset { ref assets, .. }) => if assets.len() <= MAX_ASSETS_FOR_BUY_EXECUTION { Ok(()) } else { @@ -94,22 +94,22 @@ impl> ShouldExecute for AllowTopLevelPaidExecutionFrom _ => Err(ProcessMessageError::BadFormat), })? .skip_inst_while(|inst| { - matches!(inst, ClearOrigin | AliasOrigin(..)) || - matches!(inst, DescendOrigin(child) if child != &Here) || - matches!(inst, SetHints { .. }) + matches!(inst, Instruction::ClearOrigin(_) | Instruction::AliasOrigin(..)) || + matches!(inst, Instruction::DescendOrigin(DescendOrigin(child)) if child != &Here) || + matches!(inst, Instruction::SetHints { .. }) })? .match_next_inst(|inst| match inst { - BuyExecution { weight_limit: Limited(ref mut weight), .. } + Instruction::BuyExecution(BuyExecution { weight_limit: Limited(ref mut weight), .. }) if weight.all_gte(max_weight) => { *weight = max_weight; Ok(()) }, - BuyExecution { ref mut weight_limit, .. } if weight_limit == &Unlimited => { + Instruction::BuyExecution(BuyExecution { ref mut weight_limit, .. }) if weight_limit == &Unlimited => { *weight_limit = Limited(max_weight); Ok(()) }, - PayFees { .. } => Ok(()), + Instruction::PayFees(_) => Ok(()), _ => Err(ProcessMessageError::Overweight(max_weight)), })?; Ok(()) @@ -189,14 +189,14 @@ impl, MaxPref |_| skipped.get() < MaxPrefixes::get() as usize, |inst| { match inst { - UniversalOrigin(new_global) => { + Instruction::UniversalOrigin(UniversalOrigin(new_global)) => { // Note the origin is *relative to local consensus*! So we need to escape // local consensus with the `parents` before diving in into the // `universal_location`. actual_origin = Junctions::from([*new_global]).relative_to(&LocalUniversal::get()); }, - DescendOrigin(j) => { + Instruction::DescendOrigin(DescendOrigin(j)) => { let Ok(_) = actual_origin.append_with(j.clone()) else { return Err(ProcessMessageError::Unsupported) }; @@ -235,7 +235,7 @@ impl ShouldExecute for TrailingSetTopicAsId> ShouldExecute for AllowExplicitUnpaidExecutionFrom Ok(()), - UnpaidExecution { weight_limit: Unlimited, .. } => Ok(()), + Instruction::UnpaidExecution(UnpaidExecution { weight_limit: Limited(m), .. }) if m.all_gte(max_weight) => Ok(()), + Instruction::UnpaidExecution(UnpaidExecution { weight_limit: Unlimited, .. }) => Ok(()), _ => Err(ProcessMessageError::Overweight(max_weight)), })?; Ok(()) @@ -369,7 +369,7 @@ impl ShouldExecute for AllowKnownQueryResponses Ok(()), _ => Err(ProcessMessageError::BadFormat), @@ -398,7 +398,7 @@ impl> ShouldExecute for AllowSubscriptionsFrom { .matcher() .assert_remaining_insts(1)? .match_next_inst(|inst| match inst { - SubscribeVersion { .. } | UnsubscribeVersion => Ok(()), + Instruction::SubscribeVersion(_) | Instruction::UnsubscribeVersion(_) => Ok(()), _ => Err(ProcessMessageError::BadFormat), })?; Ok(()) @@ -431,9 +431,9 @@ impl ShouldExecute for AllowHrmpNotificationsFromRelayChain { .matcher() .assert_remaining_insts(1)? .match_next_inst(|inst| match inst { - HrmpNewChannelOpenRequest { .. } | - HrmpChannelAccepted { .. } | - HrmpChannelClosing { .. } => Ok(()), + Instruction::HrmpNewChannelOpenRequest(_) | + Instruction::HrmpChannelAccepted(_) | + Instruction::HrmpChannelClosing(_) => Ok(()), _ => Err(ProcessMessageError::BadFormat), })?; Ok(()) @@ -475,18 +475,18 @@ impl ShouldExecute for DenyReserveTransferToRelayChain { message.matcher().match_next_inst_while( |_| true, |inst| match inst { - InitiateReserveWithdraw { + Instruction::InitiateReserveWithdraw(InitiateReserveWithdraw { reserve: Location { parents: 1, interior: Here }, .. - } | - DepositReserveAsset { dest: Location { parents: 1, interior: Here }, .. } | - TransferReserveAsset { dest: Location { parents: 1, interior: Here }, .. } => { + }) | + Instruction::DepositReserveAsset(DepositReserveAsset { dest: Location { parents: 1, interior: Here }, .. }) | + Instruction::TransferReserveAsset(TransferReserveAsset { dest: Location { parents: 1, interior: Here }, .. }) => { Err(ProcessMessageError::Unsupported) // Deny }, // An unexpected reserve transfer has arrived from the Relay Chain. Generally, // `IsReserve` should not allow this, but we just log it here. - ReserveAssetDeposited { .. } + Instruction::ReserveAssetDeposited(_) if matches!(origin, Location { parents: 1, interior: Here }) => { log::warn!( diff --git a/polkadot/xcm/xcm-builder/src/matcher.rs b/polkadot/xcm/xcm-builder/src/matcher.rs index ab515f180527..426349b252e3 100644 --- a/polkadot/xcm/xcm-builder/src/matcher.rs +++ b/polkadot/xcm/xcm-builder/src/matcher.rs @@ -116,13 +116,13 @@ pub trait MatchXcm { /// /// Implements `MatchXcm` to allow an iterator-like API to match against each `Instruction` /// contained within the slice, which facilitates the building of XCM barriers. -pub struct Matcher<'a, Call> { +pub struct Matcher<'a, Call: 'static> { pub(crate) xcm: &'a mut [Instruction], pub(crate) current_idx: usize, pub(crate) total_inst: usize, } -impl<'a, Call> MatchXcm for Matcher<'a, Call> { +impl<'a, Call: 'static> MatchXcm for Matcher<'a, Call> { type Error = ProcessMessageError; type Inst = Instruction; type Loc = Location; diff --git a/polkadot/xcm/xcm-builder/src/pay.rs b/polkadot/xcm/xcm-builder/src/pay.rs index 0093051290b7..1cf5e970c190 100644 --- a/polkadot/xcm/xcm-builder/src/pay.rs +++ b/polkadot/xcm/xcm-builder/src/pay.rs @@ -23,7 +23,7 @@ use frame_support::traits::{ Get, }; use sp_runtime::traits::TryConvert; -use xcm::{opaque::lts::Weight, prelude::*}; +use xcm::{opaque::lts::Weight, prelude::*, traits::IntoInstruction}; use xcm_executor::traits::{QueryHandler, QueryResponseStatus}; /// Implementation of the `frame_support::traits::tokens::Pay` trait, to allow @@ -108,21 +108,21 @@ impl< let query_id = Querier::new_query(asset_location.clone(), Timeout::get(), Interior::get()); - let message = Xcm(vec![ - DescendOrigin(Interior::get()), - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - SetAppendix(Xcm(vec![ - SetFeesMode { jit_withdraw: true }, + let message = Xcm::new(vec![ + DescendOrigin(Interior::get()).into(), + UnpaidExecution { weight_limit: Unlimited, check_origin: None }.into(), + SetAppendix(Xcm::new(vec![ + SetFeesMode { jit_withdraw: true }.into(), ReportError(QueryResponseInfo { destination, query_id, max_weight: Weight::zero(), - }), - ])), + }).into(), + ])).into_instruction(), TransferAsset { beneficiary, assets: vec![Asset { id: asset_id, fun: Fungibility::Fungible(amount) }].into(), - }, + }.into(), ]); let (ticket, _) = Router::validate(&mut Some(asset_location), &mut Some(message))?; diff --git a/polkadot/xcm/xcm-builder/src/universal_exports.rs b/polkadot/xcm/xcm-builder/src/universal_exports.rs index 6b3c3adf737d..3d6a78874f2a 100644 --- a/polkadot/xcm/xcm-builder/src/universal_exports.rs +++ b/polkadot/xcm/xcm-builder/src/universal_exports.rs @@ -242,16 +242,16 @@ impl(bridge, message).inspect_err(|err| { if let NotApplicable = err { @@ -328,21 +328,21 @@ impl(PhantomData<(W, C, M)>); impl WeightBounds for WeightInfoBounds where W: XcmWeightInfo, - C: Decode + GetDispatchInfo, + C: Decode + GetDispatchInfo + 'static, M: Get, Instruction: xcm::latest::GetWeight, { @@ -94,7 +94,7 @@ where impl WeightInfoBounds where W: XcmWeightInfo, - C: Decode + GetDispatchInfo, + C: Decode + GetDispatchInfo + 'static, M: Get, Instruction: xcm::latest::GetWeight, {