Skip to content

Commit

Permalink
Deprecate XCMv2 (paritytech#4131)
Browse files Browse the repository at this point in the history
Marked XCMv2 as deprecated now that we have XCMv4.
It will be removed sometime around June 2024.

---------

Co-authored-by: Branislav Kontur <bkontur@gmail.com>
  • Loading branch information
2 people authored and TarekkMA committed Aug 2, 2024
1 parent be387c0 commit 4ddcbd4
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 358 deletions.
20 changes: 10 additions & 10 deletions cumulus/pallets/xcmp-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,13 @@ impl GetChannelInfo for MockedChannelInfo {
pub(crate) fn mk_page() -> Vec<u8> {
let mut page = Vec::<u8>::new();

let newer_xcm_version = xcm::prelude::XCM_VERSION;
let older_xcm_version = newer_xcm_version - 1;

for i in 0..100 {
page.extend(match i % 2 {
0 => v2_xcm().encode(),
1 => v3_xcm().encode(),
0 => versioned_xcm(older_xcm_version).encode(),
1 => versioned_xcm(newer_xcm_version).encode(),
// We cannot push an undecodable XCM here since it would break the decode stream.
// This is expected and the whole reason to introduce `MaybeDoubleEncodedVersionedXcm`
// instead.
Expand All @@ -335,12 +338,9 @@ pub(crate) fn mk_page() -> Vec<u8> {
page
}

pub(crate) fn v2_xcm() -> VersionedXcm<()> {
let instr = xcm::v2::Instruction::<()>::ClearOrigin;
VersionedXcm::V2(xcm::v2::Xcm::<()>(vec![instr; 3]))
}

pub(crate) fn v3_xcm() -> VersionedXcm<()> {
let instr = xcm::v3::Instruction::<()>::Trap(1);
VersionedXcm::V3(xcm::v3::Xcm::<()>(vec![instr; 3]))
pub(crate) fn versioned_xcm(version: XcmVersion) -> VersionedXcm<()> {
let instr = Instruction::<()>::Trap(1);
VersionedXcm::from(Xcm::<()>(vec![instr; 3]))
.into_version(version)
.expect("Version conversion should work")
}
18 changes: 12 additions & 6 deletions cumulus/pallets/xcmp-queue/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.

use super::{
mock::{mk_page, v2_xcm, v3_xcm, EnqueuedMessages, HRMP_PARA_ID},
mock::{mk_page, versioned_xcm, EnqueuedMessages, HRMP_PARA_ID},
*,
};
use XcmpMessageFormat::*;
Expand Down Expand Up @@ -536,24 +536,27 @@ fn hrmp_signals_are_prioritized() {
#[test]
fn maybe_double_encoded_versioned_xcm_works() {
// pre conditions
assert_eq!(VersionedXcm::<()>::V2(Default::default()).encode(), &[2, 0]);
assert_eq!(VersionedXcm::<()>::V3(Default::default()).encode(), &[3, 0]);
assert_eq!(VersionedXcm::<()>::V4(Default::default()).encode(), &[4, 0]);
}

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

let newer_xcm_version = xcm::prelude::XCM_VERSION;
let older_xcm_version = newer_xcm_version - 1;

// Now try to decode the page.
let input = &mut &page[..];
for i in 0..100 {
match (i % 2, VersionedXcm::<()>::decode(input)) {
(0, Ok(xcm)) => {
assert_eq!(xcm, v2_xcm());
assert_eq!(xcm, versioned_xcm(older_xcm_version));
},
(1, Ok(xcm)) => {
assert_eq!(xcm, v3_xcm());
assert_eq!(xcm, versioned_xcm(newer_xcm_version));
},
unexpected => unreachable!("{:?}", unexpected),
}
Expand All @@ -568,14 +571,17 @@ fn take_first_concatenated_xcm_works() {
let page = mk_page();
let input = &mut &page[..];

let newer_xcm_version = xcm::prelude::XCM_VERSION;
let older_xcm_version = newer_xcm_version - 1;

for i in 0..100 {
let xcm = XcmpQueue::take_first_concatenated_xcm(input, &mut WeightMeter::new()).unwrap();
match (i % 2, xcm) {
(0, data) | (2, data) => {
assert_eq!(data, v2_xcm().encode());
assert_eq!(data, versioned_xcm(older_xcm_version).encode());
},
(1, data) | (3, data) => {
assert_eq!(data, v3_xcm().encode());
assert_eq!(data, versioned_xcm(newer_xcm_version).encode());
},
unexpected => unreachable!("{:?}", unexpected),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ fn send_xcm_from_rococo_relay_to_westend_asset_hub_should_fail_on_not_applicable
#[test]
fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
// Initially set only default version on all runtimes
AssetHubRococo::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
BridgeHubRococo::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
BridgeHubWestend::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
AssetHubWestend::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
let newer_xcm_version = xcm::prelude::XCM_VERSION;
let older_xcm_version = newer_xcm_version - 1;

AssetHubRococo::force_default_xcm_version(Some(older_xcm_version));
BridgeHubRococo::force_default_xcm_version(Some(older_xcm_version));
BridgeHubWestend::force_default_xcm_version(Some(older_xcm_version));
AssetHubWestend::force_default_xcm_version(Some(older_xcm_version));

// prepare data
let destination = asset_hub_westend_location();
Expand All @@ -87,42 +90,12 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
);

// set destination version
AssetHubRococo::force_xcm_version(destination.clone(), xcm::v3::prelude::XCM_VERSION);

// TODO: remove this block, when removing `xcm:v2`
{
// send XCM from AssetHubRococo - fails - AssetHubRococo is set to the default/safe `2`
// version, which does not have the `ExportMessage` instruction. If the default `2` is
// changed to `3`, then this assert can go away"
assert_err!(
send_asset_from_asset_hub_rococo(destination.clone(), (native_token.clone(), amount)),
DispatchError::Module(sp_runtime::ModuleError {
index: 31,
error: [1, 0, 0, 0],
message: Some("SendFailure")
})
);

// set exact version for BridgeHubWestend to `2` without `ExportMessage` instruction
AssetHubRococo::force_xcm_version(
ParentThen(Parachain(BridgeHubRococo::para_id().into()).into()).into(),
xcm::v2::prelude::XCM_VERSION,
);
// send XCM from AssetHubRococo - fails - `ExportMessage` is not in `2`
assert_err!(
send_asset_from_asset_hub_rococo(destination.clone(), (native_token.clone(), amount)),
DispatchError::Module(sp_runtime::ModuleError {
index: 31,
error: [1, 0, 0, 0],
message: Some("SendFailure")
})
);
}
AssetHubRococo::force_xcm_version(destination.clone(), newer_xcm_version);

// set version with `ExportMessage` for BridgeHubRococo
AssetHubRococo::force_xcm_version(
ParentThen(Parachain(BridgeHubRococo::para_id().into()).into()).into(),
xcm::v3::prelude::XCM_VERSION,
newer_xcm_version,
);
// send XCM from AssetHubRococo - ok
assert_ok!(send_asset_from_asset_hub_rococo(
Expand All @@ -134,14 +107,11 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
assert_bridge_hub_rococo_message_accepted(false);

// set version for remote BridgeHub on BridgeHubRococo
BridgeHubRococo::force_xcm_version(
bridge_hub_westend_location(),
xcm::v3::prelude::XCM_VERSION,
);
BridgeHubRococo::force_xcm_version(bridge_hub_westend_location(), newer_xcm_version);
// set version for AssetHubWestend on BridgeHubWestend
BridgeHubWestend::force_xcm_version(
ParentThen(Parachain(AssetHubWestend::para_id().into()).into()).into(),
xcm::v3::prelude::XCM_VERSION,
newer_xcm_version,
);

// send XCM from AssetHubRococo - ok
Expand All @@ -164,20 +134,4 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
]
);
});

// TODO: remove this block, when removing `xcm:v2`
{
// set `2` version for remote BridgeHub on BridgeHubRococo, which does not have
// `UniversalOrigin` and `DescendOrigin`
BridgeHubRococo::force_xcm_version(
bridge_hub_westend_location(),
xcm::v2::prelude::XCM_VERSION,
);

// send XCM from AssetHubRococo - ok
assert_ok!(send_asset_from_asset_hub_rococo(destination, (native_token, amount)));
// message is not accepted on the local BridgeHub (`DestinationUnsupported`) because we
// cannot add `UniversalOrigin` and `DescendOrigin`
assert_bridge_hub_rococo_message_accepted(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ fn send_xcm_from_westend_relay_to_rococo_asset_hub_should_fail_on_not_applicable
#[test]
fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
// Initially set only default version on all runtimes
AssetHubRococo::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
BridgeHubRococo::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
BridgeHubWestend::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
AssetHubWestend::force_default_xcm_version(Some(xcm::v2::prelude::XCM_VERSION));
let newer_xcm_version = xcm::prelude::XCM_VERSION;
let older_xcm_version = newer_xcm_version - 1;

AssetHubRococo::force_default_xcm_version(Some(older_xcm_version));
BridgeHubRococo::force_default_xcm_version(Some(older_xcm_version));
BridgeHubWestend::force_default_xcm_version(Some(older_xcm_version));
AssetHubWestend::force_default_xcm_version(Some(older_xcm_version));

// prepare data
let destination = asset_hub_rococo_location();
Expand All @@ -87,42 +90,12 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
);

// set destination version
AssetHubWestend::force_xcm_version(destination.clone(), xcm::v3::prelude::XCM_VERSION);

// TODO: remove this block, when removing `xcm:v2`
{
// send XCM from AssetHubRococo - fails - AssetHubRococo is set to the default/safe `2`
// version, which does not have the `ExportMessage` instruction. If the default `2` is
// changed to `3`, then this assert can go away"
assert_err!(
send_asset_from_asset_hub_westend(destination.clone(), (native_token.clone(), amount)),
DispatchError::Module(sp_runtime::ModuleError {
index: 31,
error: [1, 0, 0, 0],
message: Some("SendFailure")
})
);

// set exact version for BridgeHubWestend to `2` without `ExportMessage` instruction
AssetHubWestend::force_xcm_version(
ParentThen(Parachain(BridgeHubWestend::para_id().into()).into()).into(),
xcm::v2::prelude::XCM_VERSION,
);
// send XCM from AssetHubWestend - fails - `ExportMessage` is not in `2`
assert_err!(
send_asset_from_asset_hub_westend(destination.clone(), (native_token.clone(), amount)),
DispatchError::Module(sp_runtime::ModuleError {
index: 31,
error: [1, 0, 0, 0],
message: Some("SendFailure")
})
);
}
AssetHubWestend::force_xcm_version(destination.clone(), newer_xcm_version);

// set version with `ExportMessage` for BridgeHubWestend
AssetHubWestend::force_xcm_version(
ParentThen(Parachain(BridgeHubWestend::para_id().into()).into()).into(),
xcm::v3::prelude::XCM_VERSION,
newer_xcm_version,
);
// send XCM from AssetHubWestend - ok
assert_ok!(send_asset_from_asset_hub_westend(
Expand All @@ -134,14 +107,11 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
assert_bridge_hub_westend_message_accepted(false);

// set version for remote BridgeHub on BridgeHubWestend
BridgeHubWestend::force_xcm_version(
bridge_hub_rococo_location(),
xcm::v3::prelude::XCM_VERSION,
);
BridgeHubWestend::force_xcm_version(bridge_hub_rococo_location(), newer_xcm_version);
// set version for AssetHubRococo on BridgeHubRococo
BridgeHubRococo::force_xcm_version(
ParentThen(Parachain(AssetHubRococo::para_id().into()).into()).into(),
xcm::v3::prelude::XCM_VERSION,
newer_xcm_version,
);

// send XCM from AssetHubWestend - ok
Expand All @@ -164,20 +134,4 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
]
);
});

// TODO: remove this block, when removing `xcm:v2`
{
// set `2` version for remote BridgeHub on BridgeHubRococo, which does not have
// `UniversalOrigin` and `DescendOrigin`
BridgeHubWestend::force_xcm_version(
bridge_hub_rococo_location(),
xcm::v2::prelude::XCM_VERSION,
);

// send XCM from AssetHubWestend - ok
assert_ok!(send_asset_from_asset_hub_westend(destination, (native_token, amount)));
// message is not accepted on the local BridgeHub (`DestinationUnsupported`) because we
// cannot add `UniversalOrigin` and `DescendOrigin`
assert_bridge_hub_westend_message_accepted(false);
}
}
21 changes: 11 additions & 10 deletions polkadot/xcm/pallet-xcm/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use super::*;
use bounded_collections::{ConstU32, WeakBoundedVec};
use frame_benchmarking::{benchmarks, whitelisted_caller, BenchmarkError, BenchmarkResult};
use frame_support::{assert_ok, weights::Weight};
use frame_system::RawOrigin;
use sp_std::prelude::*;
use xcm::{latest::prelude::*, v2};
use xcm::latest::prelude::*;
use xcm_builder::EnsureDelivery;
use xcm_executor::traits::FeeReason;

Expand Down Expand Up @@ -313,15 +312,17 @@ benchmarks! {
}

notify_target_migration_fail {
let bad_loc: v2::MultiLocation = v2::Junction::Plurality {
id: v2::BodyId::Named(WeakBoundedVec::<u8, ConstU32<32>>::try_from(vec![0; 32])
.expect("vec has a length of 32 bits; qed")),
part: v2::BodyPart::Voice,
}
.into();
let bad_loc = VersionedLocation::from(bad_loc);
let newer_xcm_version = xcm::prelude::XCM_VERSION;
let older_xcm_version = newer_xcm_version - 1;
let bad_location: Location = Plurality {
id: BodyId::Unit,
part: BodyPart::Voice,
}.into();
let bad_location = VersionedLocation::from(bad_location)
.into_version(older_xcm_version)
.expect("Version convertion should work");
let current_version = T::AdvertisedXcmVersion::get();
VersionNotifyTargets::<T>::insert(current_version, bad_loc, (0, Weight::zero(), current_version));
VersionNotifyTargets::<T>::insert(current_version, bad_location, (0, Weight::zero(), current_version));
}: {
crate::Pallet::<T>::check_xcm_version_change(VersionMigrationStage::MigrateAndNotifyOldTargets, Weight::zero());
}
Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/pallet-xcm/src/tests/assets_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn limited_teleport_assets_works() {
)]
);
let versioned_sent = VersionedXcm::from(sent_xcm().into_iter().next().unwrap().1);
let _check_v2_ok: xcm::v2::Xcm<()> = versioned_sent.try_into().unwrap();
let _check_v3_ok: xcm::v3::Xcm<()> = versioned_sent.try_into().unwrap();

let mut last_events = last_events(3).into_iter();
assert_eq!(
Expand Down
Loading

0 comments on commit 4ddcbd4

Please sign in to comment.