mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 13:51:11 +00:00
Mock XCM (#876)
* sketch downward messages * bring in attempt to mock mqc-head from moonbeam * just patch individual crates * fing comma * add some logs * Holy shit, we actually imported a block! * Actually mock the message queue chain * use relay parent number for `sent_at` * finish moving MQC to primitives * more complete mock and better config type * change name * fix export * better map types * fix dependencies after rebase * try-rejigging branches because this is an override * try to re-jig for hrmp mcqs * fix branches * actually fix branches better * even better * Removestray log lines Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Nicer handling of default `ParachainSystem` name * better docs * Default MockXcm for people who only who don't care to mock xcm. * cargo fmt * trailing commas * Apply suggestions from code review Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * use the variable for hrmp to * fix deref * deduplicate MessageQueueChain * better docs for MessageQueueChain * Use `Vec<u8>` instead of `&'static [u8]` Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * cargo fmt * associated changes for using Vec<u8> * Unused import * Fix compilation Co-authored-by: Joshy Orndorff <admin@joshyorndorff.com> Co-authored-by: Joshy Orndorff <JoshOrndorff@users.noreply.github.com>
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use cumulus_primitives_core::{
|
||||
relay_chain::{BlakeTwo256, Hash as RelayHash, HashT as _},
|
||||
InboundDownwardMessage, InboundHrmpMessage, ParaId, PersistedValidationData,
|
||||
};
|
||||
|
||||
@@ -42,7 +43,7 @@ pub use client_side::*;
|
||||
#[cfg(feature = "std")]
|
||||
mod mock;
|
||||
#[cfg(feature = "std")]
|
||||
pub use mock::MockValidationDataInherentDataProvider;
|
||||
pub use mock::{MockValidationDataInherentDataProvider, MockXcmConfig};
|
||||
|
||||
/// The identifier for the parachain inherent.
|
||||
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"sysi1337";
|
||||
@@ -68,3 +69,50 @@ pub struct ParachainInherentData {
|
||||
/// this means `sent_at` is **strictly** greater than the previous one (if any).
|
||||
pub horizontal_messages: BTreeMap<ParaId, Vec<InboundHrmpMessage>>,
|
||||
}
|
||||
|
||||
/// This struct provides ability to extend a message queue chain (MQC) and compute a new head.
|
||||
///
|
||||
/// MQC is an instance of a [hash chain] applied to a message queue. Using a hash chain it's
|
||||
/// possible to represent a sequence of messages using only a single hash.
|
||||
///
|
||||
/// A head for an empty chain is agreed to be a zero hash.
|
||||
///
|
||||
/// An instance is used to track either DMP from the relay chain or HRMP across a channel.
|
||||
/// But a given instance is never used to track both. Therefore, you should call either
|
||||
/// `extend_downward` or `extend_hrmp`, but not both methods on a single instance.
|
||||
///
|
||||
/// [hash chain]: https://en.wikipedia.org/wiki/Hash_chain
|
||||
#[derive(Default, Clone, codec::Encode, codec::Decode, scale_info::TypeInfo)]
|
||||
pub struct MessageQueueChain(RelayHash);
|
||||
|
||||
impl MessageQueueChain {
|
||||
/// Extend the hash chain with an HRMP message. This method should be used only when
|
||||
/// this chain is tracking HRMP.
|
||||
pub fn extend_hrmp(&mut self, horizontal_message: &InboundHrmpMessage) -> &mut Self {
|
||||
let prev_head = self.0;
|
||||
self.0 = BlakeTwo256::hash_of(&(
|
||||
prev_head,
|
||||
horizontal_message.sent_at,
|
||||
BlakeTwo256::hash_of(&horizontal_message.data),
|
||||
));
|
||||
self
|
||||
}
|
||||
|
||||
/// Extend the hash chain with a downward message. This method should be used only when
|
||||
/// this chain is tracking DMP.
|
||||
pub fn extend_downward(&mut self, downward_message: &InboundDownwardMessage) -> &mut Self {
|
||||
let prev_head = self.0;
|
||||
self.0 = BlakeTwo256::hash_of(&(
|
||||
prev_head,
|
||||
downward_message.sent_at,
|
||||
BlakeTwo256::hash_of(&downward_message.msg),
|
||||
));
|
||||
self
|
||||
}
|
||||
|
||||
/// Return the current mead of the message queue hash chain.
|
||||
/// This is agreed to be the zero hash for an empty chain.
|
||||
pub fn head(&self) -> RelayHash {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user