Skip to content
This repository has been archived by the owner on Oct 15, 2021. It is now read-only.

Include Cross-Chain Transfers #2

Closed
JoshOrndorff opened this issue Jun 16, 2020 · 2 comments
Closed

Include Cross-Chain Transfers #2

JoshOrndorff opened this issue Jun 16, 2020 · 2 comments

Comments

@JoshOrndorff
Copy link
Owner

JoshOrndorff commented Jun 16, 2020

When paritytech/cumulus#118 is merged into cumulus, it will be possible to demonstrate cross-chain taken transfers. The test collator has also improved significantly since this workshop was first written and it is now ready to shine. Here is a draft for the flow of the workshop. These instructions reproduce the results demonstrated in https://twitter.com/bkchr/status/1263608038923083779?s=20 and https://twitter.com/bkchr/status/1270479898696695808?s=20

Overview

In this demonstration we will launch a relay chain with three validators. We will launch two parachains, each with a single collator, and register the parachains with the relay chain. We will transfer tokens from the relay chain to each parachain and back.

Setup

You'll need several files to complete this exercise:

  • Cumulus test collator binary
  • Polkadot binary
  • Polkadot chainspec file
  • Parachain runtime wasm

Download the cumulus assets here. (These binaries are for linux 64 bit.)

You'll need five terminals for the five total nodes. I'll refer to the nodes and the terminal's in which they run as Alice, Bob, Charlie, Collator100, and Collator99.

Launch the relay chain

You need a polkadot chainspec that calls for at least three validators. You need three because you need one assigned to each of the two parachains, and one for local relay chain duty.

# In alice's terminal (Alice is using the default websocket and libp2p ports)
polkadot --base-path /tmp/alice --chain polkadot_chainspec.json --alice --port 30333 --ws-port 9944

# In bob's terminal
polkadot --base-path /tmp/bob --chain polkadot_chainspec.json --bob --port 40444 --ws-port 9955

# In charlie's terminal
polkadot --base-path /tmp/bob --chain polkadot_chainspec.json --port 50555 --ws-port 9966

After a short time the nodes will discover each other and peer. If you are running on seperate physical machines, you will need to supply the subsequent nodes with a --bootnodes flag and point it to the network location of another node.

Launch the parachain

Before we launch the chain, we'll export it's state. This creates a file called genesis-state-100 that contains the parachain's starting state. We'll need this information later when registering the parachain with the relaychain.

collator export-genesis-state --parachain-id 100 genesis-state-100

These instructions are for launching the first parachain, you may repeat to launch the second parachain. And you could repeat to launch even more parachains, but you would need more validators in the relay chain to support that many parachains.

# In Collator100's terminal
collator --base-path /tmp/collator100 --ws-port 9977 --parachain-id 100 -- --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/<ALICE'S PEER ID>

Notice we didn't give the collator a polkadot chainspec. It is currently hard-coded.

Register the parachain

Connect the polkadot js Apps user interface to Alice's node. https://polkadot.js.org/apps/ To connect to Alice, use ws://127.0.0.1:9944/

Use the sudo tab to submit the registrar registerPara extrinsic. Params are

Parachain ID: 100
Scheduling: Always
code: upload the parachain runtime code
initial_head_data: upload the genesis-state-100 file.

You should notice that the collator begins authoring blocks.

Transfer tokens to Parachain 100

Open a second instance of Apps and connect it to Collator100 (ws://127.0.0.1:9977). You'll need to enter these custom types:

{
  "Address": "AccountId",
  "LookupSource": "AccountId",
  "ValidationFunctionParams": {
    "max_code_size": "u32",
    "relay_chain_height": "BlockNumber",
    "code_upgrade_allowed": "Option<BlockNumber>"
  }
}

Open the accounts tab and watch Alice's balance to see when the incoming transfer arrives. Back in the UI that's connected to Alice on the relay chain, navigate to extrinsics and submit parachains::TransferToParachain extrinsic.

to: 100
amount: whatever you like
remark: Recipient's address on the parachain

Transfer tokens back to the relay chain

In The UI connected to collator100, submit the tokenDealer::transferTokensToRelayChain. Enter the destination account on the relay chain and the number of tokens to transfer as you desire. Confirm you balance has increased on the relay chain.

@JoshOrndorff
Copy link
Owner Author

cc @joepetrowski

@JoshOrndorff
Copy link
Owner Author

This process is now detailed in the main workshop.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant