Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cab6466
Start by replacing branch names and set `DownwardMessage`
bkchr Apr 30, 2020
20b7977
Add the upward-message crate
bkchr May 5, 2020
1b7065d
Add Kusama & Polkadot
bkchr May 7, 2020
0af3395
Merge remote-tracking branch 'origin/master' into bkchr-upward-downwa…
bkchr May 8, 2020
c1bcce8
More work on getting the upward messages working
bkchr May 14, 2020
495088a
Fix build
bkchr May 15, 2020
12d4f43
Merge remote-tracking branch 'origin/master' into bkchr-upward-downwa…
bkchr May 15, 2020
6f55f3a
Merge remote-tracking branch 'origin/master' into bkchr-upward-downwa…
bkchr May 15, 2020
bb23735
Begin to integrate it into the test Parachain
bkchr May 18, 2020
131fc35
Merge remote-tracking branch 'origin/master' into bkchr-upward-downwa…
bkchr May 19, 2020
8a0e3b0
Update
bkchr May 20, 2020
204097b
Make everything compile again
bkchr May 20, 2020
3ba4e80
Switch to westend and print parachain account on startup
bkchr May 20, 2020
c787fbf
Use MultiSignature etc
bkchr May 20, 2020
ca1c222
Fix validate block
bkchr May 22, 2020
3d96d81
Merge remote-tracking branch 'origin/master' into bkchr-upward-downwa…
bkchr Jun 5, 2020
f3c14c2
Some downward messages work
bkchr Jun 9, 2020
ec8f352
Update git reference
bkchr Jun 9, 2020
ab4d96f
More downward messages integration
bkchr Jun 9, 2020
95e0e3c
Update test runtime for downward messages
bkchr Jun 9, 2020
a3a4df1
Enable downward message handler and withdraw send tokens
bkchr Jun 9, 2020
9fde313
Add some docs
bkchr Jun 10, 2020
215444c
Begin to implement simple XCMP
bkchr Jun 11, 2020
348e688
More work
bkchr Jun 11, 2020
fcb66c4
Merge remote-tracking branch 'origin/master' into bkchr-upward-downwa…
bkchr Jun 11, 2020
d451f10
Fixes and make parachain id configurable
bkchr Jun 11, 2020
cd1a9e4
Make parachain ID be part of the genesis
bkchr Jun 11, 2020
7c987ce
Finishing the XCMP message demo
bkchr Jun 11, 2020
b52f9d6
Update and fixes tests
bkchr Jun 15, 2020
5df2315
Update branch
bkchr Jun 15, 2020
fe2b7ca
Merge remote-tracking branch 'origin/master' into bkchr-upward-downwa…
bkchr Jun 15, 2020
2a15c6f
Merge remote-tracking branch 'origin/master' into bkchr-upward-downwa…
bkchr Jun 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More work
  • Loading branch information
bkchr committed Jun 11, 2020
commit 348e6881705c2452820323e078e45ebcf2be9723
799 changes: 382 additions & 417 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions message-broker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ codec = { package = "parity-scale-codec", version = "1.3.0", features = [ "deriv

# Cumulus dependencies
cumulus-primitives = { path = "../primitives", default-features = false }
cumulus-upward-message = { path = "../upward-message", default-features = false }

[features]
default = [ "std" ]
Expand All @@ -30,4 +31,5 @@ std = [
"sp-runtime/std",
"codec/std",
"cumulus-primitives/std",
"cumulus-upward-message/std",
]
39 changes: 31 additions & 8 deletions message-broker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@

#![cfg_attr(not(feature = "std"), no_std)]

use codec::Encode;
use codec::{Encode, Decode};
use cumulus_primitives::{
inherents::{DownwardMessagesType, DOWNWARD_MESSAGES_IDENTIFIER},
well_known_keys, DownwardMessage, DownwardMessageHandler, GenericUpwardMessage,
UpwardMessageOrigin, UpwardMessageSender, xcmp::{XCMPMessageHandler, XCMPMessageSender}
well_known_keys,
xcmp::{RawXCMPMessage, XCMPMessageHandler, XCMPMessageSender},
DownwardMessage, DownwardMessageHandler, GenericUpwardMessage, ParaId, UpwardMessageOrigin,
UpwardMessageSender,
};
use cumulus_upward_message::XCMPMessage;
use frame_support::{
decl_event, decl_module, storage,
traits::Get,
Expand All @@ -46,13 +49,16 @@ pub trait Trait: frame_system::Trait {
type DownwardMessageHandlers: DownwardMessageHandler;

/// The upward message type used by the Parachain runtime.
type UpwardMessage: codec::Codec;
type UpwardMessage: codec::Codec + XCMPMessage;

/// The XCMP message handlers that will be informed when a XCMP message is received.
type XCMPMessageHandlers: XCMPMessageHandler;
type XCMPMessageHandlers: XCMPMessageHandler<Self::XCMPMessage>;

/// The XCMP message type used by the Parachain runtime.
type XCMPMessage: codec::Codec;

/// The Id of the parachain.
type ParachainId: Get<ParaId>;
}

decl_event! {
Expand All @@ -77,7 +83,16 @@ decl_module! {
// weight used by the handlers.
let max_messages = 10;
messages.iter().take(max_messages).for_each(|msg| {
T::DownwardMessageHandlers::handle_downward_message(msg);
match msg {
DownwardMessage::XCMPMessage(msg) => {
if let Ok(msg) = RawXCMPMessage::decode(&mut &msg[..]) {
if let Ok(xcmp_msg) = T::XCMPMessage::decode(&mut &msg.data[..]) {
T::XCMPMessageHandlers::handle_xcmp_message(msg.from, &xcmp_msg);
}
}
},
msg => T::DownwardMessageHandlers::handle_downward_message(msg),
}
});

let processed = sp_std::cmp::min(messages.len(), max_messages) as u32;
Expand Down Expand Up @@ -110,8 +125,16 @@ impl<T: Trait> UpwardMessageSender<T::UpwardMessage> for Module<T> {
}

impl<T: Trait> XCMPMessageSender<T::XCMPMessage> for Module<T> {
fn send_xcmp_message(msg: &Message) -> Result<(), ()> {

fn send_xcmp_message(dest: ParaId, msg: &T::XCMPMessage) -> Result<(), ()> {
let message = RawXCMPMessage {
from: T::ParachainId::get(),
data: msg.encode(),
};

Self::send_upward_message(
&T::UpwardMessage::send_message(dest, message.encode()),
UpwardMessageOrigin::Signed,
)
}
}

Expand Down
1 change: 1 addition & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub use polkadot_core_primitives::DownwardMessage;
/// Besides the `data` it also holds the `origin` of the message.
pub use polkadot_parachain::primitives::UpwardMessage as GenericUpwardMessage;
pub use polkadot_parachain::primitives::ParachainDispatchOrigin as UpwardMessageOrigin;
pub use polkadot_parachain::primitives::Id as ParaId;

pub mod validation_function_params;
pub mod xcmp;
Expand Down
11 changes: 6 additions & 5 deletions primitives/src/xcmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,26 @@
//! XMCP related primitives

use polkadot_primitives::parachain::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,
/// Parachain receiving the message.
pub to: 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(msg: &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.
fn send_xcmp_message(msg: &Message) -> Result<(), ()>;
/// Send a XCMP message to the given parachain.
fn send_xcmp_message(dest: ParaId, msg: &Message) -> Result<(), ()>;
}
12 changes: 12 additions & 0 deletions test/parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ pub const DAYS: BlockNumber = HOURS * 24;
// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);

#[derive(codec::Encode, codec::Decode)]
pub enum XCMPMessage {

}

/// The version infromation used to identify this runtime when compiled natively.
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
Expand Down Expand Up @@ -233,10 +238,17 @@ impl cumulus_parachain_upgrade::Trait for Runtime {
type OnValidationFunctionParams = ();
}

parameter_types! {
pub storage ParachainId: cumulus_primitives::ParaId = 100.into();
}

impl cumulus_message_broker::Trait for Runtime {
type Event = Event;
type DownwardMessageHandlers = TokenDealer;
type UpwardMessage = cumulus_upward_message::WestendUpwardMessage;
type ParachainId = ParachainId;
type XCMPMessage = XCMPMessage;
type XCMPMessageHandlers = ();
}

impl message_example::Trait for Runtime {
Expand Down
6 changes: 6 additions & 0 deletions upward-message/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

[dependencies]
# Substrate dependencies
sp-std = { git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch", default-features = false }

# Polkadot deps
polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", branch = "bkchr-cumulus-branch", default-features = false }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "bkchr-cumulus-branch", default-features = false }

# All these should be optional dependenices, but given the perfect Cargo, it is not possible.
polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "bkchr-cumulus-branch", default-features = false }
Expand All @@ -16,10 +20,12 @@ westend-runtime = { git = "https://github.com/paritytech/polkadot", branch = "bk
[features]
default = [ "std" ]
std = [
"sp-std/std",
"polkadot-runtime/std",
"kusama-runtime/std",
"westend-runtime/std",
"polkadot-core-primitives/std",
"polkadot-parachain/std",
]
# Should be enabled by when compiling the runtime for WASM.
#
Expand Down
9 changes: 8 additions & 1 deletion upward-message/src/kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

use crate::*;
use polkadot_core_primitives::{Balance, AccountId};
use kusama_runtime::BalancesCall;
use kusama_runtime::{BalancesCall, ParachainsCall};
use sp_std::vec::Vec;

/// The Kusama upward message.
pub type UpwardMessage = kusama_runtime::Call;
Expand All @@ -28,3 +29,9 @@ impl BalancesMessage<AccountId, Balance> for UpwardMessage {
BalancesCall::transfer(dest, amount).into()
}
}

impl XCMPMessage for UpwardMessage {
fn send_message(dest: ParaId, msg: Vec<u8>) -> Self {
ParachainsCall::send_xcmp_message(dest, msg).into()
}
}
9 changes: 9 additions & 0 deletions upward-message/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#![cfg_attr(not(feature = "std"), no_std)]

use polkadot_parachain::primitives::Id as ParaId;
use sp_std::vec::Vec;

mod polkadot;
mod kusama;
mod westend;
Expand All @@ -36,3 +39,9 @@ pub trait BalancesMessage<AccountId, Balance>: Sized {
/// `dest` account.
fn transfer(dest: AccountId, amount: Balance) -> Self;
}

/// A `XCMP` related upward message.
pub trait XCMPMessage: Sized {
/// Send the given XCMP message to given parachain.
fn send_message(dest: ParaId, msg: Vec<u8>) -> Self;
}
9 changes: 8 additions & 1 deletion upward-message/src/polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

use crate::*;
use polkadot_core_primitives::{Balance, AccountId};
use polkadot_runtime::BalancesCall;
use polkadot_runtime::{BalancesCall, ParachainsCall};
use sp_std::vec::Vec;

/// The Polkadot upward message.
pub type UpwardMessage = polkadot_runtime::Call;
Expand All @@ -28,3 +29,9 @@ impl BalancesMessage<AccountId, Balance> for UpwardMessage {
BalancesCall::transfer(dest, amount).into()
}
}

impl XCMPMessage for UpwardMessage {
fn send_message(dest: ParaId, msg: Vec<u8>) -> Self {
ParachainsCall::send_xcmp_message(dest, msg).into()
}
}
9 changes: 8 additions & 1 deletion upward-message/src/westend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

use crate::*;
use polkadot_core_primitives::{Balance, AccountId};
use westend_runtime::BalancesCall;
use westend_runtime::{BalancesCall, ParachainsCall};
use sp_std::vec::Vec;

/// The Westend upward message.
pub type UpwardMessage = westend_runtime::Call;
Expand All @@ -28,3 +29,9 @@ impl BalancesMessage<AccountId, Balance> for UpwardMessage {
BalancesCall::transfer(dest, amount).into()
}
}

impl XCMPMessage for UpwardMessage {
fn send_message(dest: ParaId, msg: Vec<u8>) -> Self {
ParachainsCall::send_xcmp_message(dest, msg).into()
}
}