Beginner
Separate Node on BNB Smart Chain
Welcome to our tutorial on setting up a Separate Node on the Binance Smart Chain (BSC). With the increasing popularity of decentralized applications, it’s important to have a secure and efficient infrastructure to support these platforms. One of the key components of this infrastructure is a node. A separate node is a full copy of the blockchain that runs independently and is not connected to any other nodes in the network. This tutorial will guide you through the process of setting up and configuring a separate node on the Binance Smart Chain. Whether you are a developer looking to build decentralized applications or an investor looking to enhance the security of your investments, this tutorial will provide you with the knowledge and skills necessary to run a separate node on the Binance Smart Chain.
Introduction
Currently, a BSC node has two kinds of state world: MPT and snapshot. MPT(Merkle Patricia Tries) is a tree-structured state world. The key function of MPT is to generate the state root to ensure state consistency, while the query/commit on MPT is quite slow. Snapshot is a flattened key-value-based state world. Snapshot provides fast queries and commits. The storage size of the snapshot increases slowly even with a large transaction volume. Snapshot is usually used for block processing, while MPT is used for state verification.
In order to lower the hardware requirement and keep security, we introduce two types of nodes to make full use of different storage, one is named fast node, and the other is named verify node. The fast node will do block processing with snapshot, it will do all verification against blocks except state root. The verify node receives diffhash from the fast node and then responds MPT root to the fast node.
The fast node doesn’t need to store MPT, so the storage and computation requirement will be much lower.
Roles
-
Fast Node: It does full sync using only Snapshot and generates difflayer. It needs the confirm message from the verify node before freezing the blocks, it has to wait until it receives a confirm message from the verify node for the ancestor block before inserting new blocks.
-
Verify Node: It is a normal BSC full node that does full sync using Snapshot and MPT, and generates difflayer. It receives diffhash from fast nodes, finds the corresponding difflayer whose diffhash is matched, then responds MPT root message to the fast node.
Related Commands
Fast Node
Introduce a new tries-verify-mode setting, there are four modes:
-
local: a normal full node with complete state world(both MPT and snapshot), merkle state root will be verified against the block header.
-
full: a fast node with only a snapshot state world. Merkle state root is verified by the trustworthy remote verify node by comparing the diffhash(an identity of difflayer generated by the block) and state root.
-
insecure: same as full mode, except that it can tolerate without verifying the diffhash when verify node does not have it.
-
none: no merkle state root verification at all, there is no need to set up or connect a remote verify node at all, it is light compared to full and insecure node, but get very little chance that the state is not consistent with other peers.
If the fast node runs in not local mode, the node will disable diff protocol by default, If the fast node runs in full or light mode, the node will enable trust protocol by default.
./geth --config ./config.toml --datadir ./node --syncmode full --cache 5000 --tries-verify-mode none
*Note: fast node can never revert to a full node.
Verify node
When a full node has enabled the trust protocol, it can serve as a verify node, at the same time, we will recommend you enable persist diff, and disable snap protocol, and diff protocol when running a verify node.
./geth --config ./config.toml --datadir ./node --syncmode full --cache 5000 --persistdiff --enabletrustprotocol --disablesnapprotocol --disablediffprotocol
Prune tries node
Prune the tires node:
Run Verify Node
Verify Node on BNB Smart Chain
Verify Node Functions
-
Stores the full blockchain history on disk and can answer the data request from the network.
-
Receives and validates the new blocks and transactions.
-
Verifies the states of every account.
-
Verifies the states of a Fast Node.
Steps to Run a Verify Node
Download the pre-build binaries from release page or follow the instructions below:
# Linux wget $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep geth_linux |cut -d\" -f4) mv geth_linux geth chmod -v u+x geth # MacOS wget $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep geth_mac |cut -d\" -f4) mv geth_mac geth chmod -v u+x geth
Download the config files
Download genesis.json and config.toml by:
wget $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep mainnet |cut -d\" -f4) unzip mainnet.zip
Download snapshot
Download the latest chaindata snapshot from here. Follow the guide to structure your files.
NOTE
Your –datadir flag should point to the extracted chaindata folder path
Start verify node
./geth --config ./config.toml --datadir ./node --cache 8000 --rpc.allow-unprotected-txs --txlookuplimit 0 --enabletrustprotocol --disablesnapprotocol --disablediffprotocol
NOTE
Make sure you use the version of geth you downloaded with wget above, and not your local installation of geth, which might be the wrong version.
Run Fast Node
Fast Node on BNB Smart Chain
Note
Fast Node does not generate Trie Data when syncing.
Once the Fast Node is running, there is no way to switch back to Full Node.
Need to re-download snapshot data to restore it to Full Node.
Fast Node Functions
-
Stores the full blockchain history on disk and can answer the data request from the network.
-
Receives and validates the new blocks and transactions.
-
Verifies the states of every account.
Steps to Run a Fast Node
Download the pre-build binaries from release page or follow the instructions below:
# Linux wget $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep geth_linux |cut -d\" -f4) mv geth_linux geth chmod -v u+x geth # MacOS wget $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep geth_mac |cut -d\" -f4) mv geth_mac geth chmod -v u+x geth
Download the config files
Download genesis.json and config.toml by:
wget $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep mainnet |cut -d\" -f4) unzip mainnet.zip
Download snapshot
Download the latest chaindata snapshot from here. Follow the guide to structure your files.
NOTE
Your –datadir flag should point to the extracted chaindata folder path
Prune all trie data
Fast node does not need trie data anymore, prune the trie data by the following command.
./geth snapshot insecure-prune-all --datadir ./node ./genesis.json
Start Fast Node Without Snapshot Verification
You can start Fast Node without snapshot verification by verify nodes.
## start a fast node ./geth --tries-verify-mode none --config ./config.toml --datadir ./node --cache 8000 --rpc.allow-unprotected-txs --txlookuplimit 0
Or start Fast Node With Snapshot Verification
Add verifyNodes peers in config.toml.
[Node.P2P] MaxPeers = 1350 NoDiscovery = false BootstrapNodes = ["enode://...", "enode://...", ...] VerifyNodes = ["enode://...", "enode://...", ...] StaticNodes = ["enode://...", "enode://...", ...] ListenAddr = ":30311" EnableMsgEvents = false
Start your fast node with snapshot verification by verify nodes.
## start a fast node ./geth --tries-verify-mode full --config ./config.toml --datadir ./node --cache 8000 --rpc.allow-unprotected-txs --txlookuplimit 0