Skip to content

Commit 8428f67

Browse files
XCMv4 (#1230)
# Note for reviewer Most changes are just syntax changes necessary for the new version. Most important files should be the ones under the `xcm` folder. # Description Added XCMv4. ## Removed `Multi` prefix The following types have been renamed: - MultiLocation -> Location - MultiAsset -> Asset - MultiAssets -> Assets - InteriorMultiLocation -> InteriorLocation - MultiAssetFilter -> AssetFilter - VersionedMultiAsset -> VersionedAsset - WildMultiAsset -> WildAsset - VersionedMultiLocation -> VersionedLocation In order to fix a name conflict, the `Assets` in `xcm-executor` were renamed to `HoldingAssets`, as they represent assets in holding. ## Removed `Abstract` asset id It was not being used anywhere and this simplifies the code. Now assets are just constructed as follows: ```rust let asset: Asset = (AssetId(Location::new(1, Here)), 100u128).into(); ``` No need for specifying `Concrete` anymore. ## Outcome is now a named fields struct Instead of ```rust pub enum Outcome { Complete(Weight), Incomplete(Weight, Error), Error(Error), } ``` we now have ```rust pub enum Outcome { Complete { used: Weight }, Incomplete { used: Weight, error: Error }, Error { error: Error }, } ``` ## Added Reanchorable trait Now both locations and assets implement this trait, making it easier to reanchor both. ## New syntax for building locations and junctions Now junctions are built using the following methods: ```rust let location = Location { parents: 1, interior: [Parachain(1000), PalletInstance(50), GeneralIndex(1984)].into() }; ``` or ```rust let location = Location::new(1, [Parachain(1000), PalletInstance(50), GeneralIndex(1984)]); ``` And they are matched like so: ```rust match location.unpack() { (1, [Parachain(id)]) => ... (0, Here) => ..., (1, [_]) => ..., } ``` This syntax is mandatory in v4, and has been also implemented for v2 and v3 for easier migration. This was needed to make all sizes smaller. # TODO - [x] Scaffold v4 - [x] Port github.com/paritytech/polkadot/pull/7236 - [x] Remove `Multi` prefix - [x] Remove `Abstract` asset id --------- Co-authored-by: command-bot <> Co-authored-by: Keith Yeung <[email protected]>
1 parent ec7bfae commit 8428f67

File tree

255 files changed

+12421
-6722
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

255 files changed

+12421
-6722
lines changed

bridges/bin/runtime-common/src/messages_benchmarking.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use frame_support::weights::Weight;
3838
use pallet_bridge_messages::benchmarking::{MessageDeliveryProofParams, MessageProofParams};
3939
use sp_runtime::traits::{Header, Zero};
4040
use sp_std::prelude::*;
41-
use xcm::v3::prelude::*;
41+
use xcm::latest::prelude::*;
4242

4343
/// Prepare inbound bridge message according to given message proof parameters.
4444
fn prepare_inbound_message(
@@ -266,19 +266,19 @@ where
266266
/// Returns callback which generates `BridgeMessage` from Polkadot XCM builder based on
267267
/// `expected_message_size` for benchmark.
268268
pub fn generate_xcm_builder_bridge_message_sample(
269-
destination: InteriorMultiLocation,
269+
destination: InteriorLocation,
270270
) -> impl Fn(usize) -> MessagePayload {
271271
move |expected_message_size| -> MessagePayload {
272272
// For XCM bridge hubs, it is the message that
273273
// will be pushed further to some XCM queue (XCMP/UMP)
274-
let location = xcm::VersionedInteriorMultiLocation::V3(destination);
274+
let location = xcm::VersionedInteriorLocation::V4(destination.clone());
275275
let location_encoded_size = location.encoded_size();
276276

277277
// we don't need to be super-precise with `expected_size` here
278278
let xcm_size = expected_message_size.saturating_sub(location_encoded_size);
279279
let xcm_data_size = xcm_size.saturating_sub(
280280
// minus empty instruction size
281-
xcm::v3::Instruction::<()>::ExpectPallet {
281+
Instruction::<()>::ExpectPallet {
282282
index: 0,
283283
name: vec![],
284284
module_name: vec![],
@@ -294,8 +294,8 @@ pub fn generate_xcm_builder_bridge_message_sample(
294294
expected_message_size, location_encoded_size, xcm_size, xcm_data_size,
295295
);
296296

297-
let xcm = xcm::VersionedXcm::<()>::V3(
298-
vec![xcm::v3::Instruction::<()>::ExpectPallet {
297+
let xcm = xcm::VersionedXcm::<()>::V4(
298+
vec![Instruction::<()>::ExpectPallet {
299299
index: 0,
300300
name: vec![42; xcm_data_size],
301301
module_name: vec![],

bridges/bin/runtime-common/src/messages_xcm_extension.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ impl<
123123
#[cfg_attr(feature = "std", derive(Debug, Eq, PartialEq))]
124124
pub struct SenderAndLane {
125125
/// Sending chain relative location.
126-
pub location: MultiLocation,
126+
pub location: Location,
127127
/// Message lane, used by the sending chain.
128128
pub lane: LaneId,
129129
}
130130

131131
impl SenderAndLane {
132132
/// Create new object using provided location and lane.
133-
pub fn new(location: MultiLocation, lane: LaneId) -> Self {
133+
pub fn new(location: Location, lane: LaneId) -> Self {
134134
SenderAndLane { location, lane }
135135
}
136136
}
@@ -168,7 +168,7 @@ pub struct XcmBlobHaulerAdapter<XcmBlobHauler, Lanes>(
168168

169169
impl<
170170
H: XcmBlobHauler,
171-
Lanes: Get<sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))>>,
171+
Lanes: Get<sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))>>,
172172
> OnMessagesDelivered for XcmBlobHaulerAdapter<H, Lanes>
173173
{
174174
fn on_messages_delivered(lane: LaneId, enqueued_messages: MessageNonce) {
@@ -288,7 +288,7 @@ impl<H: XcmBlobHauler> LocalXcmQueueManager<H> {
288288
/// Send congested signal to the `sending_chain_location`.
289289
fn send_congested_signal(sender_and_lane: &SenderAndLane) -> Result<(), SendError> {
290290
if let Some(msg) = H::CongestedMessage::get() {
291-
send_xcm::<H::ToSourceChainSender>(sender_and_lane.location, msg)?;
291+
send_xcm::<H::ToSourceChainSender>(sender_and_lane.location.clone(), msg)?;
292292
OutboundLanesCongestedSignals::<H::Runtime, H::MessagesInstance>::insert(
293293
sender_and_lane.lane,
294294
true,
@@ -300,7 +300,7 @@ impl<H: XcmBlobHauler> LocalXcmQueueManager<H> {
300300
/// Send `uncongested` signal to the `sending_chain_location`.
301301
fn send_uncongested_signal(sender_and_lane: &SenderAndLane) -> Result<(), SendError> {
302302
if let Some(msg) = H::UncongestedMessage::get() {
303-
send_xcm::<H::ToSourceChainSender>(sender_and_lane.location, msg)?;
303+
send_xcm::<H::ToSourceChainSender>(sender_and_lane.location.clone(), msg)?;
304304
OutboundLanesCongestedSignals::<H::Runtime, H::MessagesInstance>::remove(
305305
sender_and_lane.lane,
306306
);
@@ -315,10 +315,10 @@ impl<H: XcmBlobHauler> LocalXcmQueueManager<H> {
315315
pub struct XcmVersionOfDestAndRemoteBridge<Version, RemoteBridge>(
316316
sp_std::marker::PhantomData<(Version, RemoteBridge)>,
317317
);
318-
impl<Version: GetVersion, RemoteBridge: Get<MultiLocation>> GetVersion
318+
impl<Version: GetVersion, RemoteBridge: Get<Location>> GetVersion
319319
for XcmVersionOfDestAndRemoteBridge<Version, RemoteBridge>
320320
{
321-
fn get_version_for(dest: &MultiLocation) -> Option<XcmVersion> {
321+
fn get_version_for(dest: &Location) -> Option<XcmVersion> {
322322
let dest_version = Version::get_version_for(dest);
323323
let bridge_hub_version = Version::get_version_for(&RemoteBridge::get());
324324

@@ -342,11 +342,11 @@ mod tests {
342342

343343
parameter_types! {
344344
pub TestSenderAndLane: SenderAndLane = SenderAndLane {
345-
location: MultiLocation::new(1, X1(Parachain(1000))),
345+
location: Location::new(1, [Parachain(1000)]),
346346
lane: TEST_LANE_ID,
347347
};
348-
pub TestLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))> = sp_std::vec![
349-
(TestSenderAndLane::get(), (NetworkId::ByGenesis([0; 32]), InteriorMultiLocation::Here))
348+
pub TestLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))> = sp_std::vec![
349+
(TestSenderAndLane::get(), (NetworkId::ByGenesis([0; 32]), InteriorLocation::Here))
350350
];
351351
pub DummyXcmMessage: Xcm<()> = Xcm::new();
352352
}
@@ -363,7 +363,7 @@ mod tests {
363363
type Ticket = ();
364364

365365
fn validate(
366-
_destination: &mut Option<MultiLocation>,
366+
_destination: &mut Option<Location>,
367367
_message: &mut Option<Xcm<()>>,
368368
) -> SendResult<Self::Ticket> {
369369
Ok(((), Default::default()))

bridges/modules/xcm-bridge-hub-router/src/benchmarking.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ pub trait Config<I: 'static>: crate::Config<I> {
3737
/// Returns destination which is valid for this router instance.
3838
/// (Needs to pass `T::Bridges`)
3939
/// Make sure that `SendXcm` will pass.
40-
fn ensure_bridged_target_destination() -> Result<MultiLocation, BenchmarkError> {
41-
Ok(MultiLocation::new(
40+
fn ensure_bridged_target_destination() -> Result<Location, BenchmarkError> {
41+
Ok(Location::new(
4242
Self::UniversalLocation::get().len() as u8,
43-
X1(GlobalConsensus(Self::BridgedNetworkId::get().unwrap())),
43+
[GlobalConsensus(Self::BridgedNetworkId::get().unwrap())],
4444
))
4545
}
4646
}

bridges/modules/xcm-bridge-hub-router/src/lib.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub mod pallet {
8080
type WeightInfo: WeightInfo;
8181

8282
/// Universal location of this runtime.
83-
type UniversalLocation: Get<InteriorMultiLocation>;
83+
type UniversalLocation: Get<InteriorLocation>;
8484
/// The bridged network that this config is for if specified.
8585
/// Also used for filtering `Bridges` by `BridgedNetworkId`.
8686
/// If not specified, allows all networks pass through.
@@ -235,9 +235,9 @@ type ViaBridgeHubExporter<T, I> = SovereignPaidRemoteExporter<
235235
impl<T: Config<I>, I: 'static> ExporterFor for Pallet<T, I> {
236236
fn exporter_for(
237237
network: &NetworkId,
238-
remote_location: &InteriorMultiLocation,
238+
remote_location: &InteriorLocation,
239239
message: &Xcm<()>,
240-
) -> Option<(MultiLocation, Option<MultiAsset>)> {
240+
) -> Option<(Location, Option<Asset>)> {
241241
// ensure that the message is sent to the expected bridged network (if specified).
242242
if let Some(bridged_network) = T::BridgedNetworkId::get() {
243243
if *network != bridged_network {
@@ -268,7 +268,7 @@ impl<T: Config<I>, I: 'static> ExporterFor for Pallet<T, I> {
268268
// take `base_fee` from `T::Brides`, but it has to be the same `T::FeeAsset`
269269
let base_fee = match maybe_payment {
270270
Some(payment) => match payment {
271-
MultiAsset { fun: Fungible(amount), id } if id.eq(&T::FeeAsset::get()) => amount,
271+
Asset { fun: Fungible(amount), id } if id.eq(&T::FeeAsset::get()) => amount,
272272
invalid_asset => {
273273
log::error!(
274274
target: LOG_TARGET,
@@ -318,7 +318,7 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> {
318318
type Ticket = (u32, <T::ToBridgeHubSender as SendXcm>::Ticket);
319319

320320
fn validate(
321-
dest: &mut Option<MultiLocation>,
321+
dest: &mut Option<Location>,
322322
xcm: &mut Option<Xcm<()>>,
323323
) -> SendResult<Self::Ticket> {
324324
// `dest` and `xcm` are required here
@@ -446,7 +446,7 @@ mod tests {
446446
run_test(|| {
447447
assert_eq!(
448448
send_xcm::<XcmBridgeHubRouter>(
449-
MultiLocation::new(2, X2(GlobalConsensus(Rococo), Parachain(1000))),
449+
Location::new(2, [GlobalConsensus(Rococo), Parachain(1000)]),
450450
vec![].into(),
451451
),
452452
Err(SendError::NotApplicable),
@@ -459,7 +459,7 @@ mod tests {
459459
run_test(|| {
460460
assert_eq!(
461461
send_xcm::<XcmBridgeHubRouter>(
462-
MultiLocation::new(2, X2(GlobalConsensus(Rococo), Parachain(1000))),
462+
Location::new(2, [GlobalConsensus(Rococo), Parachain(1000)]),
463463
vec![ClearOrigin; HARD_MESSAGE_SIZE_LIMIT as usize].into(),
464464
),
465465
Err(SendError::ExceedsMaxMessageSize),
@@ -483,14 +483,14 @@ mod tests {
483483
#[test]
484484
fn returns_proper_delivery_price() {
485485
run_test(|| {
486-
let dest = MultiLocation::new(2, X1(GlobalConsensus(BridgedNetworkId::get())));
486+
let dest = Location::new(2, [GlobalConsensus(BridgedNetworkId::get())]);
487487
let xcm: Xcm<()> = vec![ClearOrigin].into();
488488
let msg_size = xcm.encoded_size();
489489

490490
// initially the base fee is used: `BASE_FEE + BYTE_FEE * msg_size + HRMP_FEE`
491491
let expected_fee = BASE_FEE + BYTE_FEE * (msg_size as u128) + HRMP_FEE;
492492
assert_eq!(
493-
XcmBridgeHubRouter::validate(&mut Some(dest), &mut Some(xcm.clone()))
493+
XcmBridgeHubRouter::validate(&mut Some(dest.clone()), &mut Some(xcm.clone()))
494494
.unwrap()
495495
.1
496496
.get(0),
@@ -518,10 +518,7 @@ mod tests {
518518
run_test(|| {
519519
let old_bridge = XcmBridgeHubRouter::bridge();
520520
assert_ok!(send_xcm::<XcmBridgeHubRouter>(
521-
MultiLocation::new(
522-
2,
523-
X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(1000))
524-
),
521+
Location::new(2, [GlobalConsensus(BridgedNetworkId::get()), Parachain(1000)]),
525522
vec![ClearOrigin].into(),
526523
)
527524
.map(drop));
@@ -538,10 +535,7 @@ mod tests {
538535

539536
let old_bridge = XcmBridgeHubRouter::bridge();
540537
assert_ok!(send_xcm::<XcmBridgeHubRouter>(
541-
MultiLocation::new(
542-
2,
543-
X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(1000))
544-
),
538+
Location::new(2, [GlobalConsensus(BridgedNetworkId::get()), Parachain(1000)]),
545539
vec![ClearOrigin].into(),
546540
)
547541
.map(drop));
@@ -560,10 +554,7 @@ mod tests {
560554

561555
let old_bridge = XcmBridgeHubRouter::bridge();
562556
assert_ok!(send_xcm::<XcmBridgeHubRouter>(
563-
MultiLocation::new(
564-
2,
565-
X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(1000))
566-
),
557+
Location::new(2, [GlobalConsensus(BridgedNetworkId::get()), Parachain(1000)]),
567558
vec![ClearOrigin].into(),
568559
)
569560
.map(drop));

bridges/modules/xcm-bridge-hub-router/src/mock.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ construct_runtime! {
4949
parameter_types! {
5050
pub ThisNetworkId: NetworkId = Polkadot;
5151
pub BridgedNetworkId: NetworkId = Kusama;
52-
pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(ThisNetworkId::get()), Parachain(1000));
53-
pub SiblingBridgeHubLocation: MultiLocation = ParentThen(X1(Parachain(1002))).into();
54-
pub BridgeFeeAsset: AssetId = MultiLocation::parent().into();
52+
pub UniversalLocation: InteriorLocation = [GlobalConsensus(ThisNetworkId::get()), Parachain(1000)].into();
53+
pub SiblingBridgeHubLocation: Location = ParentThen([Parachain(1002)].into()).into();
54+
pub BridgeFeeAsset: AssetId = Location::parent().into();
5555
pub BridgeTable: Vec<NetworkExportTableItem>
5656
= vec![
5757
NetworkExportTableItem::new(
@@ -61,7 +61,7 @@ parameter_types! {
6161
Some((BridgeFeeAsset::get(), BASE_FEE).into())
6262
)
6363
];
64-
pub UnknownXcmVersionLocation: MultiLocation = MultiLocation::new(2, X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(9999)));
64+
pub UnknownXcmVersionLocation: Location = Location::new(2, [GlobalConsensus(BridgedNetworkId::get()), Parachain(9999)]);
6565
}
6666

6767
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
@@ -87,11 +87,11 @@ impl pallet_xcm_bridge_hub_router::Config<()> for TestRuntime {
8787
}
8888

8989
pub struct LatestOrNoneForLocationVersionChecker<Location>(sp_std::marker::PhantomData<Location>);
90-
impl<Location: Contains<MultiLocation>> GetVersion
91-
for LatestOrNoneForLocationVersionChecker<Location>
90+
impl<LocationValue: Contains<Location>> GetVersion
91+
for LatestOrNoneForLocationVersionChecker<LocationValue>
9292
{
93-
fn get_version_for(dest: &MultiLocation) -> Option<XcmVersion> {
94-
if Location::contains(dest) {
93+
fn get_version_for(dest: &Location) -> Option<XcmVersion> {
94+
if LocationValue::contains(dest) {
9595
return None
9696
}
9797
Some(XCM_VERSION)
@@ -110,7 +110,7 @@ impl SendXcm for TestToBridgeHubSender {
110110
type Ticket = ();
111111

112112
fn validate(
113-
_destination: &mut Option<MultiLocation>,
113+
_destination: &mut Option<Location>,
114114
_message: &mut Option<Xcm<()>>,
115115
) -> SendResult<Self::Ticket> {
116116
Ok(((), (BridgeFeeAsset::get(), HRMP_FEE).into()))

bridges/modules/xcm-bridge-hub/src/exporter.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ where
5252
fn validate(
5353
network: NetworkId,
5454
channel: u32,
55-
universal_source: &mut Option<InteriorMultiLocation>,
56-
destination: &mut Option<InteriorMultiLocation>,
55+
universal_source: &mut Option<InteriorLocation>,
56+
destination: &mut Option<InteriorLocation>,
5757
message: &mut Option<Xcm<()>>,
58-
) -> Result<(Self::Ticket, MultiAssets), SendError> {
58+
) -> Result<(Self::Ticket, Assets), SendError> {
5959
// Find supported lane_id.
6060
let sender_and_lane = Self::lane_for(
6161
universal_source.as_ref().ok_or(SendError::MissingArgument)?,
@@ -137,11 +137,11 @@ mod tests {
137137
use frame_support::assert_ok;
138138
use xcm_executor::traits::export_xcm;
139139

140-
fn universal_source() -> InteriorMultiLocation {
141-
X2(GlobalConsensus(RelayNetwork::get()), Parachain(SIBLING_ASSET_HUB_ID))
140+
fn universal_source() -> InteriorLocation {
141+
[GlobalConsensus(RelayNetwork::get()), Parachain(SIBLING_ASSET_HUB_ID)].into()
142142
}
143143

144-
fn universal_destination() -> InteriorMultiLocation {
144+
fn universal_destination() -> InteriorLocation {
145145
BridgedDestination::get()
146146
}
147147

bridges/modules/xcm-bridge-hub/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,25 @@ pub mod pallet {
4545
BridgeMessagesConfig<Self::BridgeMessagesPalletInstance>
4646
{
4747
/// Runtime's universal location.
48-
type UniversalLocation: Get<InteriorMultiLocation>;
48+
type UniversalLocation: Get<InteriorLocation>;
4949
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1666 remove `ChainId` and
5050
// replace it with the `NetworkId` - then we'll be able to use
5151
// `T as pallet_bridge_messages::Config<T::BridgeMessagesPalletInstance>::BridgedChain::NetworkId`
5252
/// Bridged network as relative location of bridged `GlobalConsensus`.
5353
#[pallet::constant]
54-
type BridgedNetwork: Get<MultiLocation>;
54+
type BridgedNetwork: Get<Location>;
5555
/// Associated messages pallet instance that bridges us with the
5656
/// `BridgedNetworkId` consensus.
5757
type BridgeMessagesPalletInstance: 'static;
5858

5959
/// Price of single message export to the bridged consensus (`Self::BridgedNetworkId`).
60-
type MessageExportPrice: Get<MultiAssets>;
60+
type MessageExportPrice: Get<Assets>;
6161
/// Checks the XCM version for the destination.
6262
type DestinationVersion: GetVersion;
6363

6464
/// Get point-to-point links with bridged consensus (`Self::BridgedNetworkId`).
6565
/// (this will be replaced with dynamic on-chain bridges - `Bridges V2`)
66-
type Lanes: Get<sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))>>;
66+
type Lanes: Get<sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))>>;
6767
/// Support for point-to-point links
6868
/// (this will be replaced with dynamic on-chain bridges - `Bridges V2`)
6969
type LanesSupport: XcmBlobHauler;
@@ -86,10 +86,10 @@ pub mod pallet {
8686
impl<T: Config<I>, I: 'static> Pallet<T, I> {
8787
/// Returns dedicated/configured lane identifier.
8888
pub(crate) fn lane_for(
89-
source: &InteriorMultiLocation,
90-
dest: (&NetworkId, &InteriorMultiLocation),
89+
source: &InteriorLocation,
90+
dest: (&NetworkId, &InteriorLocation),
9191
) -> Option<SenderAndLane> {
92-
let source = source.relative_to(&T::UniversalLocation::get());
92+
let source = source.clone().relative_to(&T::UniversalLocation::get());
9393

9494
// Check that we have configured a point-to-point lane for 'source' and `dest`.
9595
T::Lanes::get()

0 commit comments

Comments
 (0)