Skip to content

Commit

Permalink
XCM v3 Companion (#697)
Browse files Browse the repository at this point in the history
* Fixes

* Undiener

* Undiener

* Undiener

* Lockfile

* Changes for send returning hash

* Include message ID as params to execute_xcm

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Companion fixes

* Formatting

* Fixes

* Formatting

* Bump

* Bump

* Fixes

* Formatting

* Make the price of UMP/XCMP message sending configurable

* cargo fmt

* Remove InvertLocation

* Formatting

* Use ConstantPrice from polkadot-runtime-common

* Fix naming

* cargo fmt

* Fixes

* Fixes

* Fixes

* Add CallDispatcher

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Remove unused import

* Remove unused import

* XCMv3 fixes (#1710)

* Fixes XCMv3 related
Fixes XCMv3 (removed query_holding)
Fixes XCMv3 - should use _depositable_count?
Fixes XCMv3 - removed TrustedReserve
Fixes - missing weights for statemine/statemint/westmint
[DO-NOT-CHERRY-PICK] tmp return query_holding to aviod conficts to master
Fixes - missing functions for pallet_xcm_benchmarks::generic::Config
Fixes for XCMv3 benchmarking
Fix xcm - removed query_holding

* ".git/.scripts/bench-bot.sh" xcm statemine assets pallet_xcm_benchmarks::generic

* ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::generic

* ".git/.scripts/bench-bot.sh" xcm westmint assets pallet_xcm_benchmarks::generic

* Fix imports

* Avoid consuming XCM message for NotApplicable scenario (#1787)

* Avoid consuming message for NotApplicable scenario

* Avoid consuming message for NotApplicable scenario tests

* Add 10 message processing limit to DMP queue

* Add 10 message limit to XCMP queue

* Always increment the message_processed count whenever a message is processed

* Fix formatting

* Set an upper limit to the overweight message DMP queue

* Add upper limit to XCMP overweight message queue

* Fix for missing weight for `fn unpaid_execution()`

* Fix - usage of `messages_processed`

* Fixes

* Fixes

* Fixes

* cargo fmt

* Fixes

* Fixes

* Fixes

* Fixes

* Remove unused import

* Fixes for gav-xcm-v3 (#1835)

* Fix for FungiblesAdapter - trait changes: Contains -> AssetChecking

* Fix for missing weight for `fn unpaid_execution()`

* Used NonLocalMint for all NonZeroIssuance

* Fix

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fix tests

* Fixes

* Add SafeCallFilter

* Add missing config items

* Add TODO

* Use () as the PriceForParentDelivery

* Fixes

* Fixes

* Fixes

* Fixes

* Update transact_origin to transact_origin_and_runtime_call

* Add ReachableDest config item to XCM pallet

* Update SafeCallFilter to allow remark_with_event in runtime benchmarks

* cargo fmt

* Update substrate

* Fix worst_case_holding

* Fix DMQ queue unit tests

* Remove unused label

* cargo fmt

* Actually process incoming XCMs

* Fixes

* Fixes

* Fixes

* Fixes - return back Weightless

* Added measured benchmarks for `pallet_xcm` (#1968)

* Fix

Fix

Fix

* Fix

* Fixes for transact benchmark

* Fixes add pallet_xcm to benchmarks

* Revert remark_with_event

* ".git/.scripts/bench-bot.sh" xcm statemine assets pallet_xcm_benchmarks::generic

* Fixes

* TMP

* Fix for reserve_asset_deposited

* ".git/.scripts/bench-bot.sh" pallet statemine assets pallet_xcm

* Fix

* ".git/.scripts/bench-bot.sh" pallet statemint assets pallet_xcm

* Fix

* ".git/.scripts/bench-bot.sh" pallet westmint assets pallet_xcm

* Fix westmint

* ".git/.scripts/bench-bot.sh" xcm statemine assets pallet_xcm_benchmarks::generic

* Fix

* ".git/.scripts/bench-bot.sh" xcm westmint assets pallet_xcm_benchmarks::generic

* ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::generic

* ".git/.scripts/bench-bot.sh" pallet collectives-polkadot collectives pallet_xcm

* Fix for collectives

* ".git/.scripts/bench-bot.sh" pallet bridge-hub-kusama bridge-hubs pallet_xcm

* ".git/.scripts/bench-bot.sh" pallet bridge-hub-rococo bridge-hubs pallet_xcm

* Fixes for bridge-hubs

* Fixes - return back Weightless

* Fix - removed MigrateToTrackInactive for contracts-rococo

Co-authored-by: command-bot <>

* cargo fmt

* Fix benchmarks

* Bko gav xcm v3 (#1993)

* Fix

* ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::fungible

* ".git/.scripts/bench-bot.sh" xcm statemine assets pallet_xcm_benchmarks::fungible

* ".git/.scripts/bench-bot.sh" xcm westmint assets pallet_xcm_benchmarks::fungible

* ".git/.scripts/bench-bot.sh" xcm statemine assets pallet_xcm_benchmarks::generic

* ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::generic

* ".git/.scripts/bench-bot.sh" xcm westmint assets pallet_xcm_benchmarks::generic

* ".git/.scripts/bench-bot.sh" pallet statemine assets pallet_xcm

* ".git/.scripts/bench-bot.sh" pallet westmint assets pallet_xcm

* ".git/.scripts/bench-bot.sh" pallet statemint assets pallet_xcm

* ".git/.scripts/bench-bot.sh" pallet collectives-polkadot collectives pallet_xcm

* ".git/.scripts/bench-bot.sh" pallet bridge-hub-kusama bridge-hubs pallet_xcm

* ".git/.scripts/bench-bot.sh" pallet bridge-hub-rococo bridge-hubs pallet_xcm

Co-authored-by: command-bot <>

* Change AllowUnpaidExecutionFrom to be explicit

* xcm-v3 benchmarks, weights, fixes for bridge-hubs (#2035)

* Dumy weights to get compile

* Change UniversalLocation according to paritytech/polkadot#4097 (Location Inversion Removed)

* Fix bridge-hubs weights

* ".git/.scripts/bench-bot.sh" pallet statemine assets pallet_xcm

* ".git/.scripts/bench-bot.sh" pallet statemint assets pallet_xcm

* ".git/.scripts/bench-bot.sh" pallet collectives-polkadot collectives pallet_xcm

* ".git/.scripts/bench-bot.sh" pallet westmint assets pallet_xcm

* ".git/.scripts/bench-bot.sh" xcm bridge-hub-kusama bridge-hubs pallet_xcm_benchmarks::generic

* ".git/.scripts/bench-bot.sh" xcm bridge-hub-kusama bridge-hubs pallet_xcm_benchmarks::fungible

* ".git/.scripts/bench-bot.sh" pallet bridge-hub-kusama bridge-hubs pallet_xcm

* ".git/.scripts/bench-bot.sh" pallet bridge-hub-rococo bridge-hubs pallet_xcm

* ".git/.scripts/bench-bot.sh" xcm bridge-hub-rococo bridge-hubs pallet_xcm_benchmarks::fungible

* ".git/.scripts/bench-bot.sh" xcm bridge-hub-rococo bridge-hubs pallet_xcm_benchmarks::generic

* Change NetworkId to Option<NetworkId>

Co-authored-by: command-bot <>
Co-authored-by: Keith Yeung <[email protected]>

* Add event for showing the hash of an UMP sent message (#1228)

* Add UpwardMessageSent event in parachain-system

* additional fixes

* Message Id

* Fix errors from merge

* fmt

* more fmt

* Remove todo

* more formatting

* Fixes

* Fixes

* Fixes

* Fixes

* Allow explicit unpaid executions from the relay chains for system parachains (#2060)

* Allow explicit unpaid executions from the relay chains for system parachains

* Put origin-filtering barriers into WithComputedOrigin

* Use ConstU32<8>

* Small nits

* formatting

* cargo fmt

* Allow receiving XCMs from any relay chain plurality

* Fixes

* update lockfile for {"polkadot", "substrate"}

* Update polkadot

* Add runtime-benchmarks feature

Co-authored-by: Keith Yeung <[email protected]>
Co-authored-by: Branislav Kontur <[email protected]>
Co-authored-by: girazoki <[email protected]>
Co-authored-by: parity-processbot <>
  • Loading branch information
4 people authored Jan 17, 2023
1 parent 9610cec commit 8678c1b
Show file tree
Hide file tree
Showing 54 changed files with 3,340 additions and 957 deletions.
1 change: 1 addition & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sp-std = { git = "https://github.com/paritytech/substrate", default-features = f
# Polkadot
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }

# Cumulus
Expand Down
14 changes: 5 additions & 9 deletions common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
use frame_support::traits::{
fungibles::{self, Balanced, CreditOf},
Contains, Currency, Get, Imbalance, OnUnbalanced,
Contains, ContainsPair, Currency, Get, Imbalance, OnUnbalanced,
};
use pallet_asset_tx_payment::HandleCredit;
use sp_runtime::traits::Zero;
use sp_std::marker::PhantomData;
use xcm::latest::{AssetId, Fungibility::Fungible, MultiAsset, MultiLocation};
use xcm_executor::traits::FilterAssetLocation;

/// Type alias to conveniently refer to the `Currency::NegativeImbalance` associated type.
pub type NegativeImbalance<T> = <pallet_balances::Pallet<T> as Currency<
Expand Down Expand Up @@ -97,8 +96,8 @@ where

/// Asset filter that allows all assets from a certain location.
pub struct AssetsFrom<T>(PhantomData<T>);
impl<T: Get<MultiLocation>> FilterAssetLocation for AssetsFrom<T> {
fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool {
impl<T: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation> for AssetsFrom<T> {
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
let loc = T::get();
&loc == origin &&
matches!(asset, MultiAsset { id: AssetId::Concrete(asset_loc), fun: Fungible(_a) }
Expand Down Expand Up @@ -267,12 +266,9 @@ mod tests {
.clone()
.pushed_with_interior(GeneralIndex(42))
.expect("multilocation will only have 2 junctions; qed");
let asset = MultiAsset { id: Concrete(asset_location), fun: 1_000_000.into() };
let asset = MultiAsset { id: Concrete(asset_location), fun: 1_000_000u128.into() };
assert!(
AssetsFrom::<SomeSiblingParachain>::filter_asset_location(
&asset,
&SomeSiblingParachain::get()
),
AssetsFrom::<SomeSiblingParachain>::contains(&asset, &SomeSiblingParachain::get()),
"AssetsFrom should allow assets from any of its interior locations"
);
}
Expand Down
28 changes: 15 additions & 13 deletions common/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use crate::impls::AccountIdOf;
use core::marker::PhantomData;
use frame_support::{
log,
traits::{fungibles::Inspect, tokens::BalanceConversion},
traits::{fungibles::Inspect, tokens::BalanceConversion, ContainsPair},
weights::{Weight, WeightToFee, WeightToFeePolynomial},
};
use sp_runtime::traits::Get;
use xcm::latest::{prelude::*, Weight as XCMWeight};
use xcm_executor::traits::{FilterAssetLocation, ShouldExecute};
use xcm::latest::prelude::*;
use xcm_executor::traits::ShouldExecute;

//TODO: move DenyThenTry to polkadot's xcm module.
/// Deny executing the XCM if it matches any of the Deny filter regardless of anything else.
Expand All @@ -24,9 +24,9 @@ where
{
fn should_execute<RuntimeCall>(
origin: &MultiLocation,
message: &mut Xcm<RuntimeCall>,
max_weight: XCMWeight,
weight_credit: &mut XCMWeight,
message: &mut [Instruction<RuntimeCall>],
max_weight: Weight,
weight_credit: &mut Weight,
) -> Result<(), ()> {
Deny::should_execute(origin, message, max_weight, weight_credit)?;
Allow::should_execute(origin, message, max_weight, weight_credit)
Expand All @@ -38,11 +38,11 @@ pub struct DenyReserveTransferToRelayChain;
impl ShouldExecute for DenyReserveTransferToRelayChain {
fn should_execute<RuntimeCall>(
origin: &MultiLocation,
message: &mut Xcm<RuntimeCall>,
_max_weight: XCMWeight,
_weight_credit: &mut XCMWeight,
message: &mut [Instruction<RuntimeCall>],
_max_weight: Weight,
_weight_credit: &mut Weight,
) -> Result<(), ()> {
if message.0.iter().any(|inst| {
if message.iter().any(|inst| {
matches!(
inst,
InitiateReserveWithdraw {
Expand All @@ -61,7 +61,7 @@ impl ShouldExecute for DenyReserveTransferToRelayChain {
// An unexpected reserve transfer has arrived from the Relay Chain. Generally, `IsReserve`
// should not allow this, but we just log it here.
if matches!(origin, MultiLocation { parents: 1, interior: Here }) &&
message.0.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
message.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
{
log::warn!(
target: "xcm::barriers",
Expand Down Expand Up @@ -111,8 +111,10 @@ where

/// Accepts an asset if it is a native asset from a particular `MultiLocation`.
pub struct ConcreteNativeAssetFrom<Location>(PhantomData<Location>);
impl<Location: Get<MultiLocation>> FilterAssetLocation for ConcreteNativeAssetFrom<Location> {
fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool {
impl<Location: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
for ConcreteNativeAssetFrom<Location>
{
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
log::trace!(target: "xcm::filter_asset_location",
"ConcreteNativeAsset asset: {:?}, origin: {:?}, location: {:?}",
asset, origin, Location::get());
Expand Down
33 changes: 20 additions & 13 deletions pallets/ping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
PingSent(ParaId, u32, Vec<u8>),
PingSent(ParaId, u32, Vec<u8>, XcmHash, MultiAssets),
Pinged(ParaId, u32, Vec<u8>),
PongSent(ParaId, u32, Vec<u8>),
PongSent(ParaId, u32, Vec<u8>, XcmHash, MultiAssets),
Ponged(ParaId, u32, Vec<u8>, T::BlockNumber),
ErrorSendingPing(SendError, ParaId, u32, Vec<u8>),
ErrorSendingPong(SendError, ParaId, u32, Vec<u8>),
Expand All @@ -103,11 +103,11 @@ pub mod pallet {
*seq += 1;
*seq
});
match T::XcmSender::send_xcm(
(1, Junction::Parachain(para.into())),
match send_xcm::<T::XcmSender>(
(Parent, Junction::Parachain(para.into())).into(),
Xcm(vec![Transact {
origin_type: OriginKind::Native,
require_weight_at_most: 1_000,
origin_kind: OriginKind::Native,
require_weight_at_most: Weight::from_parts(1_000, 1_000),
call: <T as Config>::RuntimeCall::from(Call::<T>::ping {
seq,
payload: payload.clone().to_vec(),
Expand All @@ -116,9 +116,15 @@ pub mod pallet {
.into(),
}]),
) {
Ok(()) => {
Ok((hash, cost)) => {
Pings::<T>::insert(seq, n);
Self::deposit_event(Event::PingSent(para, seq, payload.to_vec()));
Self::deposit_event(Event::PingSent(
para,
seq,
payload.to_vec(),
hash,
cost,
));
},
Err(e) => {
Self::deposit_event(Event::ErrorSendingPing(
Expand Down Expand Up @@ -198,11 +204,11 @@ pub mod pallet {
let para = ensure_sibling_para(<T as Config>::RuntimeOrigin::from(origin))?;

Self::deposit_event(Event::Pinged(para, seq, payload.clone()));
match T::XcmSender::send_xcm(
(1, Junction::Parachain(para.into())),
match send_xcm::<T::XcmSender>(
(Parent, Junction::Parachain(para.into())).into(),
Xcm(vec![Transact {
origin_type: OriginKind::Native,
require_weight_at_most: 1_000,
origin_kind: OriginKind::Native,
require_weight_at_most: Weight::from_parts(1_000, 1_000),
call: <T as Config>::RuntimeCall::from(Call::<T>::pong {
seq,
payload: payload.clone(),
Expand All @@ -211,7 +217,8 @@ pub mod pallet {
.into(),
}]),
) {
Ok(()) => Self::deposit_event(Event::PongSent(para, seq, payload)),
Ok((hash, cost)) =>
Self::deposit_event(Event::PongSent(para, seq, payload, hash, cost)),
Err(e) => Self::deposit_event(Event::ErrorSendingPong(e, para, seq, payload)),
}
Ok(())
Expand Down
44 changes: 28 additions & 16 deletions runtimes/assets/statemine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
>;
type ControllerOriginConverter = xcm_config::XcmOriginToTransactDispatchOrigin;
type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo<Runtime>;
type PriceForSiblingDelivery = ();
}

impl cumulus_pallet_dmp_queue::Config for Runtime {
Expand Down Expand Up @@ -684,6 +685,7 @@ mod benches {
[pallet_collator_selection, CollatorSelection]
[cumulus_pallet_xcmp_queue, XcmpQueue]
// XCM
[pallet_xcm, PolkadotXcm]
// NOTE: Make sure you point to the individual modules below.
[pallet_xcm_benchmarks::fungible, XcmBalances]
[pallet_xcm_benchmarks::generic, XcmGeneric]
Expand Down Expand Up @@ -870,7 +872,7 @@ impl_runtime_apis! {
impl cumulus_pallet_session_benchmarking::Config for Runtime {}

use xcm::latest::prelude::*;
use xcm_config::KsmLocation;
use xcm_config::{KsmLocation, MaxAssetsIntoHolding};
use pallet_xcm_benchmarks::asset_instance_from;

impl pallet_xcm_benchmarks::Config for Runtime {
Expand All @@ -879,12 +881,12 @@ impl_runtime_apis! {
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
Ok(KsmLocation::get())
}
fn worst_case_holding() -> MultiAssets {
fn worst_case_holding(depositable_count: u32) -> MultiAssets {
// A mix of fungible, non-fungible, and concrete assets.
const HOLDING_FUNGIBLES: u32 = 100;
const HOLDING_NON_FUNGIBLES: u32 = 100;
let holding_non_fungibles = MaxAssetsIntoHolding::get() / 2 - depositable_count;
let holding_fungibles = holding_non_fungibles.saturating_sub(1);
let fungibles_amount: u128 = 100;
let mut assets = (0..HOLDING_FUNGIBLES)
let mut assets = (0..holding_fungibles)
.map(|i| {
MultiAsset {
id: Concrete(GeneralIndex(i as u128).into()),
Expand All @@ -893,17 +895,17 @@ impl_runtime_apis! {
.into()
})
.chain(core::iter::once(MultiAsset { id: Concrete(Here.into()), fun: Fungible(u128::MAX) }))
.chain((0..HOLDING_NON_FUNGIBLES).map(|i| MultiAsset {
.chain((0..holding_non_fungibles).map(|i| MultiAsset {
id: Concrete(GeneralIndex(i as u128).into()),
fun: NonFungible(asset_instance_from(i)),
}))
.collect::<Vec<_>>();

assets.push(MultiAsset{
id: Concrete(KsmLocation::get()),
fun: Fungible(1_000_000 * UNITS),
});
assets.into()
assets.push(MultiAsset {
id: Concrete(KsmLocation::get()),
fun: Fungible(1_000_000 * UNITS),
});
assets.into()
}
}

Expand All @@ -912,8 +914,7 @@ impl_runtime_apis! {
KsmLocation::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(KsmLocation::get()) },
));
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None;
pub const CheckedAccount: Option<AccountId> = None;
pub const CheckedAccount: Option<(AccountId, xcm_builder::MintLocation)> = None;

}

Expand All @@ -922,7 +923,6 @@ impl_runtime_apis! {

type CheckedAccount = CheckedAccount;
type TrustedTeleporter = TrustedTeleporter;
type TrustedReserve = TrustedReserve;

fn get_multi_asset() -> MultiAsset {
MultiAsset {
Expand All @@ -939,8 +939,16 @@ impl_runtime_apis! {
(0u64, Response::Version(Default::default()))
}

fn transact_origin() -> Result<MultiLocation, BenchmarkError> {
Ok(KsmLocation::get())
fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> {
Err(BenchmarkError::Skip)
}

fn universal_alias() -> Result<Junction, BenchmarkError> {
Err(BenchmarkError::Skip)
}

fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> {
Ok((KsmLocation::get(), frame_system::Call::remark_with_event { remark: vec![] }.into()))
}

fn subscribe_origin() -> Result<MultiLocation, BenchmarkError> {
Expand All @@ -953,6 +961,10 @@ impl_runtime_apis! {
let ticket = MultiLocation { parents: 0, interior: Here };
Ok((origin, ticket, assets))
}

fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> {
Err(BenchmarkError::Skip)
}
}

type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;
Expand Down
1 change: 1 addition & 0 deletions runtimes/assets/statemine/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod pallet_session;
pub mod pallet_timestamp;
pub mod pallet_uniques;
pub mod pallet_utility;
pub mod pallet_xcm;
pub mod paritydb_weights;
pub mod rocksdb_weights;
pub mod xcm;
Expand Down
Loading

0 comments on commit 8678c1b

Please sign in to comment.