Implement basic upward & downward messages (#118)

* Start by replacing branch names and set `DownwardMessage`

* Add the upward-message crate

* Add Kusama & Polkadot

* More work on getting the upward messages working

* Fix build

* Begin to integrate it into the test Parachain

* Update

* Make everything compile again

* Switch to westend and print parachain account on startup

* Use MultiSignature etc

* Fix validate block

* Some downward messages work

* Update git reference

* More downward messages integration

* Update test runtime for downward messages

* Enable downward message handler and withdraw send tokens

* Add some docs

* Begin to implement simple XCMP

* More work

* Fixes and make parachain id configurable

* Make parachain ID be part of the genesis

* Finishing the XCMP message demo

* Update and fixes tests

* Update branch
This commit is contained in:
Bastian Köcher
2020-06-18 12:10:20 +02:00
committed by GitHub
parent 071d7a11c4
commit c9aaddf667
30 changed files with 1037 additions and 391 deletions
+37
View File
@@ -0,0 +1,37 @@
// 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/>.
//! Kusama upward message
use crate::*;
use polkadot_core_primitives::{Balance, AccountId};
use kusama_runtime::{BalancesCall, ParachainsCall};
use sp_std::vec::Vec;
/// The Kusama upward message.
pub type UpwardMessage = kusama_runtime::Call;
impl BalancesMessage<AccountId, Balance> for UpwardMessage {
fn transfer(dest: AccountId, amount: Balance) -> Self {
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()
}
}
+47
View File
@@ -0,0 +1,47 @@
// 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/>.
//! Upward messages types and traits for Polkadot, Kusama and Westend.
//!
//! As Cumulus needs to suits multiple Polkadot-like runtimes the upward message
//! type is different for each of them. To support all of them, Cumulus provides
//! traits to write upward message generic code.
#![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;
pub use polkadot::UpwardMessage as PolkadotUpwardMessage;
pub use kusama::UpwardMessage as KusamaUpwardMessage;
pub use westend::UpwardMessage as WestendUpwardMessage;
/// A `Balances` related upward message.
pub trait BalancesMessage<AccountId, Balance>: Sized {
/// Transfer the given `amount` from the parachain account to the given
/// `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;
}
+37
View File
@@ -0,0 +1,37 @@
// 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/>.
//! Polkadot upward message
use crate::*;
use polkadot_core_primitives::{Balance, AccountId};
use polkadot_runtime::{BalancesCall, ParachainsCall};
use sp_std::vec::Vec;
/// The Polkadot upward message.
pub type UpwardMessage = polkadot_runtime::Call;
impl BalancesMessage<AccountId, Balance> for UpwardMessage {
fn transfer(dest: AccountId, amount: Balance) -> Self {
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()
}
}
+37
View File
@@ -0,0 +1,37 @@
// 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/>.
//! Westend upward message
use crate::*;
use polkadot_core_primitives::{Balance, AccountId};
use westend_runtime::{BalancesCall, ParachainsCall};
use sp_std::vec::Vec;
/// The Westend upward message.
pub type UpwardMessage = westend_runtime::Call;
impl BalancesMessage<AccountId, Balance> for UpwardMessage {
fn transfer(dest: AccountId, amount: Balance) -> Self {
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()
}
}