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:

  • Docker Compose Installation:

Verify the installation by running:

Step 2: Create a Directory Structure

  1. Create a directory for your Besu network setup:

  1. Inside this directory, create subdirectories for each validator and the RPC node:

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:

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:

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).

Step 6: Launch the Network

With your docker-compose.yml, genesis file, and private keys in place, launch the Besu network:

This will spin up 4 validator nodes and 1 RPC node.

Step 7: Verify and Interact with the Network

  1. List Running Containers:

  1. Check Node Logs:

View logs for a specific validator to ensure it's working correctly:

  1. Interact with the Network:

Using curl, you can interact with the blockchain via the RPC node:

  1. Get the current block number:

  1. 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:

Add the services to your Docker Compose file:

Start the services:

You can access Grafana on http://localhost:3000 and Prometheus on http://localhost:9090.

6. Troubleshooting

  1. Nodes Not Syncing:

    1. Ensure all nodes use the same genesis.json.

    2. Verify that all nodes can reach each other through their P2P ports.

  2. No Peer Connections:

    1. Check firewall settings to ensure P2P ports are open.

    2. Use docker network ls to verify that all containers are on the same network.

  3. Node Crashes:

    1. View the logs using docker logs <container-name> to diagnose the issue.

    2. 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?