Skip to content

Commit

Permalink
update XCM usages
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Jan 15, 2025
1 parent c3a575d commit 9fbe244
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 47 deletions.
1 change: 1 addition & 0 deletions polkadot/xcm/src/v6/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
50 changes: 25 additions & 25 deletions polkadot/xcm/xcm-builder/src/barriers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ impl<T: Contains<Location>> ShouldExecute for AllowTopLevelPaidExecutionFrom<T>
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 {
Expand All @@ -94,22 +94,22 @@ impl<T: Contains<Location>> ShouldExecute for AllowTopLevelPaidExecutionFrom<T>
_ => 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(())
Expand Down Expand Up @@ -189,14 +189,14 @@ impl<InnerBarrier: ShouldExecute, LocalUniversal: Get<InteriorLocation>, 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)
};
Expand Down Expand Up @@ -235,7 +235,7 @@ impl<InnerBarrier: ShouldExecute> ShouldExecute for TrailingSetTopicAsId<InnerBa
"TrailingSetTopicAsId origin: {:?}, instructions: {:?}, max_weight: {:?}, properties: {:?}",
origin, instructions, max_weight, properties,
);
let until = if let Some(SetTopic(t)) = instructions.last() {
let until = if let Some(Instruction::SetTopic(SetTopic(t))) = instructions.last() {
properties.message_id = Some(*t);
instructions.len() - 1
} else {
Expand Down Expand Up @@ -308,8 +308,8 @@ impl<T: Contains<Location>> ShouldExecute for AllowExplicitUnpaidExecutionFrom<T
);
ensure!(T::contains(origin), ProcessMessageError::Unsupported);
instructions.matcher().match_next_inst(|inst| match inst {
UnpaidExecution { weight_limit: Limited(m), .. } if m.all_gte(max_weight) => 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(())
Expand Down Expand Up @@ -369,7 +369,7 @@ impl<ResponseHandler: OnResponse> ShouldExecute for AllowKnownQueryResponses<Res
.matcher()
.assert_remaining_insts(1)?
.match_next_inst(|inst| match inst {
QueryResponse { query_id, querier, .. }
Instruction::QueryResponse(QueryResponse { query_id, querier, .. })
if ResponseHandler::expecting_response(origin, *query_id, querier.as_ref()) =>
Ok(()),
_ => Err(ProcessMessageError::BadFormat),
Expand Down Expand Up @@ -398,7 +398,7 @@ impl<T: Contains<Location>> ShouldExecute for AllowSubscriptionsFrom<T> {
.matcher()
.assert_remaining_insts(1)?
.match_next_inst(|inst| match inst {
SubscribeVersion { .. } | UnsubscribeVersion => Ok(()),
Instruction::SubscribeVersion(_) | Instruction::UnsubscribeVersion(_) => Ok(()),
_ => Err(ProcessMessageError::BadFormat),
})?;
Ok(())
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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!(
Expand Down
4 changes: 2 additions & 2 deletions polkadot/xcm/xcm-builder/src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Call>],
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<Call>;
type Loc = Location;
Expand Down
18 changes: 9 additions & 9 deletions polkadot/xcm/xcm-builder/src/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))?;
Expand Down
18 changes: 9 additions & 9 deletions polkadot/xcm/xcm-builder/src/universal_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,16 @@ impl<Bridges: ExporterFor, Router: SendXcm, UniversalLocation: Get<InteriorLocat
// We then send a normal message to the bridge asking it to export the prepended
// message to the remote chain. This will only work if the bridge will do the message
// export for free. Common-good chains will typically be afforded this.
let mut message = Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
let mut message = Xcm::new(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None }.into(),
ExportMessage {
network: remote_network,
destination: remote_location,
xcm: xcm.clone(),
},
}.into(),
]);
if let Some(forward_id) = maybe_forward_id {
message.0.push(SetTopic(forward_id));
message.0.push(SetTopic(forward_id).into());
}
validate_send::<Router>(bridge, message).inspect_err(|err| {
if let NotApplicable = err {
Expand Down Expand Up @@ -328,21 +328,21 @@ impl<Bridges: ExporterFor, Router: SendXcm, UniversalLocation: Get<InteriorLocat
xcm: xcm.clone(),
};

let mut message = Xcm(if let Some(ref payment) = maybe_payment {
let mut message = Xcm::new(if let Some(ref payment) = maybe_payment {
let fees = payment
.clone()
.reanchored(&bridge, &UniversalLocation::get())
.map_err(|_| Unroutable)?;
vec![
WithdrawAsset(fees.clone().into()),
BuyExecution { fees, weight_limit: Unlimited },
WithdrawAsset(fees.clone().into()).into(),
BuyExecution { fees, weight_limit: Unlimited }.into(),
// `SetAppendix` ensures that `fees` are not trapped in any case, for example, when
// `ExportXcm::validate` encounters an error during the processing of
// `ExportMessage`.
SetAppendix(Xcm(vec![DepositAsset {
SetAppendix(Xcm::new(vec![DepositAsset {
assets: AllCounted(1).into(),
beneficiary: local_from_bridge,
}])),
}.into()])),
export_instruction,
]
} else {
Expand Down
4 changes: 2 additions & 2 deletions polkadot/xcm/xcm-builder/src/weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub struct WeightInfoBounds<W, C, M>(PhantomData<(W, C, M)>);
impl<W, C, M> WeightBounds<C> for WeightInfoBounds<W, C, M>
where
W: XcmWeightInfo<C>,
C: Decode + GetDispatchInfo,
C: Decode + GetDispatchInfo + 'static,
M: Get<u32>,
Instruction<C>: xcm::latest::GetWeight<W>,
{
Expand All @@ -94,7 +94,7 @@ where
impl<W, C, M> WeightInfoBounds<W, C, M>
where
W: XcmWeightInfo<C>,
C: Decode + GetDispatchInfo,
C: Decode + GetDispatchInfo + 'static,
M: Get<u32>,
Instruction<C>: xcm::latest::GetWeight<W>,
{
Expand Down

0 comments on commit 9fbe244

Please sign in to comment.