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

XCM simulator #3538

Merged
9 commits merged into from
Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ members = [
"xcm",
"xcm/xcm-builder",
"xcm/xcm-executor",
"xcm/xcm-simulator",
"xcm/xcm-simulator/example",
"xcm/pallet-xcm",
"node/client",
"node/collation-generation",
Expand Down
1 change: 1 addition & 0 deletions parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ parity-util-mem = { version = "0.10.0", optional = true }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
polkadot-core-primitives = { path = "../core-primitives", default-features = false }
derive_more = "0.99.11"

Expand Down
54 changes: 54 additions & 0 deletions parachain/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use sp_std::vec::Vec;
use parity_scale_codec::{Encode, Decode, CompactAs};
use sp_core::{RuntimeDebug, TypeId};
use sp_runtime::traits::Hash as _;
use frame_support::weights::Weight;

#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
Expand Down Expand Up @@ -318,6 +319,59 @@ pub struct HrmpChannelId {
/// A message from a parachain to its Relay Chain.
pub type UpwardMessage = Vec<u8>;

/// Something that should be called when a downward message is received.
pub trait DmpMessageHandler {
/// Handle some incoming DMP messages (note these are individual XCM messages).
///
/// Also, process messages up to some `max_weight`.
fn handle_dmp_messages(
iter: impl Iterator<Item = (RelayChainBlockNumber, Vec<u8>)>,
max_weight: Weight,
) -> Weight;
}
impl DmpMessageHandler for () {
fn handle_dmp_messages(
iter: impl Iterator<Item = (RelayChainBlockNumber, Vec<u8>)>,
_max_weight: Weight,
) -> Weight {
iter.for_each(drop);
0
}
}

/// The aggregate XCMP message format.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode)]
pub enum XcmpMessageFormat {
/// Encoded `VersionedXcm` messages, all concatenated.
ConcatenatedVersionedXcm,
/// Encoded `Vec<u8>` messages, all concatenated.
ConcatenatedEncodedBlob,
/// One or more channel control signals; these should be interpreted immediately upon receipt
/// from the relay-chain.
Signals,
}

/// Something that should be called for each batch of messages received over XCMP.
pub trait XcmpMessageHandler {
/// Handle some incoming XCMP messages (note these are the big one-per-block aggregate
/// messages).
///
/// Also, process messages up to some `max_weight`.
fn handle_xcmp_messages<'a, I: Iterator<Item = (Id, RelayChainBlockNumber, &'a [u8])>>(
iter: I,
max_weight: Weight,
) -> Weight;
}
impl XcmpMessageHandler for () {
fn handle_xcmp_messages<'a, I: Iterator<Item = (Id, RelayChainBlockNumber, &'a [u8])>>(
iter: I,
_max_weight: Weight,
) -> Weight {
for _ in iter {}
0
}
}

/// Validation parameters for evaluating the parachain validity function.
// TODO: balance downloads (https://github.com/paritytech/polkadot/issues/220)
#[derive(PartialEq, Eq, Decode, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion xcm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "xcm"
version = "0.9.8"
authors = ["Parity Technologies x<admin@parity.io>"]
authors = ["Parity Technologies <admin@parity.io>"]
description = "The basic XCM datastructures."
edition = "2018"

Expand Down
20 changes: 20 additions & 0 deletions xcm/xcm-simulator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "xcm-simulator"
version = "0.9.8"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Test kit to simulate cross-chain message passing and XCM execution"
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0" }
paste = "1.0.5"

frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master" }

xcm = { path = "../" }
xcm-executor = { path = "../xcm-executor" }
polkadot-core-primitives = { path = "../../core-primitives"}
polkadot-parachain = { path = "../../parachain" }
polkadot-runtime-parachains = { path = "../../runtime/parachains" }
27 changes: 27 additions & 0 deletions xcm/xcm-simulator/example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "xcm-simulator-example"
version = "0.9.8"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Examples of xcm-simulator usage."
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0" }
paste = "1.0.5"

frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }

xcm = { path = "../../" }
xcm-simulator = { path = "../" }
xcm-executor = { path = "../../xcm-executor" }
xcm-builder = { path = "../../xcm-builder" }
pallet-xcm = { path = "../../pallet-xcm" }
polkadot-core-primitives = { path = "../../../core-primitives"}
polkadot-runtime-parachains = { path = "../../../runtime/parachains" }
polkadot-parachain = { path = "../../../parachain" }
Loading