Skip to content

Commit

Permalink
XCM v5 (#4826)
Browse files Browse the repository at this point in the history
# Context

This PR aims to introduce XCMv5, for now it's in progress and will be
updated over time.
This branch will serve as a milestone branch for merging in all features
we want to add to XCM, roughly outlined
[here](polkadot-fellows/xcm-format#60).
More features could be added.

## TODO
- [x] Migrate foreign assets from v3 to v4
- [x] Setup v5 skeleton
- [x] Remove XCMv2
- [x] #5390
- [x] #5585
- [x] #5420
- [x] #5876
- [x] #5971
- [x] #6148
- [x] #6228

Fixes #3434 
Fixes #4190
Fixes #5209
Fixes #5241
Fixes #4284

---------

Signed-off-by: Adrian Catangiu <adrian@parity.io>
Co-authored-by: Adrian Catangiu <adrian@parity.io>
Co-authored-by: Andrii <ndk@parity.io>
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Co-authored-by: Joseph Zhao <65984904+programskillforverification@users.noreply.github.com>
Co-authored-by: Nazar Mokrynskyi <nazar@mokrynskyi.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: command-bot <>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Serban Iorga <serban@parity.io>
  • Loading branch information
10 people authored Nov 6, 2024
1 parent ee3a035 commit 9472abb
Show file tree
Hide file tree
Showing 227 changed files with 12,140 additions and 7,048 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bridges/modules/xcm-bridge-hub-router/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ impl InspectMessageQueues for TestToBridgeHubSender {
.iter()
.map(|(location, message)| {
(
VersionedLocation::V4(location.clone()),
vec![VersionedXcm::V4(message.clone())],
VersionedLocation::from(location.clone()),
vec![VersionedXcm::from(message.clone())],
)
})
.collect()
Expand Down
4 changes: 2 additions & 2 deletions bridges/modules/xcm-bridge-hub/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use sp_runtime::{
AccountId32, BuildStorage, StateVersion,
};
use sp_std::cell::RefCell;
use xcm::prelude::*;
use xcm::{latest::ROCOCO_GENESIS_HASH, prelude::*};
use xcm_builder::{
AllowUnpaidExecutionFrom, DispatchBlob, DispatchBlobError, FixedWeightBounds,
InspectMessageQueues, NetworkExportTable, NetworkExportTableItem, ParentIsPreset,
Expand Down Expand Up @@ -160,7 +160,7 @@ parameter_types! {
pub BridgedRelayNetworkLocation: Location = (Parent, GlobalConsensus(BridgedRelayNetwork::get())).into();
pub BridgedRelativeDestination: InteriorLocation = [Parachain(BRIDGED_ASSET_HUB_ID)].into();
pub BridgedUniversalDestination: InteriorLocation = [GlobalConsensus(BridgedRelayNetwork::get()), Parachain(BRIDGED_ASSET_HUB_ID)].into();
pub const NonBridgedRelayNetwork: NetworkId = NetworkId::Rococo;
pub const NonBridgedRelayNetwork: NetworkId = NetworkId::ByGenesis(ROCOCO_GENESIS_HASH);

pub const BridgeDeposit: Balance = 100_000;

Expand Down
3 changes: 2 additions & 1 deletion bridges/primitives/xcm-bridge-hub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,11 @@ impl BridgeLocations {
#[cfg(test)]
mod tests {
use super::*;
use xcm::latest::ROCOCO_GENESIS_HASH;

const LOCAL_NETWORK: NetworkId = Kusama;
const REMOTE_NETWORK: NetworkId = Polkadot;
const UNREACHABLE_NETWORK: NetworkId = Rococo;
const UNREACHABLE_NETWORK: NetworkId = NetworkId::ByGenesis(ROCOCO_GENESIS_HASH);
const SIBLING_PARACHAIN: u32 = 1000;
const LOCAL_BRIDGE_HUB: u32 = 1001;
const REMOTE_PARACHAIN: u32 = 2000;
Expand Down
9 changes: 6 additions & 3 deletions bridges/snowbridge/pallets/inbound-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use sp_runtime::{
BuildStorage, FixedU128, MultiSignature,
};
use sp_std::{convert::From, default::Default};
use xcm::{latest::SendXcm, prelude::*};
use xcm::{
latest::{SendXcm, WESTEND_GENESIS_HASH},
prelude::*,
};
use xcm_executor::AssetsInHolding;

use crate::{self as inbound_queue};
Expand Down Expand Up @@ -113,8 +116,8 @@ parameter_types! {
pub const InitialFund: u128 = 1_000_000_000_000;
pub const InboundQueuePalletInstance: u8 = 80;
pub UniversalLocation: InteriorLocation =
[GlobalConsensus(Westend), Parachain(1002)].into();
pub AssetHubFromEthereum: Location = Location::new(1,[GlobalConsensus(Westend),Parachain(1000)]);
[GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)), Parachain(1002)].into();
pub AssetHubFromEthereum: Location = Location::new(1,[GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),Parachain(1000)]);
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
4 changes: 2 additions & 2 deletions bridges/snowbridge/pallets/inbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ fn test_submit_happy_path() {
.into(),
nonce: 1,
message_id: [
255, 125, 48, 71, 174, 185, 100, 26, 159, 43, 108, 6, 116, 218, 55, 155, 223, 143,
141, 22, 124, 110, 241, 18, 122, 217, 130, 29, 139, 76, 97, 201,
11, 25, 133, 51, 23, 68, 111, 211, 132, 94, 254, 17, 194, 252, 198, 233, 10, 193,
156, 93, 72, 140, 65, 69, 79, 155, 154, 28, 141, 166, 171, 255,
],
fee_burned: 110000000000,
}
Expand Down
2 changes: 1 addition & 1 deletion bridges/snowbridge/pallets/system/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mod benchmarks {
T::Token::mint_into(&caller, amount)?;

let relay_token_asset_id: Location = Location::parent();
let asset = Box::new(VersionedLocation::V4(relay_token_asset_id));
let asset = Box::new(VersionedLocation::from(relay_token_asset_id));
let asset_metadata = AssetMetadata {
name: "wnd".as_bytes().to_vec().try_into().unwrap(),
symbol: "wnd".as_bytes().to_vec().try_into().unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions bridges/snowbridge/pallets/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,12 @@ pub mod pallet {
/// Lookup table for foreign token ID to native location relative to ethereum
#[pallet::storage]
pub type ForeignToNativeId<T: Config> =
StorageMap<_, Blake2_128Concat, TokenId, xcm::v4::Location, OptionQuery>;
StorageMap<_, Blake2_128Concat, TokenId, xcm::v5::Location, OptionQuery>;

/// Lookup table for native location relative to ethereum to foreign token ID
#[pallet::storage]
pub type NativeToForeignId<T: Config> =
StorageMap<_, Blake2_128Concat, xcm::v4::Location, TokenId, OptionQuery>;
StorageMap<_, Blake2_128Concat, xcm::v5::Location, TokenId, OptionQuery>;

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
Expand Down
50 changes: 36 additions & 14 deletions bridges/snowbridge/primitives/core/src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ impl DescribeLocation for DescribeTokenTerminal {
#[cfg(test)]
mod tests {
use crate::TokenIdOf;
use xcm::prelude::{
GeneralIndex, GeneralKey, GlobalConsensus, Junction::*, Location, NetworkId::*,
PalletInstance, Parachain,
use xcm::{
latest::WESTEND_GENESIS_HASH,
prelude::{
GeneralIndex, GeneralKey, GlobalConsensus, Junction::*, Location, NetworkId::ByGenesis,
PalletInstance, Parachain,
},
};
use xcm_executor::traits::ConvertLocation;

Expand All @@ -108,17 +111,24 @@ mod tests {
let token_locations = [
// Relay Chain cases
// Relay Chain relative to Ethereum
Location::new(1, [GlobalConsensus(Westend)]),
Location::new(1, [GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH))]),
// Parachain cases
// Parachain relative to Ethereum
Location::new(1, [GlobalConsensus(Westend), Parachain(2000)]),
Location::new(1, [GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)), Parachain(2000)]),
// Parachain general index
Location::new(1, [GlobalConsensus(Westend), Parachain(2000), GeneralIndex(1)]),
Location::new(
1,
[
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(2000),
GeneralIndex(1),
],
),
// Parachain general key
Location::new(
1,
[
GlobalConsensus(Westend),
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(2000),
GeneralKey { length: 32, data: [0; 32] },
],
Expand All @@ -127,7 +137,7 @@ mod tests {
Location::new(
1,
[
GlobalConsensus(Westend),
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(2000),
AccountKey20 { network: None, key: [0; 20] },
],
Expand All @@ -136,24 +146,36 @@ mod tests {
Location::new(
1,
[
GlobalConsensus(Westend),
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(2000),
AccountId32 { network: None, id: [0; 32] },
],
),
// Parchain Pallet instance cases
// Parachain pallet instance
Location::new(1, [GlobalConsensus(Westend), Parachain(2000), PalletInstance(8)]),
Location::new(
1,
[
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(2000),
PalletInstance(8),
],
),
// Parachain Pallet general index
Location::new(
1,
[GlobalConsensus(Westend), Parachain(2000), PalletInstance(8), GeneralIndex(1)],
[
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(2000),
PalletInstance(8),
GeneralIndex(1),
],
),
// Parachain Pallet general key
Location::new(
1,
[
GlobalConsensus(Westend),
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(2000),
PalletInstance(8),
GeneralKey { length: 32, data: [0; 32] },
Expand All @@ -163,7 +185,7 @@ mod tests {
Location::new(
1,
[
GlobalConsensus(Westend),
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(2000),
PalletInstance(8),
AccountKey20 { network: None, key: [0; 20] },
Expand All @@ -173,7 +195,7 @@ mod tests {
Location::new(
1,
[
GlobalConsensus(Westend),
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(2000),
PalletInstance(8),
AccountId32 { network: None, id: [0; 32] },
Expand Down
3 changes: 1 addition & 2 deletions bridges/snowbridge/primitives/router/src/inbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod tests;

use codec::{Decode, Encode};
use core::marker::PhantomData;
use frame_support::{traits::tokens::Balance as BalanceT, weights::Weight, PalletError};
use frame_support::{traits::tokens::Balance as BalanceT, PalletError};
use scale_info::TypeInfo;
use snowbridge_core::TokenId;
use sp_core::{Get, RuntimeDebug, H160, H256};
Expand Down Expand Up @@ -279,7 +279,6 @@ where
// Call create_asset on foreign assets pallet.
Transact {
origin_kind: OriginKind::Xcm,
require_weight_at_most: Weight::from_parts(400_000_000, 8_000),
call: (
create_call_index,
asset_id,
Expand Down
15 changes: 10 additions & 5 deletions bridges/snowbridge/primitives/router/src/outbound/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use snowbridge_core::{
AgentIdOf,
};
use sp_std::default::Default;
use xcm::prelude::SendError as XcmSendError;
use xcm::{
latest::{ROCOCO_GENESIS_HASH, WESTEND_GENESIS_HASH},
prelude::SendError as XcmSendError,
};

use super::*;

Expand Down Expand Up @@ -61,7 +64,7 @@ impl SendMessageFeeProvider for MockErrOutboundQueue {
pub struct MockTokenIdConvert;
impl MaybeEquivalence<TokenId, Location> for MockTokenIdConvert {
fn convert(_id: &TokenId) -> Option<Location> {
Some(Location::new(1, [GlobalConsensus(Westend)]))
Some(Location::new(1, [GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH))]))
}
fn convert_back(_loc: &Location) -> Option<TokenId> {
None
Expand Down Expand Up @@ -1109,7 +1112,7 @@ fn xcm_converter_transfer_native_token_success() {
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");

let amount = 1000000;
let asset_location = Location::new(1, [GlobalConsensus(Westend)]);
let asset_location = Location::new(1, [GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH))]);
let token_id = TokenIdOf::convert_location(&asset_location).unwrap();

let assets: Assets = vec![Asset { id: AssetId(asset_location), fun: Fungible(amount) }].into();
Expand Down Expand Up @@ -1142,7 +1145,8 @@ fn xcm_converter_transfer_native_token_with_invalid_location_will_fail() {

let amount = 1000000;
// Invalid asset location from a different consensus
let asset_location = Location { parents: 2, interior: [GlobalConsensus(Rococo)].into() };
let asset_location =
Location { parents: 2, interior: [GlobalConsensus(ByGenesis(ROCOCO_GENESIS_HASH))].into() };

let assets: Assets = vec![Asset { id: AssetId(asset_location), fun: Fungible(amount) }].into();
let filter: AssetFilter = assets.clone().into();
Expand Down Expand Up @@ -1221,7 +1225,8 @@ fn exporter_validate_with_invalid_universal_source_does_not_alter_universal_sour
let network = BridgedNetwork::get();
let destination: InteriorLocation = Here.into();

let universal_source: InteriorLocation = [GlobalConsensus(Westend), Parachain(1000)].into();
let universal_source: InteriorLocation =
[GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)), Parachain(1000)].into();

let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
Expand Down
9 changes: 3 additions & 6 deletions bridges/snowbridge/runtime/test-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ use snowbridge_pallet_ethereum_client_fixtures::*;
use sp_core::{Get, H160, U256};
use sp_keyring::AccountKeyring::*;
use sp_runtime::{traits::Header, AccountId32, DigestItem, SaturatedConversion, Saturating};
use xcm::{
latest::prelude::*,
v3::Error::{self, Barrier},
};
use xcm::latest::prelude::*;
use xcm_executor::XcmExecutor;

type RuntimeHelper<Runtime, AllPalletsWithoutSystem = ()> =
Expand Down Expand Up @@ -374,7 +371,7 @@ pub fn send_unpaid_transfer_token_message<Runtime, XcmConfig>(
Weight::zero(),
);
// check error is barrier
assert_err!(outcome.ensure_complete(), Barrier);
assert_err!(outcome.ensure_complete(), XcmError::Barrier);
});
}

Expand All @@ -388,7 +385,7 @@ pub fn send_transfer_token_message_failure<Runtime, XcmConfig>(
weth_contract_address: H160,
destination_address: H160,
fee_amount: u128,
expected_error: Error,
expected_error: XcmError,
) where
Runtime: frame_system::Config
+ pallet_balances::Config
Expand Down
2 changes: 1 addition & 1 deletion cumulus/pallets/xcmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ impl<T: Config> InspectMessageQueues for Pallet<T> {
}

(
VersionedLocation::V4((Parent, Parachain(para_id.into())).into()),
VersionedLocation::from(Location::new(1, Parachain(para_id.into()))),
decoded_messages,
)
})
Expand Down
Loading

0 comments on commit 9472abb

Please sign in to comment.