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

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 aae4731 commit 3aae882
Show file tree
Hide file tree
Showing 73 changed files with 4,321 additions and 1,480 deletions.
528 changes: 273 additions & 255 deletions Cargo.lock

Large diffs are not rendered by default.

259 changes: 167 additions & 92 deletions pallets/dmp-queue/src/lib.rs

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions pallets/dmp-queue/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use frame_support::{
traits::StorageVersion,
weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, Weight},
};
use xcm::latest::Weight as XcmWeight;

/// The current storage version.
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
Expand All @@ -33,8 +32,15 @@ pub fn migrate_to_latest<T: Config>() -> Weight {
let mut weight = T::DbWeight::get().reads(1);

if StorageVersion::get::<Pallet<T>>() == 0 {
weight += migrate_to_v1::<T>();
weight.saturating_accrue(migrate_to_v1::<T>());
StorageVersion::new(1).put::<Pallet<T>>();
weight.saturating_accrue(T::DbWeight::get().writes(1));
}

if StorageVersion::get::<Pallet<T>>() == 1 {
weight.saturating_accrue(migrate_to_v2::<T>());
StorageVersion::new(2).put::<Pallet<T>>();
weight.saturating_accrue(T::DbWeight::get().writes(1));
}

weight
Expand All @@ -46,7 +52,7 @@ mod v0 {

#[derive(Decode, Encode, Debug)]
pub struct ConfigData {
pub max_individual: XcmWeight,
pub max_individual: u64,
}

impl Default for ConfigData {
Expand Down Expand Up @@ -78,6 +84,16 @@ pub fn migrate_to_v1<T: Config>() -> Weight {
T::DbWeight::get().reads_writes(1, 1)
}

/// Migrates `Overweight` so that it initializes the storage map's counter.
///
/// NOTE: Only use this function if you know what you're doing. Default to using
/// `migrate_to_latest`.
pub fn migrate_to_v2<T: Config>() -> Weight {
let overweight_messages = <Pallet<T> as Store>::Overweight::initialize_counter() as u64;

T::DbWeight::get().reads_writes(overweight_messages, 1)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 2 additions & 0 deletions pallets/parachain-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sp-version = { git = "https://github.com/paritytech/substrate", default-features

# Polkadot
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, features = [ "wasm-api" ], branch = "master" }
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }

# Cumulus
cumulus-pallet-parachain-system-proc-macro = { path = "proc-macro", default-features = false }
Expand Down Expand Up @@ -67,6 +68,7 @@ std = [
"sp-state-machine/std",
"sp-std/std",
"sp-trie/std",
"xcm/std",
]

runtime-benchmarks = [
Expand Down
18 changes: 13 additions & 5 deletions pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use sp_runtime::{
},
};
use sp_std::{cmp, collections::btree_map::BTreeMap, prelude::*};
use xcm::latest::XcmHash;

mod migration;
mod relay_state_snapshot;
Expand Down Expand Up @@ -480,6 +481,8 @@ pub mod pallet {
DownwardMessagesReceived { count: u32 },
/// Downward messages were processed using the given weight.
DownwardMessagesProcessed { weight_used: Weight, dmq_head: relay_chain::Hash },
/// An upward message was sent to the relay chain.
UpwardMessageSent { message_hash: Option<XcmHash> },
}

#[pallet::error]
Expand Down Expand Up @@ -743,7 +746,7 @@ impl<T: Config> GetChannelInfo for Pallet<T> {
// None then it must be that this is an edge-case where a message is attempted to be
// sent at the first block. It should be safe to assume that there are no channels
// opened at all so early. At least, relying on this assumption seems to be a better
// tradeoff, compared to introducing an error variant that the clients should be
// trade-off, compared to introducing an error variant that the clients should be
// prepared to handle.
let index = match channels.binary_search_by_key(&id, |item| item.0) {
Err(_) => return ChannelStatus::Closed,
Expand Down Expand Up @@ -1004,7 +1007,7 @@ impl<T: Config> frame_system::SetCode<T> for ParachainSetCode<T> {
}

impl<T: Config> Pallet<T> {
pub fn send_upward_message(message: UpwardMessage) -> Result<u32, MessageSendError> {
pub fn send_upward_message(message: UpwardMessage) -> Result<(u32, XcmHash), MessageSendError> {
// Check if the message fits into the relay-chain constraints.
//
// Note, that we are using `host_configuration` here which may be from the previous
Expand Down Expand Up @@ -1034,13 +1037,18 @@ impl<T: Config> Pallet<T> {
// Thus fall through here.
},
};
<PendingUpwardMessages<T>>::append(message);
Ok(0)
<PendingUpwardMessages<T>>::append(message.clone());

// The relay ump does not use using_encoded
// We apply the same this to use the same hash
let hash = sp_io::hashing::blake2_256(&message);
Self::deposit_event(Event::UpwardMessageSent { message_hash: Some(hash) });
Ok((0, hash))
}
}

impl<T: Config> UpwardMessageSender for Pallet<T> {
fn send_upward_message(message: UpwardMessage) -> Result<u32, MessageSendError> {
fn send_upward_message(message: UpwardMessage) -> Result<(u32, XcmHash), MessageSendError> {
Self::send_upward_message(message)
}
}
Expand Down
18 changes: 9 additions & 9 deletions pallets/xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ pub mod pallet {
pub enum Event<T: Config> {
/// Downward message is invalid XCM.
/// \[ id \]
InvalidFormat([u8; 8]),
InvalidFormat([u8; 32]),
/// Downward message is unsupported version of XCM.
/// \[ id \]
UnsupportedVersion([u8; 8]),
UnsupportedVersion([u8; 32]),
/// Downward message executed with the given outcome.
/// \[ id, outcome \]
ExecutedDownward([u8; 8], Outcome),
ExecutedDownward([u8; 32], Outcome),
}

/// Origin for the parachains module.
Expand Down Expand Up @@ -113,7 +113,7 @@ impl<T: Config> DmpMessageHandler for UnlimitedDmpExecution<T> {
) -> Weight {
let mut used = Weight::zero();
for (_sent_at, data) in iter {
let id = sp_io::hashing::twox_64(&data[..]);
let id = sp_io::hashing::blake2_256(&data[..]);
let msg = VersionedXcm::<T::RuntimeCall>::decode_all_with_depth_limit(
MAX_XCM_DECODE_DEPTH,
&mut data.as_slice(),
Expand All @@ -123,8 +123,8 @@ impl<T: Config> DmpMessageHandler for UnlimitedDmpExecution<T> {
Err(_) => Pallet::<T>::deposit_event(Event::InvalidFormat(id)),
Ok(Err(())) => Pallet::<T>::deposit_event(Event::UnsupportedVersion(id)),
Ok(Ok(x)) => {
let outcome = T::XcmExecutor::execute_xcm(Parent, x, limit.ref_time());
used += Weight::from_ref_time(outcome.weight_used());
let outcome = T::XcmExecutor::execute_xcm(Parent, x, id, limit);
used = used.saturating_add(outcome.weight_used());
Pallet::<T>::deposit_event(Event::ExecutedDownward(id, outcome));
},
}
Expand All @@ -146,7 +146,7 @@ impl<T: Config> DmpMessageHandler for LimitAndDropDmpExecution<T> {
) -> Weight {
let mut used = Weight::zero();
for (_sent_at, data) in iter {
let id = sp_io::hashing::twox_64(&data[..]);
let id = sp_io::hashing::blake2_256(&data[..]);
let msg = VersionedXcm::<T::RuntimeCall>::decode_all_with_depth_limit(
MAX_XCM_DECODE_DEPTH,
&mut data.as_slice(),
Expand All @@ -157,8 +157,8 @@ impl<T: Config> DmpMessageHandler for LimitAndDropDmpExecution<T> {
Ok(Err(())) => Pallet::<T>::deposit_event(Event::UnsupportedVersion(id)),
Ok(Ok(x)) => {
let weight_limit = limit.saturating_sub(used);
let outcome = T::XcmExecutor::execute_xcm(Parent, x, weight_limit.ref_time());
used += Weight::from_ref_time(outcome.weight_used());
let outcome = T::XcmExecutor::execute_xcm(Parent, x, id, weight_limit);
used = used.saturating_add(outcome.weight_used());
Pallet::<T>::deposit_event(Event::ExecutedDownward(id, outcome));
},
}
Expand Down
5 changes: 4 additions & 1 deletion pallets/xcmp-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ scale-info = { version = "2.3.1", default-features = false, features = ["derive"
# Substrate
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }

# Polkadot
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }

Expand All @@ -30,7 +32,6 @@ frame-benchmarking = { default-features = false, optional = true, git = "https:/

# Substrate
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" }

# Polkadot
Expand All @@ -48,6 +49,8 @@ std = [
"frame-support/std",
"frame-system/std",
"log/std",
"polkadot-runtime-common/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"xcm-executor/std",
Expand Down
2 changes: 1 addition & 1 deletion pallets/xcmp-queue/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use frame_system::RawOrigin;

benchmarks! {
set_config_with_u32 {}: update_resume_threshold(RawOrigin::Root, 100)
set_config_with_weight {}: update_weight_restrict_decay(RawOrigin::Root, 3_000_000)
set_config_with_weight {}: update_weight_restrict_decay(RawOrigin::Root, Weight::from_ref_time(3_000_000))
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
Loading

0 comments on commit 3aae882

Please sign in to comment.