mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 15:01:06 +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
@@ -38,7 +38,7 @@ use frame_support::weights::Weight;
|
||||
use pallet_bridge_messages::benchmarking::{MessageDeliveryProofParams, MessageProofParams};
|
||||
use sp_runtime::traits::{Header, Zero};
|
||||
use sp_std::prelude::*;
|
||||
use xcm::v3::prelude::*;
|
||||
use xcm::latest::prelude::*;
|
||||
|
||||
/// Prepare inbound bridge message according to given message proof parameters.
|
||||
fn prepare_inbound_message(
|
||||
@@ -266,19 +266,19 @@ where
|
||||
/// Returns callback which generates `BridgeMessage` from Polkadot XCM builder based on
|
||||
/// `expected_message_size` for benchmark.
|
||||
pub fn generate_xcm_builder_bridge_message_sample(
|
||||
destination: InteriorMultiLocation,
|
||||
destination: InteriorLocation,
|
||||
) -> impl Fn(usize) -> MessagePayload {
|
||||
move |expected_message_size| -> MessagePayload {
|
||||
// For XCM bridge hubs, it is the message that
|
||||
// will be pushed further to some XCM queue (XCMP/UMP)
|
||||
let location = xcm::VersionedInteriorMultiLocation::V3(destination);
|
||||
let location = xcm::VersionedInteriorLocation::V4(destination.clone());
|
||||
let location_encoded_size = location.encoded_size();
|
||||
|
||||
// we don't need to be super-precise with `expected_size` here
|
||||
let xcm_size = expected_message_size.saturating_sub(location_encoded_size);
|
||||
let xcm_data_size = xcm_size.saturating_sub(
|
||||
// minus empty instruction size
|
||||
xcm::v3::Instruction::<()>::ExpectPallet {
|
||||
Instruction::<()>::ExpectPallet {
|
||||
index: 0,
|
||||
name: vec![],
|
||||
module_name: vec![],
|
||||
@@ -294,8 +294,8 @@ pub fn generate_xcm_builder_bridge_message_sample(
|
||||
expected_message_size, location_encoded_size, xcm_size, xcm_data_size,
|
||||
);
|
||||
|
||||
let xcm = xcm::VersionedXcm::<()>::V3(
|
||||
vec![xcm::v3::Instruction::<()>::ExpectPallet {
|
||||
let xcm = xcm::VersionedXcm::<()>::V4(
|
||||
vec![Instruction::<()>::ExpectPallet {
|
||||
index: 0,
|
||||
name: vec![42; xcm_data_size],
|
||||
module_name: vec![],
|
||||
|
||||
@@ -123,14 +123,14 @@ impl<
|
||||
#[cfg_attr(feature = "std", derive(Debug, Eq, PartialEq))]
|
||||
pub struct SenderAndLane {
|
||||
/// Sending chain relative location.
|
||||
pub location: MultiLocation,
|
||||
pub location: Location,
|
||||
/// Message lane, used by the sending chain.
|
||||
pub lane: LaneId,
|
||||
}
|
||||
|
||||
impl SenderAndLane {
|
||||
/// Create new object using provided location and lane.
|
||||
pub fn new(location: MultiLocation, lane: LaneId) -> Self {
|
||||
pub fn new(location: Location, lane: LaneId) -> Self {
|
||||
SenderAndLane { location, lane }
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,7 @@ pub struct XcmBlobHaulerAdapter<XcmBlobHauler, Lanes>(
|
||||
|
||||
impl<
|
||||
H: XcmBlobHauler,
|
||||
Lanes: Get<sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))>>,
|
||||
Lanes: Get<sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))>>,
|
||||
> OnMessagesDelivered for XcmBlobHaulerAdapter<H, Lanes>
|
||||
{
|
||||
fn on_messages_delivered(lane: LaneId, enqueued_messages: MessageNonce) {
|
||||
@@ -288,7 +288,7 @@ impl<H: XcmBlobHauler> LocalXcmQueueManager<H> {
|
||||
/// Send congested signal to the `sending_chain_location`.
|
||||
fn send_congested_signal(sender_and_lane: &SenderAndLane) -> Result<(), SendError> {
|
||||
if let Some(msg) = H::CongestedMessage::get() {
|
||||
send_xcm::<H::ToSourceChainSender>(sender_and_lane.location, msg)?;
|
||||
send_xcm::<H::ToSourceChainSender>(sender_and_lane.location.clone(), msg)?;
|
||||
OutboundLanesCongestedSignals::<H::Runtime, H::MessagesInstance>::insert(
|
||||
sender_and_lane.lane,
|
||||
true,
|
||||
@@ -300,7 +300,7 @@ impl<H: XcmBlobHauler> LocalXcmQueueManager<H> {
|
||||
/// Send `uncongested` signal to the `sending_chain_location`.
|
||||
fn send_uncongested_signal(sender_and_lane: &SenderAndLane) -> Result<(), SendError> {
|
||||
if let Some(msg) = H::UncongestedMessage::get() {
|
||||
send_xcm::<H::ToSourceChainSender>(sender_and_lane.location, msg)?;
|
||||
send_xcm::<H::ToSourceChainSender>(sender_and_lane.location.clone(), msg)?;
|
||||
OutboundLanesCongestedSignals::<H::Runtime, H::MessagesInstance>::remove(
|
||||
sender_and_lane.lane,
|
||||
);
|
||||
@@ -315,10 +315,10 @@ impl<H: XcmBlobHauler> LocalXcmQueueManager<H> {
|
||||
pub struct XcmVersionOfDestAndRemoteBridge<Version, RemoteBridge>(
|
||||
sp_std::marker::PhantomData<(Version, RemoteBridge)>,
|
||||
);
|
||||
impl<Version: GetVersion, RemoteBridge: Get<MultiLocation>> GetVersion
|
||||
impl<Version: GetVersion, RemoteBridge: Get<Location>> GetVersion
|
||||
for XcmVersionOfDestAndRemoteBridge<Version, RemoteBridge>
|
||||
{
|
||||
fn get_version_for(dest: &MultiLocation) -> Option<XcmVersion> {
|
||||
fn get_version_for(dest: &Location) -> Option<XcmVersion> {
|
||||
let dest_version = Version::get_version_for(dest);
|
||||
let bridge_hub_version = Version::get_version_for(&RemoteBridge::get());
|
||||
|
||||
@@ -342,11 +342,11 @@ mod tests {
|
||||
|
||||
parameter_types! {
|
||||
pub TestSenderAndLane: SenderAndLane = SenderAndLane {
|
||||
location: MultiLocation::new(1, X1(Parachain(1000))),
|
||||
location: Location::new(1, [Parachain(1000)]),
|
||||
lane: TEST_LANE_ID,
|
||||
};
|
||||
pub TestLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))> = sp_std::vec![
|
||||
(TestSenderAndLane::get(), (NetworkId::ByGenesis([0; 32]), InteriorMultiLocation::Here))
|
||||
pub TestLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))> = sp_std::vec![
|
||||
(TestSenderAndLane::get(), (NetworkId::ByGenesis([0; 32]), InteriorLocation::Here))
|
||||
];
|
||||
pub DummyXcmMessage: Xcm<()> = Xcm::new();
|
||||
}
|
||||
@@ -363,7 +363,7 @@ mod tests {
|
||||
type Ticket = ();
|
||||
|
||||
fn validate(
|
||||
_destination: &mut Option<MultiLocation>,
|
||||
_destination: &mut Option<Location>,
|
||||
_message: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<Self::Ticket> {
|
||||
Ok(((), Default::default()))
|
||||
|
||||
Reference in New Issue
Block a user