Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
XCM v1 (#2815)
Browse files Browse the repository at this point in the history
* MultiAsset TWO

* Draft next MultiAsset API.

* XCM core builds

* XCM Executor builds

* XCM Builder builds

* API changes making their way throughout

* Some TODOs

* Further build fixes

* Basic compile builds

* First test fixed

* All executor tests fixed

* Typo

* Optimize subsume_assets and add test

* Optimize checked_sub

* XCM Builder first test fixed

* Fix builder tests

* Fix doc test

* fix some doc tests

* spelling

* named fields for AllOf

* Update xcm/src/v0/multiasset.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Update xcm/src/v0/multiasset.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Update xcm/src/v0/multiasset.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Update xcm/src/v0/multiasset.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Reformat

* Move to XCM version 1

* Spelling

* warnings

* Replace some more v0->v1s

* warnings

* format

* Add max_assets param

* building

* test fixes

* tests

* another test

* final test

* tests

* Rename Null -> Here

* Introduce

* More ergonomics

* More ergonomics

* test fix

* test fixes

* docs

* BuyExecution includes

* Fix XCM extrinsics

* fmt

* Make Vec<MultiAsset>/MultiAssets conversions safe

* More MultiAssets conversion safety

* spelling

* fix doc test

* Apply suggestions from code review

Co-authored-by: Amar Singh <asinghchrony@protonmail.com>

* Apply suggestions from code review

Co-authored-by: Amar Singh <asinghchrony@protonmail.com>

* fmt

* Add v0, remove VersionedMultiAsset

* Remove VersionedMultiLocation

* Update xcm/src/v1/order.rs

Co-authored-by: Amar Singh <asinghchrony@protonmail.com>

* Update xcm/src/v1/mod.rs

Co-authored-by: Amar Singh <asinghchrony@protonmail.com>

* XCM v0 backwards compatibility

* Full compatibility

* fmt

* Update xcm/pallet-xcm/src/lib.rs

* Update xcm/src/v0/order.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Tweaks to versioning system

* Fixes

* fmt

* Update xcm/xcm-executor/src/assets.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update xcm/xcm-executor/src/assets.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Grumbles

* Update xcm/src/v1/multiasset.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* fmt

* Update xcm/src/v1/multiasset.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update xcm/src/v1/multiasset.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Fixes

* Formatting

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
Co-authored-by: Amar Singh <asinghchrony@protonmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
  • Loading branch information
3 people authored and gavofyork committed Sep 1, 2021
1 parent bfa0360 commit 39ed458
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 51 deletions.
15 changes: 9 additions & 6 deletions runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl parachains_ump::Config for Runtime {

parameter_types! {
pub const BaseXcmWeight: frame_support::weights::Weight = 1_000;
pub const AnyNetwork: xcm::v0::NetworkId = xcm::v0::NetworkId::Any;
pub const AnyNetwork: xcm::latest::NetworkId = xcm::latest::NetworkId::Any;
}

pub type LocalOriginToLocation = xcm_builder::SignedToAccountId32<Origin, AccountId, AnyNetwork>;
Expand All @@ -500,15 +500,18 @@ impl pallet_xcm::Config for Runtime {
// The config types here are entirely configurable, since the only one that is sorely needed
// is `XcmExecutor`, which will be used in unit tests located in xcm-executor.
type Event = Event;
type ExecuteXcmOrigin = xcm_config::ConvertOriginToLocal;
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type LocationInverter = xcm_config::InvertNothing;
type SendXcmOrigin = xcm_config::ConvertOriginToLocal;
type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type Weigher = xcm_builder::FixedWeightBounds<BaseXcmWeight, Call>;
type XcmRouter = xcm_config::DoNothingRouter;
type XcmExecuteFilter = frame_support::traits::Everything;
type XcmExecuteFilter =
frame_support::traits::All<(xcm::latest::MultiLocation, xcm::latest::Xcm<Call>)>;
type XcmExecutor = xcm_executor::XcmExecutor<xcm_config::XcmConfig>;
type XcmTeleportFilter = frame_support::traits::Everything;
type XcmReserveTransferFilter = frame_support::traits::Everything;
type XcmTeleportFilter =
frame_support::traits::All<(xcm::latest::MultiLocation, Vec<xcm::latest::MultiAsset>)>;
type XcmReserveTransferFilter =
frame_support::traits::All<(xcm::latest::MultiLocation, Vec<xcm::latest::MultiAsset>)>;
}

impl parachains_hrmp::Config for Runtime {
Expand Down
36 changes: 17 additions & 19 deletions runtime/test-runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,28 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use frame_support::{
traits::{EnsureOrigin, Everything, OriginTrait},
weights::Weight,
use frame_support::{parameter_types, traits::All, weights::Weight};
use xcm::latest::{
Error as XcmError, Junction::*, MultiAsset, MultiLocation, MultiLocation::*, NetworkId,
Result as XcmResult, SendXcm, Xcm,
};
use xcm::v0::{Error as XcmError, MultiAsset, MultiLocation, Result as XcmResult, SendXcm, Xcm};
use xcm_builder::{AllowUnpaidExecutionFrom, FixedWeightBounds};
use xcm_builder::{AllowUnpaidExecutionFrom, FixedWeightBounds, SignedToAccountId32};
use xcm_executor::{
traits::{InvertLocation, TransactAsset, WeightTrader},
Assets,
};

pub struct ConvertOriginToLocal;
impl<Origin: OriginTrait> EnsureOrigin<Origin> for ConvertOriginToLocal {
type Success = MultiLocation;

fn try_origin(_: Origin) -> Result<MultiLocation, Origin> {
Ok(MultiLocation::Null)
}

#[cfg(feature = "runtime-benchmarks")]
fn successful_origin() -> Origin {
Origin::root()
}
parameter_types! {
pub const OurNetwork: NetworkId = NetworkId::Polkadot;
}

/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location
/// of this chain.
pub type LocalOriginToLocation = (
// And a usual Signed origin to be used in XCM as a corresponding AccountId32
SignedToAccountId32<crate::Origin, crate::AccountId, OurNetwork>,
);

pub struct DoNothingRouter;
impl SendXcm for DoNothingRouter {
fn send_xcm(_dest: MultiLocation, _msg: Xcm<()>) -> XcmResult {
Expand All @@ -55,7 +52,8 @@ impl TransactAsset for DummyAssetTransactor {
}

fn withdraw_asset(_what: &MultiAsset, _who: &MultiLocation) -> Result<Assets, XcmError> {
Ok(Assets::default())
let asset: MultiAsset = (X1(Parent), 100_000).into();
Ok(asset.into())
}
}

Expand All @@ -73,7 +71,7 @@ impl WeightTrader for DummyWeightTrader {
pub struct InvertNothing;
impl InvertLocation for InvertNothing {
fn invert_location(_: &MultiLocation) -> MultiLocation {
MultiLocation::Null
MultiLocation::Here
}
}

Expand Down
2 changes: 2 additions & 0 deletions xcm/src/v1/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pub enum Error {
AssetNotFound,
/// The given message cannot be translated into a format that the destination can be expected to interpret.
DestinationUnsupported,
/// `execute_xcm` has been called too many times recursively.
RecursionLimitReached,
}

impl From<()> for Error {
Expand Down
16 changes: 8 additions & 8 deletions xcm/xcm-executor/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
name = "xcm-executor-integration-tests"
description = "Integration tests for the XCM Executor"
version = "0.9.10"
version = "0.9.9"

[dependencies]
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.9" }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" }
futures = "0.3.15"
pallet-xcm = { path = "../../pallet-xcm" }
polkadot-test-client = { path = "../../../node/test/client" }
polkadot-test-runtime = { path = "../../../runtime/test-runtime", features = ["runtime-benchmarks"] }
polkadot-test-service = { path = "../../../node/test/service" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.9" }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master" }
xcm = { path = "../..", default-features = false }
xcm-executor = { path = ".." }
sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" }

[features]
default = ["std"]
Expand Down
28 changes: 15 additions & 13 deletions xcm/xcm-executor/integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use polkadot_test_client::{
use polkadot_test_service::construct_extrinsic;
use sp_runtime::{generic::BlockId, traits::Block};
use sp_state_machine::InspectState;
use xcm::v0::{Error as XcmError, MultiAsset::*, MultiLocation::*, Order, Outcome, Xcm::*};
use xcm::latest::{Error as XcmError, Junction::*, MultiLocation::*, Order, Outcome, Xcm::*};
use xcm_executor::MAX_RECURSION_LIMIT;

// This is the inflection point where the test should either fail or pass.
Expand All @@ -37,22 +37,24 @@ fn execute_within_recursion_limit() {
.set_execution_strategy(ExecutionStrategy::AlwaysWasm)
.build();

let mut msg =
WithdrawAsset { assets: vec![ConcreteFungible { id: Null, amount: 0 }], effects: vec![] };
let mut msg = WithdrawAsset { assets: (X1(Parent), 100).into(), effects: vec![] };
for _ in 0..MAX_RECURSION_CHECK {
msg = WithdrawAsset {
assets: vec![ConcreteFungible { id: Null, amount: 0 }],
assets: (X1(Parent), 100).into(),
effects: vec![Order::BuyExecution {
fees: All,
fees: (X1(Parent), 1).into(),
weight: 0,
debt: 0,
halt_on_error: true,
orders: vec![],
// nest `msg` into itself on each iteration.
xcm: vec![msg],
instructions: vec![msg],
}],
};
}

let mut block_builder = client.init_polkadot_block_builder();

let execute = construct_extrinsic(
&client,
polkadot_test_runtime::Call::Xcm(pallet_xcm::Call::execute(
Expand All @@ -62,7 +64,6 @@ fn execute_within_recursion_limit() {
sp_keyring::Sr25519Keyring::Alice,
);

let mut block_builder = client.init_polkadot_block_builder();
block_builder.push_polkadot_extrinsic(execute).expect("pushes extrinsic");

let block = block_builder.build().expect("Finalizes the block").block;
Expand Down Expand Up @@ -91,22 +92,24 @@ fn exceed_recursion_limit() {
.set_execution_strategy(ExecutionStrategy::AlwaysWasm)
.build();

let mut msg =
WithdrawAsset { assets: vec![ConcreteFungible { id: Null, amount: 0 }], effects: vec![] };
let mut msg = WithdrawAsset { assets: (X1(Parent), 100).into(), effects: vec![] };
for _ in 0..(MAX_RECURSION_CHECK + 1) {
msg = WithdrawAsset {
assets: vec![ConcreteFungible { id: Null, amount: 0 }],
assets: (X1(Parent), 100).into(),
effects: vec![Order::BuyExecution {
fees: All,
fees: (X1(Parent), 1).into(),
weight: 0,
debt: 0,
halt_on_error: true,
orders: vec![],
// nest `msg` into itself on each iteration.
xcm: vec![msg],
instructions: vec![msg],
}],
};
}

let mut block_builder = client.init_polkadot_block_builder();

let execute = construct_extrinsic(
&client,
polkadot_test_runtime::Call::Xcm(pallet_xcm::Call::execute(
Expand All @@ -116,7 +119,6 @@ fn exceed_recursion_limit() {
sp_keyring::Sr25519Keyring::Alice,
);

let mut block_builder = client.init_polkadot_block_builder();
block_builder.push_polkadot_extrinsic(execute).expect("pushes extrinsic");

let block = block_builder.build().expect("Finalizes the block").block;
Expand Down
17 changes: 12 additions & 5 deletions xcm/xcm-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ impl<Config: config::Config> XcmExecutor<Config> {
};

if let Some((mut holding, effects)) = maybe_holding_effects {
for effect in effects {
total_surplus += Self::execute_effects(
for effect in effects.into_iter() {
total_surplus += Self::execute_orders(
&origin,
&mut holding,
effect,
Expand All @@ -285,11 +285,11 @@ impl<Config: config::Config> XcmExecutor<Config> {
num_recursions: u32,
) -> Result<Weight, XcmError> {
log::trace!(
target: "xcm::execute_effects",
"origin: {:?}, holding: {:?}, effect: {:?}, recursion: {:?}",
target: "xcm::execute_orders",
"origin: {:?}, holding: {:?}, order: {:?}, recursion: {:?}",
origin,
holding,
effect,
order,
num_recursions,
);

Expand Down Expand Up @@ -343,6 +343,13 @@ impl<Config: config::Config> XcmExecutor<Config> {
holding.subsume_assets(unspent);

let mut remaining_weight = weight;
for order in orders.into_iter() {
match Self::execute_orders(origin, holding, order, trader, num_recursions + 1) {
Err(e) if halt_on_error => return Err(e),
Err(_) => {},
Ok(surplus) => total_surplus += surplus,
}
}
for instruction in instructions.into_iter() {
match Self::do_execute_xcm(
origin.clone(),
Expand Down

0 comments on commit 39ed458

Please sign in to comment.