* 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:
Bastian Köcher
2021-12-24 18:06:36 +01:00
committed by GitHub
parent 0256fe73c0
commit 229000c5fc
6 changed files with 205 additions and 60 deletions
+4 -41
View File
@@ -33,7 +33,7 @@ use cumulus_primitives_core::{
OutboundHrmpMessage, ParaId, PersistedValidationData, UpwardMessage, UpwardMessageSender,
XcmpMessageHandler, XcmpMessageSource,
};
use cumulus_primitives_parachain_inherent::ParachainInherentData;
use cumulus_primitives_parachain_inherent::{MessageQueueChain, ParachainInherentData};
use frame_support::{
dispatch::{DispatchError, DispatchResult},
ensure,
@@ -46,7 +46,7 @@ use frame_system::{ensure_none, ensure_root};
use polkadot_parachain::primitives::RelayChainBlockNumber;
use relay_state_snapshot::MessagingStateSnapshot;
use sp_runtime::{
traits::{BlakeTwo256, Block as BlockT, BlockNumberProvider, Hash},
traits::{Block as BlockT, BlockNumberProvider, Hash},
transaction_validity::{
InvalidTransaction, TransactionLongevity, TransactionSource, TransactionValidity,
ValidTransaction,
@@ -750,7 +750,7 @@ impl<T: Config> Pallet<T> {
weight_used += T::DmpMessageHandler::handle_dmp_messages(message_iter, max_weight);
<LastDmqMqcHead<T>>::put(&dmq_head);
Self::deposit_event(Event::DownwardMessagesProcessed(weight_used, dmq_head.0));
Self::deposit_event(Event::DownwardMessagesProcessed(weight_used, dmq_head.head()));
}
// After hashing each message in the message queue chain submitted by the collator, we
@@ -758,7 +758,7 @@ impl<T: Config> Pallet<T> {
//
// A mismatch means that at least some of the submitted messages were altered, omitted or
// added improperly.
assert_eq!(dmq_head.0, expected_dmq_mqc_head);
assert_eq!(dmq_head.head(), expected_dmq_mqc_head);
ProcessedDownwardMessages::<T>::put(dm_count);
@@ -945,43 +945,6 @@ impl<T: Config> frame_system::SetCode<T> for ParachainSetCode<T> {
}
}
/// 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.
///
/// [hash chain]: https://en.wikipedia.org/wiki/Hash_chain
#[derive(Default, Clone, codec::Encode, codec::Decode, scale_info::TypeInfo)]
struct MessageQueueChain(relay_chain::Hash);
impl MessageQueueChain {
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
}
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
}
fn head(&self) -> relay_chain::Hash {
self.0
}
}
impl<T: Config> Pallet<T> {
pub fn send_upward_message(message: UpwardMessage) -> Result<u32, MessageSendError> {
// Check if the message fits into the relay-chain constraints.
@@ -33,7 +33,10 @@ use frame_system::{InitKind, RawOrigin};
use hex_literal::hex;
use relay_chain::v1::HrmpChannelId;
use sp_core::H256;
use sp_runtime::{testing::Header, traits::IdentityLookup};
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use sp_version::RuntimeVersion;
use std::cell::RefCell;