Skip to content

Commit 4ddcbd4

Browse files
franciscoaguirrebkontur
authored andcommitted
Deprecate XCMv2 (paritytech#4131)
Marked XCMv2 as deprecated now that we have XCMv4. It will be removed sometime around June 2024. --------- Co-authored-by: Branislav Kontur <[email protected]>
1 parent be387c0 commit 4ddcbd4

File tree

16 files changed

+249
-358
lines changed

16 files changed

+249
-358
lines changed

cumulus/pallets/xcmp-queue/src/mock.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,13 @@ impl GetChannelInfo for MockedChannelInfo {
321321
pub(crate) fn mk_page() -> Vec<u8> {
322322
let mut page = Vec::<u8>::new();
323323

324+
let newer_xcm_version = xcm::prelude::XCM_VERSION;
325+
let older_xcm_version = newer_xcm_version - 1;
326+
324327
for i in 0..100 {
325328
page.extend(match i % 2 {
326-
0 => v2_xcm().encode(),
327-
1 => v3_xcm().encode(),
329+
0 => versioned_xcm(older_xcm_version).encode(),
330+
1 => versioned_xcm(newer_xcm_version).encode(),
328331
// We cannot push an undecodable XCM here since it would break the decode stream.
329332
// This is expected and the whole reason to introduce `MaybeDoubleEncodedVersionedXcm`
330333
// instead.
@@ -335,12 +338,9 @@ pub(crate) fn mk_page() -> Vec<u8> {
335338
page
336339
}
337340

338-
pub(crate) fn v2_xcm() -> VersionedXcm<()> {
339-
let instr = xcm::v2::Instruction::<()>::ClearOrigin;
340-
VersionedXcm::V2(xcm::v2::Xcm::<()>(vec![instr; 3]))
341-
}
342-
343-
pub(crate) fn v3_xcm() -> VersionedXcm<()> {
344-
let instr = xcm::v3::Instruction::<()>::Trap(1);
345-
VersionedXcm::V3(xcm::v3::Xcm::<()>(vec![instr; 3]))
341+
pub(crate) fn versioned_xcm(version: XcmVersion) -> VersionedXcm<()> {
342+
let instr = Instruction::<()>::Trap(1);
343+
VersionedXcm::from(Xcm::<()>(vec![instr; 3]))
344+
.into_version(version)
345+
.expect("Version conversion should work")
346346
}

cumulus/pallets/xcmp-queue/src/tests.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// limitations under the License.
1515

1616
use super::{
17-
mock::{mk_page, v2_xcm, v3_xcm, EnqueuedMessages, HRMP_PARA_ID},
17+
mock::{mk_page, versioned_xcm, EnqueuedMessages, HRMP_PARA_ID},
1818
*,
1919
};
2020
use XcmpMessageFormat::*;
@@ -536,24 +536,27 @@ fn hrmp_signals_are_prioritized() {
536536
#[test]
537537
fn maybe_double_encoded_versioned_xcm_works() {
538538
// pre conditions
539-
assert_eq!(VersionedXcm::<()>::V2(Default::default()).encode(), &[2, 0]);
540539
assert_eq!(VersionedXcm::<()>::V3(Default::default()).encode(), &[3, 0]);
540+
assert_eq!(VersionedXcm::<()>::V4(Default::default()).encode(), &[4, 0]);
541541
}
542542

543543
// Now also testing a page instead of just concat messages.
544544
#[test]
545545
fn maybe_double_encoded_versioned_xcm_decode_page_works() {
546546
let page = mk_page();
547547

548+
let newer_xcm_version = xcm::prelude::XCM_VERSION;
549+
let older_xcm_version = newer_xcm_version - 1;
550+
548551
// Now try to decode the page.
549552
let input = &mut &page[..];
550553
for i in 0..100 {
551554
match (i % 2, VersionedXcm::<()>::decode(input)) {
552555
(0, Ok(xcm)) => {
553-
assert_eq!(xcm, v2_xcm());
556+
assert_eq!(xcm, versioned_xcm(older_xcm_version));
554557
},
555558
(1, Ok(xcm)) => {
556-
assert_eq!(xcm, v3_xcm());
559+
assert_eq!(xcm, versioned_xcm(newer_xcm_version));
557560
},
558561
unexpected => unreachable!("{:?}", unexpected),
559562
}
@@ -568,14 +571,17 @@ fn take_first_concatenated_xcm_works() {
568571
let page = mk_page();
569572
let input = &mut &page[..];
570573

574+
let newer_xcm_version = xcm::prelude::XCM_VERSION;
575+
let older_xcm_version = newer_xcm_version - 1;
576+
571577
for i in 0..100 {
572578
let xcm = XcmpQueue::take_first_concatenated_xcm(input, &mut WeightMeter::new()).unwrap();
573579
match (i % 2, xcm) {
574580
(0, data) | (2, data) => {
575-
assert_eq!(data, v2_xcm().encode());
581+
assert_eq!(data, versioned_xcm(older_xcm_version).encode());
576582
},
577583
(1, data) | (3, data) => {
578-
assert_eq!(data, v3_xcm().encode());
584+
assert_eq!(data, versioned_xcm(newer_xcm_version).encode());
579585
},
580586
unexpected => unreachable!("{:?}", unexpected),
581587
}

cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/send_xcm.rs

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ fn send_xcm_from_rococo_relay_to_westend_asset_hub_should_fail_on_not_applicable
6161
#[test]
6262
fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
6363
// Initially set only default version on all runtimes
64-
AssetHubRococo::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
65-
BridgeHubRococo::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
66-
BridgeHubWestend::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
67-
AssetHubWestend::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
64+
let newer_xcm_version = xcm::prelude::XCM_VERSION;
65+
let older_xcm_version = newer_xcm_version - 1;
66+
67+
AssetHubRococo::force_default_xcm_version(Some(older_xcm_version));
68+
BridgeHubRococo::force_default_xcm_version(Some(older_xcm_version));
69+
BridgeHubWestend::force_default_xcm_version(Some(older_xcm_version));
70+
AssetHubWestend::force_default_xcm_version(Some(older_xcm_version));
6871

6972
// prepare data
7073
let destination = asset_hub_westend_location();
@@ -87,42 +90,12 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
8790
);
8891

8992
// set destination version
90-
AssetHubRococo::force_xcm_version(destination.clone(), xcm::v3::prelude::XCM_VERSION);
91-
92-
// TODO: remove this block, when removing `xcm:v2`
93-
{
94-
// send XCM from AssetHubRococo - fails - AssetHubRococo is set to the default/safe `2`
95-
// version, which does not have the `ExportMessage` instruction. If the default `2` is
96-
// changed to `3`, then this assert can go away"
97-
assert_err!(
98-
send_asset_from_asset_hub_rococo(destination.clone(), (native_token.clone(), amount)),
99-
DispatchError::Module(sp_runtime::ModuleError {
100-
index: 31,
101-
error: [1, 0, 0, 0],
102-
message: Some("SendFailure")
103-
})
104-
);
105-
106-
// set exact version for BridgeHubWestend to `2` without `ExportMessage` instruction
107-
AssetHubRococo::force_xcm_version(
108-
ParentThen(Parachain(BridgeHubRococo::para_id().into()).into()).into(),
109-
xcm::v2::prelude::XCM_VERSION,
110-
);
111-
// send XCM from AssetHubRococo - fails - `ExportMessage` is not in `2`
112-
assert_err!(
113-
send_asset_from_asset_hub_rococo(destination.clone(), (native_token.clone(), amount)),
114-
DispatchError::Module(sp_runtime::ModuleError {
115-
index: 31,
116-
error: [1, 0, 0, 0],
117-
message: Some("SendFailure")
118-
})
119-
);
120-
}
93+
AssetHubRococo::force_xcm_version(destination.clone(), newer_xcm_version);
12194

12295
// set version with `ExportMessage` for BridgeHubRococo
12396
AssetHubRococo::force_xcm_version(
12497
ParentThen(Parachain(BridgeHubRococo::para_id().into()).into()).into(),
125-
xcm::v3::prelude::XCM_VERSION,
98+
newer_xcm_version,
12699
);
127100
// send XCM from AssetHubRococo - ok
128101
assert_ok!(send_asset_from_asset_hub_rococo(
@@ -134,14 +107,11 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
134107
assert_bridge_hub_rococo_message_accepted(false);
135108

136109
// set version for remote BridgeHub on BridgeHubRococo
137-
BridgeHubRococo::force_xcm_version(
138-
bridge_hub_westend_location(),
139-
xcm::v3::prelude::XCM_VERSION,
140-
);
110+
BridgeHubRococo::force_xcm_version(bridge_hub_westend_location(), newer_xcm_version);
141111
// set version for AssetHubWestend on BridgeHubWestend
142112
BridgeHubWestend::force_xcm_version(
143113
ParentThen(Parachain(AssetHubWestend::para_id().into()).into()).into(),
144-
xcm::v3::prelude::XCM_VERSION,
114+
newer_xcm_version,
145115
);
146116

147117
// send XCM from AssetHubRococo - ok
@@ -164,20 +134,4 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
164134
]
165135
);
166136
});
167-
168-
// TODO: remove this block, when removing `xcm:v2`
169-
{
170-
// set `2` version for remote BridgeHub on BridgeHubRococo, which does not have
171-
// `UniversalOrigin` and `DescendOrigin`
172-
BridgeHubRococo::force_xcm_version(
173-
bridge_hub_westend_location(),
174-
xcm::v2::prelude::XCM_VERSION,
175-
);
176-
177-
// send XCM from AssetHubRococo - ok
178-
assert_ok!(send_asset_from_asset_hub_rococo(destination, (native_token, amount)));
179-
// message is not accepted on the local BridgeHub (`DestinationUnsupported`) because we
180-
// cannot add `UniversalOrigin` and `DescendOrigin`
181-
assert_bridge_hub_rococo_message_accepted(false);
182-
}
183137
}

cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/send_xcm.rs

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ fn send_xcm_from_westend_relay_to_rococo_asset_hub_should_fail_on_not_applicable
6161
#[test]
6262
fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
6363
// Initially set only default version on all runtimes
64-
AssetHubRococo::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
65-
BridgeHubRococo::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
66-
BridgeHubWestend::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
67-
AssetHubWestend::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
64+
let newer_xcm_version = xcm::prelude::XCM_VERSION;
65+
let older_xcm_version = newer_xcm_version - 1;
66+
67+
AssetHubRococo::force_default_xcm_version(Some(older_xcm_version));
68+
BridgeHubRococo::force_default_xcm_version(Some(older_xcm_version));
69+
BridgeHubWestend::force_default_xcm_version(Some(older_xcm_version));
70+
AssetHubWestend::force_default_xcm_version(Some(older_xcm_version));
6871

6972
// prepare data
7073
let destination = asset_hub_rococo_location();
@@ -87,42 +90,12 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
8790
);
8891

8992
// set destination version
90-
AssetHubWestend::force_xcm_version(destination.clone(), xcm::v3::prelude::XCM_VERSION);
91-
92-
// TODO: remove this block, when removing `xcm:v2`
93-
{
94-
// send XCM from AssetHubRococo - fails - AssetHubRococo is set to the default/safe `2`
95-
// version, which does not have the `ExportMessage` instruction. If the default `2` is
96-
// changed to `3`, then this assert can go away"
97-
assert_err!(
98-
send_asset_from_asset_hub_westend(destination.clone(), (native_token.clone(), amount)),
99-
DispatchError::Module(sp_runtime::ModuleError {
100-
index: 31,
101-
error: [1, 0, 0, 0],
102-
message: Some("SendFailure")
103-
})
104-
);
105-
106-
// set exact version for BridgeHubWestend to `2` without `ExportMessage` instruction
107-
AssetHubWestend::force_xcm_version(
108-
ParentThen(Parachain(BridgeHubWestend::para_id().into()).into()).into(),
109-
xcm::v2::prelude::XCM_VERSION,
110-
);
111-
// send XCM from AssetHubWestend - fails - `ExportMessage` is not in `2`
112-
assert_err!(
113-
send_asset_from_asset_hub_westend(destination.clone(), (native_token.clone(), amount)),
114-
DispatchError::Module(sp_runtime::ModuleError {
115-
index: 31,
116-
error: [1, 0, 0, 0],
117-
message: Some("SendFailure")
118-
})
119-
);
120-
}
93+
AssetHubWestend::force_xcm_version(destination.clone(), newer_xcm_version);
12194

12295
// set version with `ExportMessage` for BridgeHubWestend
12396
AssetHubWestend::force_xcm_version(
12497
ParentThen(Parachain(BridgeHubWestend::para_id().into()).into()).into(),
125-
xcm::v3::prelude::XCM_VERSION,
98+
newer_xcm_version,
12699
);
127100
// send XCM from AssetHubWestend - ok
128101
assert_ok!(send_asset_from_asset_hub_westend(
@@ -134,14 +107,11 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
134107
assert_bridge_hub_westend_message_accepted(false);
135108

136109
// set version for remote BridgeHub on BridgeHubWestend
137-
BridgeHubWestend::force_xcm_version(
138-
bridge_hub_rococo_location(),
139-
xcm::v3::prelude::XCM_VERSION,
140-
);
110+
BridgeHubWestend::force_xcm_version(bridge_hub_rococo_location(), newer_xcm_version);
141111
// set version for AssetHubRococo on BridgeHubRococo
142112
BridgeHubRococo::force_xcm_version(
143113
ParentThen(Parachain(AssetHubRococo::para_id().into()).into()).into(),
144-
xcm::v3::prelude::XCM_VERSION,
114+
newer_xcm_version,
145115
);
146116

147117
// send XCM from AssetHubWestend - ok
@@ -164,20 +134,4 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
164134
]
165135
);
166136
});
167-
168-
// TODO: remove this block, when removing `xcm:v2`
169-
{
170-
// set `2` version for remote BridgeHub on BridgeHubRococo, which does not have
171-
// `UniversalOrigin` and `DescendOrigin`
172-
BridgeHubWestend::force_xcm_version(
173-
bridge_hub_rococo_location(),
174-
xcm::v2::prelude::XCM_VERSION,
175-
);
176-
177-
// send XCM from AssetHubWestend - ok
178-
assert_ok!(send_asset_from_asset_hub_westend(destination, (native_token, amount)));
179-
// message is not accepted on the local BridgeHub (`DestinationUnsupported`) because we
180-
// cannot add `UniversalOrigin` and `DescendOrigin`
181-
assert_bridge_hub_westend_message_accepted(false);
182-
}
183137
}

polkadot/xcm/pallet-xcm/src/benchmarking.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use super::*;
18-
use bounded_collections::{ConstU32, WeakBoundedVec};
1918
use frame_benchmarking::{benchmarks, whitelisted_caller, BenchmarkError, BenchmarkResult};
2019
use frame_support::{assert_ok, weights::Weight};
2120
use frame_system::RawOrigin;
2221
use sp_std::prelude::*;
23-
use xcm::{latest::prelude::*, v2};
22+
use xcm::latest::prelude::*;
2423
use xcm_builder::EnsureDelivery;
2524
use xcm_executor::traits::FeeReason;
2625

@@ -313,15 +312,17 @@ benchmarks! {
313312
}
314313

315314
notify_target_migration_fail {
316-
let bad_loc: v2::MultiLocation = v2::Junction::Plurality {
317-
id: v2::BodyId::Named(WeakBoundedVec::<u8, ConstU32<32>>::try_from(vec![0; 32])
318-
.expect("vec has a length of 32 bits; qed")),
319-
part: v2::BodyPart::Voice,
320-
}
321-
.into();
322-
let bad_loc = VersionedLocation::from(bad_loc);
315+
let newer_xcm_version = xcm::prelude::XCM_VERSION;
316+
let older_xcm_version = newer_xcm_version - 1;
317+
let bad_location: Location = Plurality {
318+
id: BodyId::Unit,
319+
part: BodyPart::Voice,
320+
}.into();
321+
let bad_location = VersionedLocation::from(bad_location)
322+
.into_version(older_xcm_version)
323+
.expect("Version convertion should work");
323324
let current_version = T::AdvertisedXcmVersion::get();
324-
VersionNotifyTargets::<T>::insert(current_version, bad_loc, (0, Weight::zero(), current_version));
325+
VersionNotifyTargets::<T>::insert(current_version, bad_location, (0, Weight::zero(), current_version));
325326
}: {
326327
crate::Pallet::<T>::check_xcm_version_change(VersionMigrationStage::MigrateAndNotifyOldTargets, Weight::zero());
327328
}

polkadot/xcm/pallet-xcm/src/tests/assets_transfer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn limited_teleport_assets_works() {
7676
)]
7777
);
7878
let versioned_sent = VersionedXcm::from(sent_xcm().into_iter().next().unwrap().1);
79-
let _check_v2_ok: xcm::v2::Xcm<()> = versioned_sent.try_into().unwrap();
79+
let _check_v3_ok: xcm::v3::Xcm<()> = versioned_sent.try_into().unwrap();
8080

8181
let mut last_events = last_events(3).into_iter();
8282
assert_eq!(

0 commit comments

Comments
 (0)