Advanced
How to set up and run a full node on Polkadot?
Overview of Polkadot’s Architecture
Polkadot has a multichain architecture with true interoperability and shared security. Polkadot uses combined consensus, proof of work and proof of stake consensus to make the entire Polkadot network more efficient and scalable. The Polkadot ecosystem comprises Parachain, Parathreads, Relaychain and bridges. Let’s decode the Polkadot architecture in brief:
Components
-
Relay chain
The relay chain is like the foundation of the Polkadot Network as it is responsible for uniting the various parachains built on the Polkadot ecosystem, enabling interoperability and robust security. -
Parachain and Parathread Slots
Parachains and Parathreads are the customized blockchains built and managed on their core slots on the Polkadot ecosystem. Besides managing the chains, these slots are responsible for facilitating easy upgradability and unparalleled security to the chains. -
Shared Security
Polkadot architecture is designed with the Relay chain as the foundation and various Parachains as connecting or parent chains. Here, the Relay chain provides security to the entire Parachains and unites them in terms of communication.
Interoperability
-
Bridges
Any blockchain built using a Substrate framework or built as Parachain/Parathread is inherently interoperable with each other. For non- Substrate and non-Parachains, Polkadot offers cross-chain bridges that enable true interoperability between two independent and inherently different blockchains. -
XCM
XCM and XCMP refer to the cross-chain messaging protocol and cross-chain message, respectively. XCMP mechanism and XCM (the message that gets delivered) together power the Polkadot ecosystem with interoperability element, enabling a seamless cross-chain communication through messaging.
Main actors
-
Validators
Validators are responsible for producing blocks on the Relay chain. Also, validators are entitled to receive staking rewards against their acceptance of proof of valid state. -
Nominators
Nominators are responsible for bonding their stake for specific validators, allowing them to show up as active visitors and thus contribute to producing new blocks. -
Collators
Collators represent the full node on the Relay chain and the Parachain. Their main responsibility includes collecting transactions on Parachains and producing transition proof for Relay chain’s validators.
What are the different types of Polkadot nodes?
The Polkadot ecosystem has three main types of nodes; an archive node, a full node and a light node. Let’s understand the mechanism of these nodes:
Archive node
An archive is responsible for keeping a record of entire past blocks, making it convenient to query any blocks of the chain whenever required. Using active nodes, users can easily query the past blocks whenever required. Furthermore, these nodes help find out what’s the account balance of a certain block to ensure fast operations. That being said, an archive node can consume high disk space, up to Kusama’s 12 millionth block’s space, which is around 660GB.
Full node
Full node on the Polkadot discards existing finalized blocks that are older than a configurable number except the genesis block. By default, a full node is the 256 blocks from the last completed blocks. How a full node is pruned is very convenient to save space compared to an archive node.
Light node
The light node is another Polkadot node that keeps a record of only runtime and the current state. It only does runtime and current state without storing the details about past blocks. Consequently, the light node cannot track or read historical data instead of requesting the data from the node.
How to set up and run a full node on Polkadot?
This guide aims to provide a Polkadot node setup and running for Windows, Linux and Ubuntu. Follow a step-by-step guide to set up and run a full node on Polkadot.
Node installation and running guide For Windows:
-
Install WSL
-
Next, Install Ubuntu
-
Make sure you have the latest version of the Polkadot binary.
Run the following command to download the accurate Polkadot binary within Ubuntu. Now, replace the *VERSION* with the latest version. Use the following code:
curl -sL https: //github.com/paritytech/polkadot/releases/download/*VERSION*/polkadot -o polkadot
-
Now, run the following command:sudo chmod +x polkadot
-
Get started with running your code:./target/release/Polkadot –name “Your Node’s Name”
Get Substrate
Follow the quick Substrate installation guide to install this framework. Prefer using a virtual machine to deal with the challenges associated with Substrate installation in Windows. Now, test the installation by running the following code:
λ cargo –version
cargo 1.41.0 (626f0f40e 2019-12-03)
Clone and Build
The following Polkadot code is available in the paritytech/Polkadot repo’s master branch: – http://github.com/paritytech/
git clone https:// http://github.com/paritytech/ polkadot polkadot
cd Polkadot
./scripts/init.sh
cargo build –release
Either way, you can use a specific release to check out a specific tag as below mentioned:
git clone https: //GitHub .com/paritytech/Polkadot Polkadot
cd Polkadot
git checkout tags/v0.8.3
./scripts/init.sh
cargo build –release
Run
The built binary resides in the target/release folder, Polkadot.
Polkadot:
./target/release/Polkadot –name “Your Node’s Name”
Furthermore, you can determine which flags you can use while running the node. For instance, you may need to use
–ws-external and –RPC-cors all
to remotely connect to nodes.
Running an Archive Node
When you run a simple sync node, only the past 256 blocks are kept. When validating, it defaults to archive mode. To keep the full state, use the –pruning flag:
Polkadot:
./target/release/Polkadot –name “My node’s name” –pruning archive
You can quadruple the synchronization speed using the additional flag: –wasm-execution Compiled. Remember that this approach requires higher computing resources through CPU and RAM.
Node installation and running guide For macOS:
-
Run the following command in the terminal to install Homebrew/bin/bash -c “$(curl -fsSL https:// raw.githubusercontent.com/Homebrew/install/master/install.sh)”
-
Next, run the following commandbrew install OpenSSL cmake llvm
-
Install Rust using the below command in the terminal:curl –proto ‘=https’ –tlsv1.2 -sSf https:// sh.rustup.rs | sh
-
Right after RUST installation, run the following command:
git clone GitHub – paritytech/Polkadot: Polkadot Node Implementation Polkadot
cd Polkadot
./scripts/init.sh
cargo build –release
- Now, start your node:
./target/release/Polkadot –name “Your Node’s Name”
Get Substrate
Follow the instructions on the Substrate Quick Starter guide to install Substrate. Note that Windows users might have to undergo challenges. Therefore, prefer using the virtual machine.
Once installed, test your Substrate installation by running the following command cargo –version:
λ cargo –version
cargo 1.41.0 (626f0f40e 2019-12-03)
Clone and Build
Run the following code from paritytech/Polkadot repo’s master branch as it contains Polkadot code:
git clone GitHub – paritytech/Polkadot: Polkadot Node Implementation Polkadot
cd Polkadot
./scripts/init.sh
cargo build –release
Either way, you can use a specific release by checking out the specific tag v0.8.3 as given in the following example:
git clone GitHub – paritytech/Polkadot: Polkadot Node Implementation Polkadot
cd Polkadot
git checkout tags/v0.8.3
./scripts/init.sh
cargo build –release
Run an Archive Node
Running a simple sync node can only keep records of the past 256 blocks. During the validation process, the same simple node is by default. Use the full state to keep the –pruning flag:
Run the following command:
1./target/release/Polkadot --name "My node's name" --pruning archive
Also, you can accelerate the synchronization speed by running this code: –wasm-execution Compiled. This approach uses high CPU and RAM computing resources, turning it off once the node is synched.
Using Docker
Finishing up, you need to use Docker to run your code. Since this process is a bit advanced, you need to be familiar with Docker and node setup experience using Docker. Also, when you run a Polkadot node, the process only listens to the local host by default.
Instructions For Linux
*Ensure you have the last version of the Polkadot binary.
-
Run the following command to downloadsudo chmod +x polkadot
Run the below command:./target/release/Polkadot –name “Your Node’s Name”
Get Substrate
Instead of Windows, use the virtual machine to get the best experience with Substrate. Follow the step-by-step instructions added in Substrate’s docs regarding the installation.
Once the installation is completed, test your installation by running the following command line:
git clone https://github.com/paritytech/polkadot Polkadot
cd Polkadot
./scripts/init.sh
cargo build –release
Clone and Build
Execute the following Polkadot code that is available in the paritytech/Polkadot repo’s master branch:
git clone GitHub – paritytech/Polkadot: Polkadot Node Implementation Polkadot
cd Polkadot
./scripts/init.sh
cargo build –release
Either way, you can use a specific release, then check the specific tag v0.8.3 given in the example below; run the following command:
git clone https:// http://github.com/paritytech/polkadot Polkadot
cd Polkadot
git checkout tags/v0.8.3
./scripts/init.sh
cargo build –release
Run
The built binary reflects in the target/release folder, Polkadot.
Run the following code on the Polkadot command prompt:
1./target/release/Polkadot --name "Your Node's Name"
Now, you can use -the-help flag to determine which flags you should use for running the node. For instance, if you want to connect to your node remotely, you need to use
1-rpc-cors all and-was-external.
Note that synching process takes time depending on the bandwidth capacity of your system, disk speed, disk space and RAM.
Running an Archive Node
When you run a simple sync node, only the records of past blocks are kept. During validation, the node defaults to the archive node. Also, you can keep the full state of blogs using –the pruning flag:
Run the following command on the Polkadot:
1./target/release/Polkadot --name "My node's name" --pruning archive
It is possible to almost quadruple synchronization speed by using an additional flag: –wasm-execution Compiled. Note that this uses much more CPU and RAM, so turn it off after the node is in sync.
Using Docker
Finishing up, you need to use Docker to run your code. Since this process is a bit advanced, you need to be familiar with Docker and node setup experience using Docker. Also, when you run a Polkadot node, the process only listens to the local host by default.