mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 06:21:02 +00:00
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 <kungfukeith11@gmail.com>
This commit is contained in:
committed by
GitHub
parent
ec7bfae00a
commit
8428f678fe
+2
-2
@@ -336,9 +336,9 @@ where
|
||||
(),
|
||||
>(
|
||||
LaneId::default(),
|
||||
vec![xcm::v3::Instruction::<()>::ClearOrigin; 1_024].into(),
|
||||
vec![Instruction::<()>::ClearOrigin; 1_024].into(),
|
||||
1,
|
||||
X2(GlobalConsensus(Polkadot), Parachain(1_000)),
|
||||
[GlobalConsensus(Polkadot), Parachain(1_000)].into(),
|
||||
1u32.into(),
|
||||
);
|
||||
|
||||
|
||||
@@ -418,9 +418,9 @@ where
|
||||
(),
|
||||
>(
|
||||
LaneId::default(),
|
||||
vec![xcm::v3::Instruction::<()>::ClearOrigin; 1_024].into(),
|
||||
vec![Instruction::<()>::ClearOrigin; 1_024].into(),
|
||||
1,
|
||||
X2(GlobalConsensus(Polkadot), Parachain(1_000)),
|
||||
[GlobalConsensus(Polkadot), Parachain(1_000)].into(),
|
||||
1,
|
||||
5,
|
||||
1_000,
|
||||
|
||||
@@ -230,7 +230,7 @@ pub fn relayed_incoming_message_works<Runtime, AllPalletsWithoutSystem, MPI>(
|
||||
prepare_message_proof_import: impl FnOnce(
|
||||
Runtime::AccountId,
|
||||
Runtime::InboundRelayer,
|
||||
InteriorMultiLocation,
|
||||
InteriorLocation,
|
||||
MessageNonce,
|
||||
Xcm<()>,
|
||||
) -> CallsAndVerifiers<Runtime>,
|
||||
@@ -276,21 +276,21 @@ pub fn relayed_incoming_message_works<Runtime, AllPalletsWithoutSystem, MPI>(
|
||||
|
||||
// set up relayer details and proofs
|
||||
|
||||
let message_destination =
|
||||
X2(GlobalConsensus(local_relay_chain_id), Parachain(sibling_parachain_id));
|
||||
let message_destination: InteriorLocation =
|
||||
[GlobalConsensus(local_relay_chain_id), Parachain(sibling_parachain_id)].into();
|
||||
// some random numbers (checked by test)
|
||||
let message_nonce = 1;
|
||||
|
||||
let xcm = vec![xcm::v3::Instruction::<()>::ClearOrigin; 42];
|
||||
let xcm = vec![Instruction::<()>::ClearOrigin; 42];
|
||||
let expected_dispatch = xcm::latest::Xcm::<()>({
|
||||
let mut expected_instructions = xcm.clone();
|
||||
// dispatch prepends bridge pallet instance
|
||||
expected_instructions.insert(
|
||||
0,
|
||||
DescendOrigin(X1(PalletInstance(
|
||||
DescendOrigin([PalletInstance(
|
||||
<pallet_bridge_messages::Pallet<Runtime, MPI> as PalletInfoAccess>::index()
|
||||
as u8,
|
||||
))),
|
||||
)].into()),
|
||||
);
|
||||
expected_instructions
|
||||
});
|
||||
|
||||
@@ -319,8 +319,8 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works<
|
||||
>,
|
||||
export_message_instruction: fn() -> Instruction<XcmConfig::RuntimeCall>,
|
||||
expected_lane_id: LaneId,
|
||||
existential_deposit: Option<MultiAsset>,
|
||||
maybe_paid_export_message: Option<MultiAsset>,
|
||||
existential_deposit: Option<Asset>,
|
||||
maybe_paid_export_message: Option<Asset>,
|
||||
prepare_configuration: impl Fn(),
|
||||
) where
|
||||
Runtime: BasicParachainRuntime + BridgeMessagesConfig<MessagesPalletInstance>,
|
||||
@@ -328,7 +328,7 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works<
|
||||
MessagesPalletInstance: 'static,
|
||||
{
|
||||
assert_ne!(runtime_para_id, sibling_parachain_id);
|
||||
let sibling_parachain_location = MultiLocation::new(1, Parachain(sibling_parachain_id));
|
||||
let sibling_parachain_location = Location::new(1, [Parachain(sibling_parachain_id)]);
|
||||
|
||||
run_test::<Runtime, _>(collator_session_key, runtime_para_id, vec![], || {
|
||||
prepare_configuration();
|
||||
@@ -361,7 +361,7 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works<
|
||||
.expect("deposited fee");
|
||||
|
||||
Xcm(vec![
|
||||
WithdrawAsset(MultiAssets::from(vec![fee.clone()])),
|
||||
WithdrawAsset(Assets::from(vec![fee.clone()])),
|
||||
BuyExecution { fees: fee, weight_limit: Unlimited },
|
||||
export_message_instruction(),
|
||||
])
|
||||
@@ -373,12 +373,13 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works<
|
||||
};
|
||||
|
||||
// execute XCM
|
||||
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
assert_ok!(XcmExecutor::<XcmConfig>::execute_xcm(
|
||||
let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
assert_ok!(XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
sibling_parachain_location,
|
||||
xcm,
|
||||
hash,
|
||||
&mut hash,
|
||||
RuntimeHelper::<Runtime>::xcm_max_weight(XcmReceivedFrom::Sibling),
|
||||
Weight::zero(),
|
||||
)
|
||||
.ensure_complete());
|
||||
|
||||
@@ -446,9 +447,9 @@ pub fn message_dispatch_routing_works<
|
||||
NetworkDistanceAsParentCount: Get<u8>,
|
||||
{
|
||||
struct NetworkWithParentCount<N, C>(core::marker::PhantomData<(N, C)>);
|
||||
impl<N: Get<NetworkId>, C: Get<u8>> Get<MultiLocation> for NetworkWithParentCount<N, C> {
|
||||
fn get() -> MultiLocation {
|
||||
MultiLocation { parents: C::get(), interior: X1(GlobalConsensus(N::get())) }
|
||||
impl<N: Get<NetworkId>, C: Get<u8>> Get<Location> for NetworkWithParentCount<N, C> {
|
||||
fn get() -> Location {
|
||||
Location::new(C::get(), [GlobalConsensus(N::get())])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -495,7 +496,7 @@ pub fn message_dispatch_routing_works<
|
||||
BridgedNetwork,
|
||||
NetworkWithParentCount<RuntimeNetwork, NetworkDistanceAsParentCount>,
|
||||
AlwaysLatest,
|
||||
>((RuntimeNetwork::get(), X1(Parachain(sibling_parachain_id))));
|
||||
>((RuntimeNetwork::get(), [Parachain(sibling_parachain_id)].into()));
|
||||
|
||||
// 2.1. WITHOUT opened hrmp channel -> RoutingError
|
||||
let result =
|
||||
@@ -565,52 +566,43 @@ where
|
||||
{
|
||||
// data here are not relevant for weighing
|
||||
let mut xcm = Xcm(vec![
|
||||
WithdrawAsset(MultiAssets::from(vec![MultiAsset {
|
||||
id: Concrete(MultiLocation { parents: 1, interior: Here }),
|
||||
WithdrawAsset(Assets::from(vec![Asset {
|
||||
id: AssetId(Location::new(1, [])),
|
||||
fun: Fungible(34333299),
|
||||
}])),
|
||||
BuyExecution {
|
||||
fees: MultiAsset {
|
||||
id: Concrete(MultiLocation { parents: 1, interior: Here }),
|
||||
fun: Fungible(34333299),
|
||||
},
|
||||
fees: Asset { id: AssetId(Location::new(1, [])), fun: Fungible(34333299) },
|
||||
weight_limit: Unlimited,
|
||||
},
|
||||
ExportMessage {
|
||||
network: Polkadot,
|
||||
destination: X1(Parachain(1000)),
|
||||
destination: [Parachain(1000)].into(),
|
||||
xcm: Xcm(vec![
|
||||
ReserveAssetDeposited(MultiAssets::from(vec![MultiAsset {
|
||||
id: Concrete(MultiLocation {
|
||||
parents: 2,
|
||||
interior: X1(GlobalConsensus(Kusama)),
|
||||
}),
|
||||
ReserveAssetDeposited(Assets::from(vec![Asset {
|
||||
id: AssetId(Location::new(2, [GlobalConsensus(Kusama)])),
|
||||
fun: Fungible(1000000000000),
|
||||
}])),
|
||||
ClearOrigin,
|
||||
BuyExecution {
|
||||
fees: MultiAsset {
|
||||
id: Concrete(MultiLocation {
|
||||
parents: 2,
|
||||
interior: X1(GlobalConsensus(Kusama)),
|
||||
}),
|
||||
fees: Asset {
|
||||
id: AssetId(Location::new(2, [GlobalConsensus(Kusama)])),
|
||||
fun: Fungible(1000000000000),
|
||||
},
|
||||
weight_limit: Unlimited,
|
||||
},
|
||||
DepositAsset {
|
||||
assets: Wild(AllCounted(1)),
|
||||
beneficiary: MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(xcm::latest::prelude::AccountId32 {
|
||||
beneficiary: Location::new(
|
||||
0,
|
||||
[xcm::latest::prelude::AccountId32 {
|
||||
network: None,
|
||||
id: [
|
||||
212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159,
|
||||
214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165,
|
||||
109, 162, 125,
|
||||
],
|
||||
}),
|
||||
},
|
||||
}],
|
||||
),
|
||||
},
|
||||
SetTopic([
|
||||
116, 82, 194, 132, 171, 114, 217, 165, 23, 37, 161, 177, 165, 179, 247, 114,
|
||||
@@ -618,10 +610,7 @@ where
|
||||
]),
|
||||
]),
|
||||
},
|
||||
DepositAsset {
|
||||
assets: Wild(All),
|
||||
beneficiary: MultiLocation { parents: 1, interior: X1(Parachain(1000)) },
|
||||
},
|
||||
DepositAsset { assets: Wild(All), beneficiary: Location::new(1, [Parachain(1000)]) },
|
||||
SetTopic([
|
||||
36, 224, 250, 165, 82, 195, 67, 110, 160, 170, 140, 87, 217, 62, 201, 164, 42, 98, 219,
|
||||
157, 124, 105, 248, 25, 131, 218, 199, 36, 109, 173, 100, 122,
|
||||
|
||||
@@ -37,10 +37,10 @@ use xcm_executor::traits::{validate_export, ExportXcm};
|
||||
|
||||
pub fn prepare_inbound_xcm<InnerXcmRuntimeCall>(
|
||||
xcm_message: Xcm<InnerXcmRuntimeCall>,
|
||||
destination: InteriorMultiLocation,
|
||||
destination: InteriorLocation,
|
||||
) -> Vec<u8> {
|
||||
let location = xcm::VersionedInteriorMultiLocation::V3(destination);
|
||||
let xcm = xcm::VersionedXcm::<InnerXcmRuntimeCall>::V3(xcm_message);
|
||||
let location = xcm::VersionedInteriorLocation::V4(destination);
|
||||
let xcm = xcm::VersionedXcm::<InnerXcmRuntimeCall>::V4(xcm_message);
|
||||
// this is the `BridgeMessage` from polkadot xcm builder, but it has no constructor
|
||||
// or public fields, so just tuple
|
||||
// (double encoding, because `.encode()` is called on original Xcm BLOB when it is pushed
|
||||
@@ -101,7 +101,7 @@ macro_rules! grab_haul_blob (
|
||||
/// which are transferred over bridge.
|
||||
pub(crate) fn simulate_message_exporter_on_bridged_chain<
|
||||
SourceNetwork: Get<NetworkId>,
|
||||
DestinationNetwork: Get<MultiLocation>,
|
||||
DestinationNetwork: Get<Location>,
|
||||
DestinationVersion: GetVersion,
|
||||
>(
|
||||
(destination_network, destination_junctions): (NetworkId, Junctions),
|
||||
@@ -109,8 +109,8 @@ pub(crate) fn simulate_message_exporter_on_bridged_chain<
|
||||
grab_haul_blob!(GrabbingHaulBlob, GRABBED_HAUL_BLOB_PAYLOAD);
|
||||
|
||||
// lets pretend that some parachain on bridged chain exported the message
|
||||
let universal_source_on_bridged_chain =
|
||||
X2(GlobalConsensus(SourceNetwork::get()), Parachain(5678));
|
||||
let universal_source_on_bridged_chain: Junctions =
|
||||
[GlobalConsensus(SourceNetwork::get()), Parachain(5678)].into();
|
||||
let channel = 1_u32;
|
||||
|
||||
// simulate XCM message export
|
||||
|
||||
Reference in New Issue
Block a user