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
Update test runtime for downward messages
  • Loading branch information
bkchr committed Jun 9, 2020
commit 95e0e3c54419afaa15f90f7a5b2cdd748aecb22e
3 changes: 2 additions & 1 deletion test/parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl message_example::Trait for Runtime {
type Event = Event;
type UpwardMessageSender = MessageBroker;
type UpwardMessage = cumulus_upward_message::WestendUpwardMessage;
type Currency = Balances;
}

construct_runtime! {
Expand All @@ -258,7 +259,7 @@ construct_runtime! {
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
ParachainUpgrade: cumulus_parachain_upgrade::{Module, Call, Storage, Inherent, Event},
MessageBroker: cumulus_message_broker::{Module, Call, Inherent, Event<T>},
TokenDealer: message_example::{Module, Call, Event},
TokenDealer: message_example::{Module, Call, Event<T>},
TransactionPayment: pallet_transaction_payment::{Module, Storage},
}
}
Expand Down
50 changes: 40 additions & 10 deletions test/parachain/runtime/src/message_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,41 @@
//! Example Pallet that shows how to send upward messages and how to receive
//! downward messages.

use frame_support::{decl_event, decl_module};
use frame_support::{decl_event, decl_module, traits::Currency};
use frame_system::ensure_signed;

use codec::{Decode, Encode};
use cumulus_primitives::{
relay_chain::{AccountId as RAccountId, Balance as RBalance},
UpwardMessageOrigin, UpwardMessageSender,
relay_chain::DownwardMessage, DownwardMessageHandler, UpwardMessageOrigin, UpwardMessageSender,
};
use cumulus_upward_message::BalancesMessage;

type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;

/// Configuration trait of this pallet.
pub trait Trait: frame_system::Trait {
/// Event type used by the runtime.
type Event: From<Event> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;

/// The sender of upward messages.
type UpwardMessageSender: UpwardMessageSender<Self::UpwardMessage>;

/// The upward message type used by the Parachain runtime.
type UpwardMessage: codec::Codec + BalancesMessage;
type UpwardMessage: codec::Codec + BalancesMessage<Self::AccountId, BalanceOf<Self>>;

/// Currency of the runtime.
type Currency: Currency<Self::AccountId>;
}

decl_event! {
pub enum Event {
pub enum Event<T> where
AccountId = <T as frame_system::Trait>::AccountId,
Balance = BalanceOf<T>
{
/// Transferred tokens to the account on the relay chain.
TransferredTokens(RAccountId, RBalance),
TransferredTokensToRelayChain(AccountId, Balance),
/// Transferred tokens to the account on request from the relay chain.
TransferredTokensFromRelayChain(AccountId, Balance),
}
}

Expand All @@ -50,17 +60,37 @@ decl_module! {
/// Transfer `amount` of tokens on the relay chain from the Parachain account to
/// the given `dest` account.
#[weight = 10]
fn transfer_tokens(origin, dest: RAccountId, amount: RBalance) {
fn transfer_tokens(origin, dest: T::AccountId, amount: BalanceOf<T>) {
//TODO: Remove the tokens from the given account
ensure_signed(origin)?;

let msg = <T as Trait>::UpwardMessage::transfer(dest.clone(), amount);
let msg = <T as Trait>::UpwardMessage::transfer(dest.clone(), amount.clone());
<T as Trait>::UpwardMessageSender::send_upward_message(&msg, UpwardMessageOrigin::Signed)
.expect("Should not fail; qed");

Self::deposit_event(Event::TransferredTokens(dest, amount));
Self::deposit_event(Event::<T>::TransferredTokensToRelayChain(dest, amount));
}

fn deposit_event() = default;
}
}

fn convert_hack<O: Decode>(input: &impl Encode) -> O {
input.using_encoded(|e| Decode::decode(&mut &e[..]).expect("Must be compatible; qed"))
}

impl<T: Trait> DownwardMessageHandler for Module<T> {
fn handle_downward_message(msg: &DownwardMessage) {
match msg {
DownwardMessage::TransferInto(dest, amount, _) => {
let dest = convert_hack(&dest);
let amount: BalanceOf<T> = convert_hack(amount);

let _ = T::Currency::deposit_creating(&dest, amount.clone());

Self::deposit_event(Event::<T>::TransferredTokensFromRelayChain(dest, amount));
}
_ => {}
}
}
}
2 changes: 1 addition & 1 deletion upward-message/src/kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use kusama_runtime::BalancesCall;
/// The Kusama upward message.
pub type UpwardMessage = kusama_runtime::Call;

impl BalancesMessage for UpwardMessage {
impl BalancesMessage<AccountId, Balance> for UpwardMessage {
fn transfer(dest: AccountId, amount: Balance) -> Self {
BalancesCall::transfer(dest, amount).into()
}
Expand Down
4 changes: 1 addition & 3 deletions upward-message/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

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

use polkadot_core_primitives::{Balance, AccountId};

mod polkadot;
mod kusama;
mod westend;
Expand All @@ -33,7 +31,7 @@ pub use kusama::UpwardMessage as KusamaUpwardMessage;
pub use westend::UpwardMessage as WestendUpwardMessage;

/// A `Balances` related upward message.
pub trait BalancesMessage: Sized {
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;
Expand Down
2 changes: 1 addition & 1 deletion upward-message/src/polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use polkadot_runtime::BalancesCall;
/// The Polkadot upward message.
pub type UpwardMessage = polkadot_runtime::Call;

impl BalancesMessage for UpwardMessage {
impl BalancesMessage<AccountId, Balance> for UpwardMessage {
fn transfer(dest: AccountId, amount: Balance) -> Self {
BalancesCall::transfer(dest, amount).into()
}
Expand Down
2 changes: 1 addition & 1 deletion upward-message/src/westend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use westend_runtime::BalancesCall;
/// The Westend upward message.
pub type UpwardMessage = westend_runtime::Call;

impl BalancesMessage for UpwardMessage {
impl BalancesMessage<AccountId, Balance> for UpwardMessage {
fn transfer(dest: AccountId, amount: Balance) -> Self {
BalancesCall::transfer(dest, amount).into()
}
Expand Down