Besu Network Set
1. Overview
Hyperledger Besu is an open-source Ethereum client that supports both public and private networks. It provides different consensus algorithms, including QBFT for permissioned networks. In this guide, we'll use QBFT to set up a private blockchain network with 4 validator nodes and 1 RPC node.
What You'll Set Up:
Validator Nodes: Validate transactions and blocks in the network.
RPC Node: Allows external applications to interact with the blockchain via JSON-RPC or WebSocket.
Prometheus & Grafana (Optional): Monitoring tools for visualizing metrics from the Besu nodes.
2. Prerequisites
Before proceeding, ensure the following tools are installed:
For Docker Setup:
Docker: Install Docker
Docker Compose: Install Docker Compose
3. Architecture
We will set up the following:
4 Validator Nodes: Each node will validate blocks and transactions using the QBFT consensus algorithm.
1 RPC Node: Provides a JSON-RPC and WebSocket interface for interacting with the blockchain.
Ports Used:
Validator Nodes: P2P ports (30303, 30304, 30305, 30306) and RPC ports (8545, 8547, 8548, 8549)
RPC Node: P2P port (30307), RPC port (8550), WebSocket port (8551)
4. Step-by-Step Setup
Step 1: Install Docker and Docker Compose
If you haven't already, install Docker and Docker Compose.
Docker Installation on Linux:
sudo apt-get update
sudo apt-get install docker.io
sudo systemctl start docker
sudo systemctl enable docker
Docker Compose Installation:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
Verify the installation by running:
docker --version
docker-compose --version
Step 2: Create a Directory Structure
Create a directory for your Besu network setup:
mkdir besu-network
cd besu-network
Inside this directory, create subdirectories for each validator and the RPC node:
mkdir -p data/validator1 data/validator2 data/validator3 data/validator4 data/rpcnode
Step 3: Generate Node Private Keys
To generate private keys for each validator node, you can use the besu CLI or generate them manually. The private keys will be required for each validator to participate in the consensus.
Run the following command for each validator node:
besu operator generate-blockchain-config --config-file=configFile --to=networkFiles --private-key-file-name=key
Place each validator's private key in its respective directory (e.g., data/validator1/key).
Step 4: Create the Genesis File
The genesis.json file defines the initial state and configuration of your blockchain. Create a file named genesis.json inside your besu-network directory:
{
"config": {
"chainId": 1337,
"isQuorum": true,
"qbft": {
"blockperiodseconds": 5,
"epochlength": 30000,
"requesttimeoutseconds": 10
}
},
"nonce": "0x0",
"timestamp": "0x58ee40ba",
"gasLimit": "0x47b760",
"difficulty": "0x1",
"alloc": {},
"extraData": "0x",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"mixHash": "0x00000000000000000000000000000000000000647572616c65787365646c6578",
"coinbase": "0x0000000000000000000000000000000000000000",
"gasUsed": "0x0",
"number": "0x0"
}
The extraData field will include your validator addresses. You can generate this once the private keys are ready.
Step 5: Create the Docker Compose File
Now create a docker-compose.yml file to define your services (4 validators and 1 RPC node).
version: "3.7"
services:
validator1:
image: hyperledger/besu:latest
container_name: validator1
volumes:
- ./data/validator1:/opt/besu/data
- ./genesis.json:/opt/besu/genesis.json
command: >
--genesis-file=/opt/besu/genesis.json
--data-path=/opt/besu/data
--node-private-key-file=/opt/besu/data/key
--p2p-port=30303
--rpc-http-enabled
--rpc-http-port=8545
--rpc-http-api=ETH,NET,WEB3,CLIQUE,ADMIN
--host-whitelist=*
--sync-mode=FULL
--miner-enabled
--min-gas-price=0
--miner-coinbase=0x0000000000000000000000000000000000000000
ports:
- "30303:30303"
- "8545:8545"
validator2:
image: hyperledger/besu:latest
container_name: validator2
volumes:
- ./data/validator2:/opt/besu/data
- ./genesis.json:/opt/besu/genesis.json
command: >
--genesis-file=/opt/besu/genesis.json
--data-path=/opt/besu/data
--node-private-key-file=/opt/besu/data/key
--p2p-port=30304
--rpc-http-enabled
--rpc-http-port=8547
--rpc-http-api=ETH,NET,WEB3,CLIQUE,ADMIN
--host-whitelist=*
--sync-mode=FULL
--miner-enabled
--min-gas-price=0
--miner-coinbase=0x0000000000000000000000000000000000000000
ports:
- "30304:30304"
- "8547:8547"
validator3:
image: hyperledger/besu:latest
container_name: validator3
volumes:
- ./data/validator3:/opt/besu/data
- ./genesis.json:/opt/besu/genesis.json
command: >
--genesis-file=/opt/besu/genesis.json
--data-path=/opt/besu/data
--node-private-key-file=/opt/besu/data/key
--p2p-port=30305
--rpc-http-enabled
--rpc-http-port=8548
--rpc-http-api=ETH,NET,WEB3,CLIQUE,ADMIN
--host-whitelist=*
--sync-mode=FULL
--miner-enabled
--min-gas-price=0
--miner-coinbase=0x0000000000000000000000000000000000000000
ports:
- "30305:30305"
- "8548:8548"
validator4:
image: hyperledger/besu:latest
container_name: validator4
volumes:
- ./data/validator4:/opt/besu/data
- ./genesis.json:/opt/besu/genesis.json
command: >
--genesis-file=/opt/besu/genesis.json
--data-path=/opt/besu/data
--node-private-key-file=/opt/besu/data/key
--p2p-port=30306
--rpc-http-enabled
--rpc-http-port=8549
--rpc-http-api=ETH,NET,WEB3,CLIQUE,ADMIN
--host-whitelist=*
--sync-mode=FULL
--miner-enabled
--min-gas-price=0
--miner-coinbase=0x0000000000000000000000000000000000000000
ports:
- "30306:30306"
- "8549:8549"
rpcnode:
image: hyperledger/besu:latest
container_name: rpcnode
volumes:
- ./data/rpcnode:/opt/besu/data
- ./genesis.json:/opt/besu/genesis.json
command: >
--genesis-file=/opt/besu/genesis.json
--data-path=/opt/besu/data
--p2p-port=30307
--rpc-http-enabled
--rpc-http-port=8550
--rpc-http-api=ETH,NET,WEB3,ADMIN,DEBUG,TXPOOL
--rpc-ws-enabled
--rpc-ws-port=8551
--rpc-ws-api=ETH,NET,WEB3,ADMIN,DEBUG,TXPOOL
--host-whitelist=*
--sync-mode=FAST
ports:
- "30307:30307"
- "8550:8550"
- "8551:8551"
Step 6: Launch the Network
With your docker-compose.yml, genesis file, and private keys in place, launch the Besu network:
docker-compose up -d
This will spin up 4 validator nodes and 1 RPC node.
Step 7: Verify and Interact with the Network
List Running Containers:
docker ps
Check Node Logs:
View logs for a specific validator to ensure it's working correctly:
docker logs validator1
Interact with the Network:
Using curl, you can interact with the blockchain via the RPC node:
Get the current block number:
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
http://localhost:8550
Connect using web3.js or ethers.js to perform more advanced actions such as sending transactions and deploying smart contracts.
5. Monitoring (Optional): Prometheus and Grafana
Prometheus and Grafana can be used to monitor your Besu nodes in real time. First, create a prometheus.yml configuration file:
scrape_configs:
- job_name: 'besu'
static_configs:
- targets: ['validator1:9545', 'validator2:9546', 'rpcnode:9547']
Add the services to your Docker Compose file:
prometheus:
image: prom/prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
grafana:
image: grafana/grafana
ports:
- "3000:3000"
Start the services:
docker-compose up -d
You can access Grafana on http://localhost:3000 and Prometheus on http://localhost:9090.
6. Troubleshooting
Nodes Not Syncing:
Ensure all nodes use the same genesis.json.
Verify that all nodes can reach each other through their P2P ports.
No Peer Connections:
Check firewall settings to ensure P2P ports are open.
Use docker network ls to verify that all containers are on the same network.
Node Crashes:
View the logs using docker logs <container-name> to diagnose the issue.
Check if private keys are correctly placed.
7. Conclusion
By following this guide, you now have a fully functional Hyperledger Besu private blockchain network with 4 validator nodes and 1 RPC node. You can now expand this network, add new nodes, or deploy smart contracts. Monitoring tools such as Prometheus and Grafana can also be added for better visibility into node performance.
Last updated
Was this helpful?