mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 09:21:04 +00:00
XCM simulator (#3538)
* Add xcm-simulator and xcm-simulator-example. * Abstract xcmp and dmp handling. * Use mock message queue. * Xcm simulator example unit tests. * Use relay chain block number on sending msg. * Fix typo. * fmt * more fmt * Fix deps.
This commit is contained in:
@@ -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"
|
||||
|
||||
|
||||
@@ -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};
|
||||
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user