Daan van der Plas
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
1
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
Guide on manually setting up a parachain with a [collator](https://wiki.polkadot.network/docs/learn-collator) using custom keys (not using dev accounts such as `Alice` & `Bob`). ### Prerequisites You should be comfortable with the following tutorials: * https://docs.substrate.io/tutorials/build-a-parachain/prepare-a-local-relay-chain/ * https://docs.substrate.io/tutorials/build-a-parachain/connect-a-local-parachain/ # Setup ## Build the Polkadot and Parachain binaries. Make sure they are compiled based on the same release version. If you want to connect the parachain to an already running Relay chain you can skip the Polkadot steps. * Build Polkadot: ``` git clone https://github.com/paritytech/polkadot cd polkadot git checkout <release> cargo b -r ``` * Build Parachain: ``` git clone https://github.com/substrate-developer-hub/substrate-parachain-template cd substrate-parachain-template git checkout <polkadot-release> cargo b -r ``` ## Generate chainspec, runtime wasm, genesis state ### Chainspec plain: ``` ./target/release/parachain-template-node build-spec --disable-default-bootnode > parachain-chainspec.json ``` **Important**: edit the `parachain-chainspec.json` where necessary. For example; set the correct `para-id`, `protocolid` or `relay_chain`. The `para-id` needs to be reserved on the Relay Chain. Check out the ["Connect a local Parachain"](https://docs.substrate.io/tutorials/build-a-parachain/connect-a-local-parachain/) tutorial and look for the step *"Reserve a unique identifier"* raw: ``` ./target/release/parachain-template-node build-spec --chain parachain-chainspec.json --disable-default-bootnode --raw > parachain-chainspec-raw.json ``` ### Runtime wasm Required to register the Parachain on the Relay Chain. The Relay Chain needs the runtime code to validate blocks. ``` ./target/release/parachain-template-node export-genesis-wasm --chain parachain-chainspec-raw.json parachain-wasm ``` ### Genesis state Required to register the Parachain on the Relay Chain. Both the Relay Chain and the Parachain need to start from the same starting state. ``` ./target/release/parachain-template-node export-genesis-state --chain parachain-chainspec-raw.json parachain-genesis-state ``` # Launch ## Relay Chain Either follow the tutorial ["Prepare a local Relay Chain"](https://docs.substrate.io/tutorials/build-a-parachain/prepare-a-local-relay-chain/), use [Zombienet](https://github.com/paritytech/zombienet) to setup a local environment or connect to Rococo. **Important**: we need the same chainspec that is used to start the validators for the collator(s). In case of connecting to Rococo, we need the [Rococo chainspec](https://github.com/paritytech/polkadot/blob/master/node/service/chain-specs/rococo.json). ## Parachain ### Register Parachain If necessary, register the parachain to the Relay Chain with the `parachain-genesis-state` and the `parachain-wasm` files generated above. In addition, you need a `parachain manager account` and the `para-id`. Check out the ["Connect a local Parachain"](https://docs.substrate.io/tutorials/build-a-parachain/connect-a-local-parachain/) tutorial and look for the step *"Register with the local Relay Chain"* ### Launch Collator Before we launch a Collator for the Parachain, make sure that its database is purged from any previous attempts, as any leftover state can cause syncing issues. In other words, the genesis state of the collator won't match the genesis state that has been given to the Relay chain. ``` ./target/release/parachain-node-template purge-chain --base-path /tmp/parachain/<collator> --chain parachain-chainspec-raw.json ``` Launch the collator: ``` ./target/release/parachain-node-template --collator \ --name C1 \ --base-path /tmp/parachain/collator1 \ --chain parachain-chainspec-raw.json \ --force-authoring \ --rpc-port 10001 \ --ws-port 10002 \ --listen-addr /ip4/0.0.0.0/tcp/10003/ws \ -- \ --execution wasm \ --chain /{PATH_TO_RELAYCHAIN_CHAINSPEC} \ --port 10004 \ --ws-port 10005 ``` 1. Ensure the collator is peering with the relay chain (and the other collator(s) if present) by checking the collator output logs. * No peers with the Relay Chain: if you made changes to the relay chainspec, make sure `bootnodes` are provided. In addition, [NAT](https://github.com/paritytech/substrate/issues/2772) can also be a problem. * No peers with the Parachain: see **Important**. 2. No blocks being produced should be expected until the session key is added to the [keystore](##Keystore) - This is specific to a custom chain spec and would probably work if using the parachain-node-template default spec as it would probably just use alice/bob as collators. `./target/release/parachain-node-template --help`: ![](https://hackmd.io/_uploads/rJEeljysh.png) **Important**: - the `force-authoring` flag is only necessary when you have one collator (e.g. for testing). - the `listen-addr` flag is necessary if you want other nodes to be able to connect to you to join the network. An additional `bootnodes` flag is necessary for this other collator (when the chainspec doesn't provide `bootnodes`). In addition, you need the `[parachain] local identity` of the collator you want to connect to (you can find this in the logs when you start your node). An example of launching a second collator that you want to connect to the first collator shown above: ``` ./target/release/parachain-node-template --collator \ --name C2 \ --base-path /tmp/parachain/collator2 \ --chain parachain-chainspec-raw.json \ --force-authoring \ --rpc-port 10006 \ --ws-port 10007 \ --listen-addr /ip4/0.0.0.0/tcp/10008/ws \ --bootnodes /ip4/127.0.0.1/tcp/10003/ws/p2p/{INSERT_COLLATOR_1_PARACHAIN_NODE_IDENTITY} \ -- \ --execution wasm \ --chain /{PATH_TO_RELAYCHAIN_CHAINSPEC} \ --port 10009 \ --ws-port 10010 ``` **The `force-authoring` can still be provided for the case where you want it to build blocks if it is the only collator in the network.* Last, depending on the chain and the syncing method, the time it takes to be completely synchronized and build your first block can vary. The flag `--sync=warp` enables the node to make use of the [warp sync protocol](https://spec.polkadot.network/chap-sync#sect-sync-warp). This decreases the synchronization time significantly by only validating / applying full blocks at the end of the initial synchronization process. # Session Keys The session key needs to be set for a collator to start producing blocks. It is advised to use a different keypair than the collator keypair. This is to minimize exposure of the collator keypair. ## Generating keys There are multiple ways to generate keys, such as: - Polkadot JS extension or any other custodial - [PolkaVault](https://wiki.polkadot.network/docs/polkadot-vault) - [Subkey](https://docs.substrate.io/reference/command-line-tools/subkey/) ## Session-pallet Session keys are set in [session-pallet](https://github.com/paritytech/substrate/tree/master/frame/session). Session keys can be added to [genesis state](https://github.com/paritytech/substrate/blob/cb450b626ac8e8848db76933e114e57e7cce3e8d/frame/session/src/lib.rs#L417-L421), otherwise [set_keys](https://github.com/paritytech/substrate/blob/4d9d9116b5f65f4a7f3e70c1f4ab74d9fed60c0c/frame/session/src/lib.rs#L589) needs to be called by the collator. In order to change your session keys you'd have to call `set_keys` with the new public key. ## Keystore In order for a collator to be able to sign e.g. its produced block, the session keypair needs to be added to the `keystore`. The keystore is a file that provides a secure and encrypted storage solution for your private keys. It ensures that only authorized processes can access and use the private keys when needed. 1. Connect to your collator via Polkadot JS: https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A10002 (`ws-port` flag set to 10002) 2. Go to `Developer` and `RPC calls` and click **author**, **insertKey**. 3. Enter "aura" as the **keyType** 4. Enter the seed/mnemonic of the collator's session key as **suri**. 5. Enter he hex value of the public key of the collator's session key for **publicKey**. The Collator's session keys are added to the keystore and should now be building blocks. # Invulnerables & Candidates As for cumulus' out-of-the-box implementation, the set of collators that are allowed to build blocks are coming from the pallet [`collator-selection`](https://github.com/paritytech/cumulus/blob/7d51356009b652aca3fa1dbba73b7c729003cd6c/pallets/collator-selection/src/lib.rs#L16-L60), more specifically the `invulnerables` and `candidates`. If we want to add a new collator we either [add it to `invulnerables`](https://github.com/paritytech/cumulus/blob/7d51356009b652aca3fa1dbba73b7c729003cd6c/pallets/collator-selection/src/lib.rs#L490) through `root` or we can [register as a candidate](https://github.com/paritytech/cumulus/blob/7d51356009b652aca3fa1dbba73b7c729003cd6c/pallets/collator-selection/src/lib.rs#L424). **Important**: `invulnerables` will always be chosen to build blocks. As for `candidates`, there is a [`desired_amount`](https://github.com/paritytech/cumulus/blob/7d51356009b652aca3fa1dbba73b7c729003cd6c/pallets/collator-selection/src/lib.rs#L205) that caps the amount of candidates that can be registered. In other words, if a collator wants to register as candidate but the `desired_amount` is met, the collator has to wait until a collator [`leave_intent`](https://github.com/paritytech/cumulus/blob/b3c98894621b317e07af5bd32f2b5a5e12bfc327/pallets/collator-selection/src/lib.rs#L469) or the desired_amount [is increased](https://github.com/paritytech/cumulus/blob/b3c98894621b317e07af5bd32f2b5a5e12bfc327/pallets/collator-selection/src/lib.rs#L389). # Additional information - [How to make a substrate node publicly accessible?](https://substrate.stackexchange.com/questions/1787/how-to-make-substrate-node-publicly-accessible/1798#1798) - [What is an RPC node?](https://substrate.stackexchange.com/questions/2246/what-is-an-rpc-node/2250#2250) - [Secure validator / collator](https://wiki.polkadot.network/docs/maintain-guides-secure-validator) - [Is it ok to combine RPC node with collator together?](https://substrate.stackexchange.com/questions/925/is-it-ok-to-combine-rpc-node-with-collator-together) - [What's the easiest way to set up a relay chain locally with a couple of parachains?](https://substrate.stackexchange.com/questions/33/whats-the-easiest-way-to-set-up-a-relay-chain-locally-with-a-couple-of-parachai) - [What are the predefined accounts (ALICE, BOB, etc)?](https://substrate.stackexchange.com/questions/41/what-are-the-predefined-accounts-alice-bob-etc)

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully