# 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 <kungfukeith11@gmail.com>
This commit is contained in:
Francisco Aguirre
2024-01-16 19:18:04 +01:00
committed by GitHub
parent ec7bfae00a
commit 8428f678fe
255 changed files with 12425 additions and 6726 deletions
+4 -4
View File
@@ -135,7 +135,7 @@ pub mod pallet {
/// The origin that is allowed to resume or suspend the XCMP queue.
type ControllerOrigin: EnsureOrigin<Self::RuntimeOrigin>;
/// The conversion function used to attempt to convert an XCM `MultiLocation` origin to a
/// The conversion function used to attempt to convert an XCM `Location` origin to a
/// superuser origin.
type ControllerOriginConverter: ConvertOrigin<Self::RuntimeOrigin>;
@@ -903,14 +903,14 @@ impl<T: Config> SendXcm for Pallet<T> {
type Ticket = (ParaId, VersionedXcm<()>);
fn validate(
dest: &mut Option<MultiLocation>,
dest: &mut Option<Location>,
msg: &mut Option<Xcm<()>>,
) -> SendResult<(ParaId, VersionedXcm<()>)> {
let d = dest.take().ok_or(SendError::MissingArgument)?;
match &d {
match d.unpack() {
// An HRMP message for a sibling parachain.
MultiLocation { parents: 1, interior: X1(Parachain(id)) } => {
(1, [Parachain(id)]) => {
let xcm = msg.take().ok_or(SendError::MissingArgument)?;
let id = ParaId::from(*id);
let price = T::PriceForSiblingDelivery::price_for_delivery(id, &xcm);
+8 -11
View File
@@ -124,8 +124,8 @@ impl cumulus_pallet_parachain_system::Config for Test {
}
parameter_types! {
pub const RelayChain: MultiLocation = MultiLocation::parent();
pub UniversalLocation: InteriorMultiLocation = X1(Parachain(1u32));
pub const RelayChain: Location = Location::parent();
pub UniversalLocation: InteriorLocation = [Parachain(1u32)].into();
pub UnitWeightCost: Weight = Weight::from_parts(1_000_000, 1024);
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsIntoHolding: u32 = 64;
@@ -138,7 +138,7 @@ pub type LocalAssetTransactor = CurrencyAdapter<
Balances,
// Use this currency when it is a fungible asset matching the given location or name:
IsConcrete<RelayChain>,
// Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:
// Do a simple punn to convert an AccountId32 Location into a native chain account ID:
LocationToAccountId,
// Our chain's account ID type (we can't get away without mentioning it explicitly):
AccountId,
@@ -187,17 +187,14 @@ impl<RuntimeOrigin: OriginTrait> ConvertOrigin<RuntimeOrigin>
for SystemParachainAsSuperuser<RuntimeOrigin>
{
fn convert_origin(
origin: impl Into<MultiLocation>,
origin: impl Into<Location>,
kind: OriginKind,
) -> Result<RuntimeOrigin, MultiLocation> {
) -> Result<RuntimeOrigin, Location> {
let origin = origin.into();
if kind == OriginKind::Superuser &&
matches!(
origin,
MultiLocation {
parents: 1,
interior: X1(Parachain(id)),
} if ParaId::from(id).is_system(),
origin.unpack(),
(1, [Parachain(id)]) if ParaId::from(*id).is_system(),
) {
Ok(RuntimeOrigin::root())
} else {
@@ -256,7 +253,7 @@ impl<T: OnQueueChanged<ParaId>> EnqueueMessage<ParaId> for EnqueueToLocalStorage
parameter_types! {
/// The asset ID for the asset that we use to pay for message delivery fees.
pub FeeAssetId: AssetId = Concrete(RelayChain::get());
pub FeeAssetId: AssetId = AssetId(RelayChain::get());
/// The base fee for the message delivery fees.
pub const BaseDeliveryFee: Balance = 300_000_000;
/// The fee per byte
+27 -27
View File
@@ -333,11 +333,11 @@ struct OkFixedXcmHashWithAssertingRequiredInputsSender;
impl OkFixedXcmHashWithAssertingRequiredInputsSender {
const FIXED_XCM_HASH: [u8; 32] = [9; 32];
fn fixed_delivery_asset() -> MultiAssets {
MultiAssets::new()
fn fixed_delivery_asset() -> Assets {
Assets::new()
}
fn expected_delivery_result() -> Result<(XcmHash, MultiAssets), SendError> {
fn expected_delivery_result() -> Result<(XcmHash, Assets), SendError> {
Ok((Self::FIXED_XCM_HASH, Self::fixed_delivery_asset()))
}
}
@@ -345,7 +345,7 @@ impl SendXcm for OkFixedXcmHashWithAssertingRequiredInputsSender {
type Ticket = ();
fn validate(
destination: &mut Option<MultiLocation>,
destination: &mut Option<Location>,
message: &mut Option<Xcm<()>>,
) -> SendResult<Self::Ticket> {
assert!(destination.is_some());
@@ -392,8 +392,8 @@ fn xcmp_queue_consumes_dest_and_msg_on_ok_validate() {
let message = Xcm(vec![Trap(5)]);
// XcmpQueue - check dest/msg is valid
let dest = (Parent, X1(Parachain(5555)));
let mut dest_wrapper = Some(dest.into());
let dest: Location = (Parent, Parachain(5555)).into();
let mut dest_wrapper = Some(dest.clone());
let mut msg_wrapper = Some(message.clone());
new_test_ext().execute_with(|| {
@@ -416,7 +416,7 @@ fn xcmp_queue_consumes_dest_and_msg_on_ok_validate() {
#[test]
fn xcmp_queue_validate_nested_xcm_works() {
let dest = (Parent, X1(Parachain(5555)));
let dest = (Parent, Parachain(5555));
// Message that is not too deeply nested:
let mut good = Xcm(vec![ClearOrigin]);
for _ in 0..MAX_XCM_DECODE_DEPTH - 1 {
@@ -441,7 +441,7 @@ fn xcmp_queue_validate_nested_xcm_works() {
#[test]
fn send_xcm_nested_works() {
let dest = (Parent, X1(Parachain(HRMP_PARA_ID)));
let dest = (Parent, Parachain(HRMP_PARA_ID));
// Message that is not too deeply nested:
let mut good = Xcm(vec![ClearOrigin]);
for _ in 0..MAX_XCM_DECODE_DEPTH - 1 {
@@ -455,7 +455,7 @@ fn send_xcm_nested_works() {
XcmpQueue::take_outbound_messages(usize::MAX),
vec![(
HRMP_PARA_ID.into(),
(XcmpMessageFormat::ConcatenatedVersionedXcm, VersionedXcm::V3(good.clone()))
(XcmpMessageFormat::ConcatenatedVersionedXcm, VersionedXcm::V4(good.clone()))
.encode(),
)]
);
@@ -474,7 +474,7 @@ fn hrmp_signals_are_prioritized() {
let message = Xcm(vec![Trap(5)]);
let sibling_para_id = ParaId::from(12345);
let dest = (Parent, X1(Parachain(sibling_para_id.into())));
let dest = (Parent, Parachain(sibling_para_id.into()));
let mut dest_wrapper = Some(dest.into());
let mut msg_wrapper = Some(message.clone());
@@ -511,7 +511,7 @@ fn hrmp_signals_are_prioritized() {
// Without a signal we get the messages in order:
let mut expected_msg = XcmpMessageFormat::ConcatenatedVersionedXcm.encode();
for _ in 0..31 {
expected_msg.extend(VersionedXcm::V3(message.clone()).encode());
expected_msg.extend(VersionedXcm::V4(message.clone()).encode());
}
hypothetically!({
@@ -590,7 +590,7 @@ fn take_first_concatenated_xcm_good_recursion_depth_works() {
for _ in 0..MAX_XCM_DECODE_DEPTH - 1 {
good = Xcm(vec![SetAppendix(good)]);
}
let good = VersionedXcm::V3(good);
let good = VersionedXcm::V4(good);
let page = good.encode();
assert_ok!(XcmpQueue::take_first_concatenated_xcm(&mut &page[..], &mut WeightMeter::new()));
@@ -603,7 +603,7 @@ fn take_first_concatenated_xcm_good_bad_depth_errors() {
for _ in 0..MAX_XCM_DECODE_DEPTH {
bad = Xcm(vec![SetAppendix(bad)]);
}
let bad = VersionedXcm::V3(bad);
let bad = VersionedXcm::V4(bad);
let page = bad.encode();
assert_err!(
@@ -699,12 +699,12 @@ fn lazy_migration_noop_when_out_of_weight() {
fn xcmp_queue_send_xcm_works() {
new_test_ext().execute_with(|| {
let sibling_para_id = ParaId::from(12345);
let dest = (Parent, X1(Parachain(sibling_para_id.into()))).into();
let dest: Location = (Parent, Parachain(sibling_para_id.into())).into();
let msg = Xcm(vec![ClearOrigin]);
// try to send without opened HRMP channel to the sibling_para_id
assert_eq!(
send_xcm::<XcmpQueue>(dest, msg.clone()),
send_xcm::<XcmpQueue>(dest.clone(), msg.clone()),
Err(SendError::Transport("NoChannel")),
);
@@ -728,7 +728,7 @@ fn xcmp_queue_send_xcm_works() {
fn xcmp_queue_send_too_big_xcm_fails() {
new_test_ext().execute_with(|| {
let sibling_para_id = ParaId::from(12345);
let dest = (Parent, X1(Parachain(sibling_para_id.into()))).into();
let dest = (Parent, Parachain(sibling_para_id.into())).into();
let max_message_size = 100_u32;
@@ -774,7 +774,7 @@ fn verify_fee_factor_increase_and_decrease() {
use sp_runtime::FixedU128;
let sibling_para_id = ParaId::from(12345);
let destination = (Parent, Parachain(sibling_para_id.into())).into();
let destination: Location = (Parent, Parachain(sibling_para_id.into())).into();
let xcm = Xcm(vec![ClearOrigin; 100]);
let versioned_xcm = VersionedXcm::from(xcm.clone());
let mut xcmp_message = XcmpMessageFormat::ConcatenatedVersionedXcm.encode();
@@ -799,15 +799,15 @@ fn verify_fee_factor_increase_and_decrease() {
// Fee factor is only increased in `send_fragment`, which is called by `send_xcm`.
// When queue is not congested, fee factor doesn't change.
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 104
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 208
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 312
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 416
assert_ok!(send_xcm::<XcmpQueue>(destination.clone(), xcm.clone())); // Size 104
assert_ok!(send_xcm::<XcmpQueue>(destination.clone(), xcm.clone())); // Size 208
assert_ok!(send_xcm::<XcmpQueue>(destination.clone(), xcm.clone())); // Size 312
assert_ok!(send_xcm::<XcmpQueue>(destination.clone(), xcm.clone())); // Size 416
assert_eq!(DeliveryFeeFactor::<Test>::get(sibling_para_id), initial);
// Sending the message right now is cheap
let (_, delivery_fees) =
validate_send::<XcmpQueue>(destination, xcm.clone()).expect("message can be sent; qed");
let (_, delivery_fees) = validate_send::<XcmpQueue>(destination.clone(), xcm.clone())
.expect("message can be sent; qed");
let Fungible(delivery_fee_amount) = delivery_fees.inner()[0].fun else {
unreachable!("asset is fungible; qed");
};
@@ -817,18 +817,18 @@ fn verify_fee_factor_increase_and_decrease() {
// When we get to half of `max_total_size`, because `THRESHOLD_FACTOR` is 2,
// then the fee factor starts to increase.
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 520
assert_ok!(send_xcm::<XcmpQueue>(destination.clone(), xcm.clone())); // Size 520
assert_eq!(DeliveryFeeFactor::<Test>::get(sibling_para_id), FixedU128::from_float(1.05));
for _ in 0..12 {
// We finish at size 929
assert_ok!(send_xcm::<XcmpQueue>(destination, smaller_xcm.clone()));
assert_ok!(send_xcm::<XcmpQueue>(destination.clone(), smaller_xcm.clone()));
}
assert!(DeliveryFeeFactor::<Test>::get(sibling_para_id) > FixedU128::from_float(1.88));
// Sending the message right now is expensive
let (_, delivery_fees) =
validate_send::<XcmpQueue>(destination, xcm.clone()).expect("message can be sent; qed");
let (_, delivery_fees) = validate_send::<XcmpQueue>(destination.clone(), xcm.clone())
.expect("message can be sent; qed");
let Fungible(delivery_fee_amount) = delivery_fees.inner()[0].fun else {
unreachable!("asset is fungible; qed");
};