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
Finishing the XCMP message demo
  • Loading branch information
bkchr committed Jun 11, 2020
commit 7c987cedeadf579b9b812d1fa9cc5323396757c2
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion message-broker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<T: Trait> XCMPMessageSender<T::XCMPMessage> for Module<T> {

Self::send_upward_message(
&T::UpwardMessage::send_message(dest, message.encode()),
UpwardMessageOrigin::Signed,
UpwardMessageOrigin::Parachain,
)
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/parachain/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ cumulus-message-broker = { path = "../../../message-broker", default-features =
cumulus-upward-message = { path = "../../../upward-message", default-features = false }
cumulus-primitives = { path = "../../../primitives", default-features = false }

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

[build-dependencies]
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.6" }

Expand Down Expand Up @@ -69,6 +72,7 @@ std = [
"cumulus-message-broker/std",
"cumulus-upward-message/std",
"cumulus-primitives/std",
"polkadot-parachain/std",
]
# Will be enabled by the `wasm-builder` when building the runtime for WASM.
runtime-wasm = [
Expand Down
10 changes: 6 additions & 4 deletions test/parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ pub const DAYS: BlockNumber = HOURS * 24;
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);

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

pub enum XCMPMessage<XAccountId, XBalance> {
/// Transfer tokens to the given account from the Parachain account.
TransferToken(XAccountId, XBalance),
}

/// The version infromation used to identify this runtime when compiled natively.
Expand Down Expand Up @@ -247,15 +248,16 @@ impl cumulus_message_broker::Trait for Runtime {
type DownwardMessageHandlers = TokenDealer;
type UpwardMessage = cumulus_upward_message::WestendUpwardMessage;
type ParachainId = ParachainId;
type XCMPMessage = XCMPMessage;
type XCMPMessageHandlers = ();
type XCMPMessage = XCMPMessage<AccountId, Balance>;
type XCMPMessageHandlers = TokenDealer;
}

impl message_example::Trait for Runtime {
type Event = Event;
type UpwardMessageSender = MessageBroker;
type UpwardMessage = cumulus_upward_message::WestendUpwardMessage;
type Currency = Balances;
type XCMPMessageSender = MessageBroker;
}

construct_runtime! {
Expand Down
64 changes: 60 additions & 4 deletions test/parachain/runtime/src/message_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ use frame_support::{
};
use frame_system::ensure_signed;

use crate::XCMPMessage;
use codec::{Decode, Encode};
use cumulus_primitives::{
relay_chain::DownwardMessage, DownwardMessageHandler, ParaId, UpwardMessageOrigin,
UpwardMessageSender,
relay_chain::DownwardMessage,
xcmp::{XCMPMessageHandler, XCMPMessageSender},
DownwardMessageHandler, ParaId, UpwardMessageOrigin, UpwardMessageSender,
};
use cumulus_upward_message::BalancesMessage;
use polkadot_parachain::primitives::AccountIdConversion;
use sp_runtime::DispatchResult;

type BalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
Expand All @@ -46,6 +50,9 @@ pub trait Trait: frame_system::Trait {

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

/// The sender of XCMP messages.
type XCMPMessageSender: XCMPMessageSender<XCMPMessage<Self::AccountId, BalanceOf<Self>>>;
}

// This pallet's storage items.
Expand All @@ -70,6 +77,8 @@ decl_event! {
TransferredTokensToRelayChain(AccountId, Balance),
/// Transferred tokens to the account on request from the relay chain.
TransferredTokensFromRelayChain(AccountId, Balance),
/// Transferred tokens to the account from the given parachain account.
TransferredTokensViaXCMP(ParaId, AccountId, Balance, DispatchResult),
}
}

Expand All @@ -78,8 +87,7 @@ 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: T::AccountId, amount: BalanceOf<T>) {
//TODO: Remove the tokens from the given account
fn transfer_tokens_to_relay_chain(origin, dest: T::AccountId, amount: BalanceOf<T>) {
let who = ensure_signed(origin)?;

let _ = T::Currency::withdraw(
Expand All @@ -96,6 +104,30 @@ decl_module! {
Self::deposit_event(Event::<T>::TransferredTokensToRelayChain(dest, amount));
}

/// Transfer `amount` of tokens to another parachain.
#[weight = 10]
fn transfer_tokens_to_parachain_chain(
origin,
para_id: u32,
dest: T::AccountId,
amount: BalanceOf<T>,
) {
//TODO we don't make sure that the parachain has some tokens on the other parachain.
let who = ensure_signed(origin)?;

let _ = T::Currency::withdraw(
&who,
amount,
WithdrawReason::Transfer.into(),
ExistenceRequirement::AllowDeath,
)?;

T::XCMPMessageSender::send_xcmp_message(
para_id.into(),
&XCMPMessage::TransferToken(dest, amount),
).expect("Should not fail; qed");
}

fn deposit_event() = default;
}
}
Expand All @@ -121,3 +153,27 @@ impl<T: Trait> DownwardMessageHandler for Module<T> {
}
}
}

impl<T: Trait> XCMPMessageHandler<XCMPMessage<T::AccountId, BalanceOf<T>>> for Module<T> {
fn handle_xcmp_message(src: ParaId, msg: &XCMPMessage<T::AccountId, BalanceOf<T>>) {
match msg {
XCMPMessage::TransferToken(dest, amount) => {
let para_account = src.clone().into_account();

let res = T::Currency::transfer(
&para_account,
dest,
amount.clone(),
ExistenceRequirement::AllowDeath,
);

Self::deposit_event(Event::<T>::TransferredTokensViaXCMP(
src,
dest.clone(),
amount.clone(),
res,
));
}
}
}
}