mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 17:41:08 +00:00
Integrate HRMP (#258)
* HRMP message ingestion * Plumb hrmp_watermark to build_collation * Plumb hrmp_watermark to ValidationResult * Plumb hrmp outbound messages * Implement message-broker part of HRMP * Kill UPWARD_MESSAGES as well Otherwise, they will get resent each block * Add sudo versions for easier testing * Remove the xcmp module Not useful for the moment * Doc for HRMP message handler * Estimate the weight upper bound for on_finalize * Remove a redundant type annotation * fix spelling of a method * Apply suggestions from code review Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Deabbreviate dmp and hrmp in the message ingestion type * Don't use binary_search since it's broken by a following rotate Instead use the linear search. We can afford linear search here since due to limited scalability of HRMP we can only have at most a couple of dozens of channels. * Fix the watermark Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
+43
-6
@@ -27,17 +27,35 @@ pub use polkadot_primitives::v1::{
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub mod genesis;
|
||||
pub mod xcmp;
|
||||
|
||||
/// An inbound HRMP message.
|
||||
pub type InboundHrmpMessage = polkadot_primitives::v1::InboundHrmpMessage<relay_chain::BlockNumber>;
|
||||
|
||||
/// And outbound HRMP message
|
||||
pub type OutboundHrmpMessage = polkadot_primitives::v1::OutboundHrmpMessage<ParaId>;
|
||||
|
||||
/// Identifiers and types related to Cumulus Inherents
|
||||
pub mod inherents {
|
||||
use sp_inherents::InherentIdentifier;
|
||||
use sp_std::{
|
||||
vec::Vec,
|
||||
collections::btree_map::BTreeMap,
|
||||
};
|
||||
use super::{InboundDownwardMessage, InboundHrmpMessage, ParaId};
|
||||
|
||||
/// Inherent identifier for downward messages.
|
||||
pub const DOWNWARD_MESSAGES_IDENTIFIER: InherentIdentifier = *b"cumdownm";
|
||||
|
||||
/// The type of the inherent downward messages.
|
||||
pub type DownwardMessagesType = sp_std::vec::Vec<crate::InboundDownwardMessage>;
|
||||
/// Inherent identifier for message ingestion inherent.
|
||||
pub const MESSAGE_INGESTION_IDENTIFIER: InherentIdentifier = *b"msgingst";
|
||||
/// The data passed via a message ingestion inherent. Consists of a bundle of
|
||||
/// DMP and HRMP messages.
|
||||
#[derive(codec::Encode, codec::Decode, sp_core::RuntimeDebug, Clone, PartialEq)]
|
||||
pub struct MessageIngestionType {
|
||||
/// Downward messages in the order they were sent.
|
||||
pub downward_messages: Vec<InboundDownwardMessage>,
|
||||
/// HRMP messages grouped by channels. The messages in the inner vec must be in order they
|
||||
/// were sent. In combination with the rule of no more than one message in a channel per block,
|
||||
/// this means `sent_at` is **strictly** greater than the previous one (if any).
|
||||
pub horizontal_messages: BTreeMap<ParaId, Vec<InboundHrmpMessage>>,
|
||||
}
|
||||
|
||||
/// The identifier for the `set_validation_data` inherent.
|
||||
pub const VALIDATION_DATA_IDENTIFIER: InherentIdentifier = *b"valfunp0";
|
||||
@@ -58,6 +76,18 @@ pub mod well_known_keys {
|
||||
/// Code upgarde (set as appropriate by a pallet).
|
||||
pub const NEW_VALIDATION_CODE: &'static [u8] = b":cumulus_new_validation_code:";
|
||||
|
||||
/// The storage key with which the runtime passes outbound HRMP messages it wants to send to the
|
||||
/// PVF.
|
||||
///
|
||||
/// The value is stored as SCALE encoded `Vec<OutboundHrmpMessage>`
|
||||
pub const HRMP_OUTBOUND_MESSAGES: &'static [u8] = b":cumulus_hrmp_outbound_messages:";
|
||||
|
||||
/// The storage key for communicating the HRMP watermark from the runtime to the PVF. Cleared by
|
||||
/// the runtime each block and set after message inclusion, but only if there were messages.
|
||||
///
|
||||
/// The value is stored as SCALE encoded relay-chain's `BlockNumber`.
|
||||
pub const HRMP_WATERMARK: &'static [u8] = b":cumulus_hrmp_watermark:";
|
||||
|
||||
/// The storage key for the processed downward messages.
|
||||
///
|
||||
/// The value is stored as SCALE encoded `u32`.
|
||||
@@ -71,6 +101,13 @@ pub trait DownwardMessageHandler {
|
||||
fn handle_downward_message(msg: InboundDownwardMessage);
|
||||
}
|
||||
|
||||
/// Something that should be called when an HRMP message is received.
|
||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||
pub trait HrmpMessageHandler {
|
||||
/// Handle the given HRMP message.
|
||||
fn handle_hrmp_message(sender: ParaId, msg: InboundHrmpMessage);
|
||||
}
|
||||
|
||||
/// A trait which is called when the validation data is set.
|
||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||
pub trait OnValidationData {
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! XMCP related primitives
|
||||
|
||||
use polkadot_primitives::v0::Id as ParaId;
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
/// A raw XCMP message that is being send between two Parachain's.
|
||||
#[derive(codec::Encode, codec::Decode)]
|
||||
pub struct RawXCMPMessage {
|
||||
/// Parachain sending the message.
|
||||
pub from: ParaId,
|
||||
/// SCALE encoded message.
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
/// Something that can handle XCMP messages.
|
||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||
pub trait XCMPMessageHandler<Message: codec::Decode> {
|
||||
/// Handle a XCMP message.
|
||||
fn handle_xcmp_message(src: ParaId, msg: &Message);
|
||||
}
|
||||
|
||||
/// Something that can send XCMP messages.
|
||||
pub trait XCMPMessageSender<Message: codec::Encode> {
|
||||
/// Send a XCMP message to the given parachain.
|
||||
fn send_xcmp_message(dest: ParaId, msg: &Message) -> Result<(), ()>;
|
||||
}
|
||||
Reference in New Issue
Block a user