mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
Resurrect (a minimal version of) message-broker (#234)
This is mostly a copy of the predating version with exception of some renaming and alterations (e.g. the message handler takes an inbound downward message by value, not by reference).
This commit is contained in:
Generated
+13
@@ -1112,6 +1112,18 @@ dependencies = [
|
||||
"tokio 0.1.22",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cumulus-message-broker"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cumulus-primitives",
|
||||
"frame-support",
|
||||
"frame-system",
|
||||
"parity-scale-codec",
|
||||
"sp-inherents",
|
||||
"sp-std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cumulus-network"
|
||||
version = "0.1.0"
|
||||
@@ -1255,6 +1267,7 @@ dependencies = [
|
||||
name = "cumulus-test-parachain-runtime"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cumulus-message-broker",
|
||||
"cumulus-parachain-upgrade",
|
||||
"cumulus-primitives",
|
||||
"cumulus-runtime",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"consensus",
|
||||
"message-broker",
|
||||
"network",
|
||||
"parachain-upgrade",
|
||||
"primitives",
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
[package]
|
||||
name = "cumulus-message-broker"
|
||||
version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
# Substrate dependencies
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" }
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
|
||||
# Other dependencies
|
||||
codec = { package = "parity-scale-codec", version = "1.3.0", features = [ "derive" ], default-features = false }
|
||||
|
||||
# Cumulus dependencies
|
||||
cumulus-primitives = { path = "../primitives", default-features = false }
|
||||
|
||||
[features]
|
||||
default = [ "std" ]
|
||||
std = [
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
"sp-inherents/std",
|
||||
"cumulus-primitives/std",
|
||||
"sp-std/std"
|
||||
]
|
||||
@@ -0,0 +1,74 @@
|
||||
// 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/>.
|
||||
|
||||
//! This pallet deals with the low-level details of parachain message passing.
|
||||
//!
|
||||
//! Specifically, this pallet serves as a glue layer between cumulus collation pipeline and the
|
||||
//! runtime that hosts this pallet.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use frame_system::ensure_none;
|
||||
use frame_support::{decl_module, storage, weights::DispatchClass};
|
||||
use sp_inherents::{InherentData, InherentIdentifier, MakeFatalError, ProvideInherent};
|
||||
|
||||
use cumulus_primitives::{
|
||||
inherents::{DownwardMessagesType, DOWNWARD_MESSAGES_IDENTIFIER},
|
||||
well_known_keys,
|
||||
DownwardMessageHandler, InboundDownwardMessage,
|
||||
};
|
||||
|
||||
/// Configuration trait of the message broker pallet.
|
||||
pub trait Trait: frame_system::Trait {
|
||||
/// The downward message handlers that will be informed when a message is received.
|
||||
type DownwardMessageHandlers: DownwardMessageHandler;
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
/// An entrypoint for an inherent to deposit downward messages into the runtime. It accepts
|
||||
/// and processes the list of downward messages.
|
||||
#[weight = (10, DispatchClass::Mandatory)]
|
||||
fn receive_downward_messages(origin, messages: Vec<InboundDownwardMessage>) {
|
||||
ensure_none(origin)?;
|
||||
|
||||
let messages_len = messages.len() as u32;
|
||||
for message in messages {
|
||||
T::DownwardMessageHandlers::handle_downward_message(message);
|
||||
}
|
||||
|
||||
// Store the processed_downward_messages here so that it's will be accessible from
|
||||
// PVF's `validate_block` wrapper and collation pipeline.
|
||||
storage::unhashed::put(
|
||||
well_known_keys::PROCESSED_DOWNWARD_MESSAGES,
|
||||
&messages_len,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> ProvideInherent for Module<T> {
|
||||
type Call = Call<T>;
|
||||
type Error = MakeFatalError<()>;
|
||||
const INHERENT_IDENTIFIER: InherentIdentifier = DOWNWARD_MESSAGES_IDENTIFIER;
|
||||
|
||||
fn create_inherent(data: &InherentData) -> Option<Self::Call> {
|
||||
data.get_data::<DownwardMessagesType>(&DOWNWARD_MESSAGES_IDENTIFIER)
|
||||
.expect("Downward messages inherent data failed to decode")
|
||||
.map(|msgs| Call::receive_downward_messages(msgs))
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ pub mod well_known_keys {
|
||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||
pub trait DownwardMessageHandler {
|
||||
/// Handle the given downward message.
|
||||
fn handle_downward_message(msg: &InboundDownwardMessage);
|
||||
fn handle_downward_message(msg: InboundDownwardMessage);
|
||||
}
|
||||
|
||||
/// A trait which is called when the validation data is set.
|
||||
|
||||
@@ -37,6 +37,7 @@ pallet-transaction-payment = { git = "https://github.com/paritytech/substrate",
|
||||
cumulus-runtime = { path = "../../runtime", default-features = false }
|
||||
cumulus-parachain-upgrade = { path = "../../parachain-upgrade", default-features = false }
|
||||
cumulus-primitives = { path = "../../primitives", default-features = false }
|
||||
cumulus-message-broker = { path = "../../message-broker", default-features = false }
|
||||
|
||||
# Polkadot dependencies
|
||||
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "master" }
|
||||
@@ -72,5 +73,6 @@ std = [
|
||||
"rococo-parachain-primitives/std",
|
||||
"cumulus-runtime/std",
|
||||
"cumulus-parachain-upgrade/std",
|
||||
"cumulus-message-broker/std",
|
||||
"cumulus-primitives/std",
|
||||
]
|
||||
|
||||
@@ -200,6 +200,10 @@ impl cumulus_parachain_upgrade::Trait for Runtime {
|
||||
type OnValidationData = ();
|
||||
}
|
||||
|
||||
impl cumulus_message_broker::Trait for Runtime {
|
||||
type DownwardMessageHandlers = ();
|
||||
}
|
||||
|
||||
impl parachain_info::Trait for Runtime {}
|
||||
|
||||
construct_runtime! {
|
||||
@@ -214,6 +218,7 @@ construct_runtime! {
|
||||
Sudo: pallet_sudo::{Module, Call, Storage, Config<T>, Event<T>},
|
||||
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
|
||||
ParachainUpgrade: cumulus_parachain_upgrade::{Module, Call, Storage, Inherent, Event},
|
||||
MessageBroker: cumulus_message_broker::{Module, Call, Inherent},
|
||||
TransactionPayment: pallet_transaction_payment::{Module, Storage},
|
||||
ParachainInfo: parachain_info::{Module, Storage, Config},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user