Vaibhavraj · Follow
10 min read · Sep 24, 2023
Blockchain technology has revolutionised the way we handle digital assets and information. It provides a secure and decentralised way of recording transactions, which is tamper-resistant and transparent. Ethereum is one of the most popular blockchain platforms, known for its smart contract capabilities. In this blog, we’ll explore what blockchain, Ethereum, Beacon Node, and running a private Ethereum node, and we’ll delve into a practical example using the provided Docker Compose code.
A blockchain is a distributed ledger technology that stores data in a chain of blocks, each containing a list of transactions. It operates on a decentralized network of computers, ensuring transparency, security, and immutability of data. The blockchain’s consensus mechanism, often Proof of Work (PoW) or Proof of Stake (PoS), helps validate and add new blocks to the chain.
Imagine a digital currency called “DigitalCoin” (DC). When you send DC to someone, that transaction is recorded on the DigitalCoin blockchain.
- You decide to send 10 DC to your friend Alice.
- This transaction is broadcast to the network for verification.
- Nodes in the network check if you have enough DC to send and if the transaction is valid.
- Once enough nodes agree that your transaction is valid, it’s added to a new block.
- This block is then added to the existing blockchain.
- Your friend Alice can now see the transaction on her digital wallet, and she knows she received 10 DC from you.
This process repeats for every transaction on the blockchain. Over time, you get a chain of blocks (the blockchain) that contains all the transactions ever made with DigitalCoin.
Ethereum is a blockchain platform designed for more than just digital currency. It introduced the concept of smart contracts, self-executing contracts with predefined rules. These contracts automate complex tasks, such as transferring assets, without the need for intermediaries. Ethereum’s native cryptocurrency, Ether (ETH), is used to fuel these transactions and execute smart contracts.
Ethereum 2.0 (Eth2) is an upgrade to the existing Ethereum network, aiming to improve scalability, security, and energy efficiency. Beacon Chain is a critical component of Eth2, responsible for managing validators, validating transactions, and maintaining consensus.
Here’s a breakdown of the components:
- Beacon Chain: The core chain in Ethereum 2.0 that coordinates and manages validators. It’s responsible for proposing new blocks and maintaining the overall network consensus.
- Validators: Participants responsible for validating transactions and adding them to the blockchain. Validators are chosen in a decentralized manner, promoting security and decentralization.
- Shard Chains: Eth2 introduces shard chains, each capable of processing its transactions and smart contracts. Beacon Chain coordinates these shards.
There are multiple tools available for setting up a private Ethereum node, but in this documentation, we will focus on using Geth and Prysm to set up the node.
In the provided Docker Compose code, you have two services: `geth` and `beacon-node`, which facilitate running your own Ethereum private node.
- Create a folder named “ethereum” and navigate into it.
mkdir ethereum && cd ethereum
2. Generate a secret key for authentication using openssl
in the terminal.
sudo openssl rand -hex 32 > jwtsecret
3. Create a “jwt” folder within the “ethereum” folder, copy the secret key into it.
We generate a JWT secret to establish a communication bridge between the execution client and the beacon client.
mkdir jwt && mv jwtsecret ./jwt/
4. Return to the “ethereum” folder and create a “docker-compose.yml” file with provided code.
Feel free to adjust any additional details or configurations as per your requirements.
touch docker-compose.yml
version: "3.8"services:
geth:
image: ethereum/client-go:latest
volumes:
- ./eth:/root/.ethereum
- ./jwt/jwtsecret:/jwt/jwtsecret
ports:
- 8545:8545
- 30303:30303
- 8551:8551
restart: unless-stopped
command:
[
"--mainnet",
"--syncmode","snap",
"--datadir=/root/.ethereum",
"--http",
"--http.addr", "0.0.0.0",
"--http.port", "8545",
"--authrpc.addr", "0.0.0.0",
"--authrpc.vhosts=0.0.0.0",
"--authrpc.port", "8551",
"--http.api", "ersonal,eth,net,web3,debug,txpool,admin",
"--authrpc.jwtsecret=/jwt/jwtsecret",
"--cache", "1024",
"--http.corsdomain", "*",
"--maxpeers=500",
"--metrics"
]
beacon-node:
image: gcr.io/prysmaticlabs/prysm/beacon-chain:stable
volumes:
- ./eth2:/data
- ./jwt/jwtsecret:/jwt/jwtsecret
ports:
- 4000:4000
- 13000:13000
- 12000:12000/udp
restart: unless-stopped
command:
[
"--datadir=/data",
"--jwt-secret=/jwt/jwtsecret",
"--execution-endpoint=http://<your-private-ip>:8551", # Enter your private ip for your system
"--mainnet",
"--accept-terms-of-use",
"--rpc-host=0.0.0.0",
"--grpc-gateway-host=0.0.0.0",
"--monitoring-host=0.0.0.0"
]
Run the
ifconfig
command to fetch your private IP and then input the IP into the Beacon Node service command.
5. Run docker-compose up -d
to start two containers for execution and beacon [ Consensus ] nodes.
docker-compose up -d
Two folders, “eth” and “eth2,” will be created.
6. After setup, your private nodes will begin execution and start fetching node data.
7. In the initial stage, it will require some time to start
Note: The process may take around 3 days and occupy approximately 660GB of storage.
- Obtain the container ID of the Geth service by running.
docker ps
2. Use the following command to attach to the Geth terminal:
docker exec -it <container-id> geth attach
This will connect you to the Geth terminal.
3. Within the Geth terminal, enter the command
eth.syncing
Initially, it will display “false,” indicating that synchronization hasn’t started yet.
However, as the process progresses, you will observe real-time syncing data being displayed.
- Execution node
Volumes: Here, you define two volumes that Docker will use to store data. Volumes are like directories that can persist data even if the container is stopped or removed.
volumes:
- ./eth:/root/.ethereum
- ./jwt/jwtsecret:/jwt/jwtsecret
1. “- ./eth:/root/.ethereum:” This maps the local directory “./eth” to “/root/.ethereum” inside the Docker container. It’s where Geth will store Ethereum blockchain data.
2. “- ./jwt/jwtsecret:/jwt/jwtsecret:” This maps the local directory “./jwt/jwtsecret” to “/jwt/jwtsecret” inside the Docker container. It’s used to store authentication secrets.
Ports: This section defines which ports from your host machine should. be mapped to ports inside the Docker container.
ports:
- 8545:8545
- 30303:30303
- 8551:8551
8545:8545: Maps port 8545 on your host to port 8545 inside the container. Port 8545 is typically used for HTTP server and GraphQL API for interacting with Ethereum.
30303:30303: Maps port 30303 on your host to port 30303 inside the container. Port 30303 is used for P2P networking to connect to other Ethereum nodes.
8551:8551: Maps port 8551 on your host to port 8551 inside the container. This port is used to connect to a consensus client (CC).
Command: This section specifies the command and its arguments that should be run inside the Docker container.
command:
[
" - mainnet",
" - syncmode","snap",
" - datadir=/root/.ethereum",
" - http",
" - http.addr", "0.0.0.0",
" - http.port", "8545",
" - authrpc.addr", "0.0.0.0",
" - authrpc.vhosts=0.0.0.0",
" - authrpc.port", "8551",
" - http.api", "ersonal,eth,net,web3,debug,txpool,admin",
" - authrpc.jwtsecret=/jwt/jwtsecret",
" - cache", "1024",
" - http.corsdomain", "*",
" - maxpeers=500",
" - metrics"
]
1. — mainnet: Indicates that this Ethereum node should connect to the Ethereum mainnet, the public Ethereum blockchain.
2. — syncmode snap: Sets the synchronization mode to “snap,” which is a fast way to synchronize the Ethereum blockchain.
3. — datadir=/root/.ethereum: Specifies the data directory where Ethereum blockchain data should be stored inside the container.
4. — http: Enables the HTTP server to allow API access.
5. — http.addr 0.0.0.0: Makes the HTTP server accessible from any IP address.
6. — http.port 8545: Sets the HTTP server’s port to 8545 for API access.
7. — authrpc.addr 0.0.0.0: Allows remote authentication for RPC.
8. — authrpc.vhosts=0.0.0.0: Accepts requests from any virtual host for authentication.
9. — authrpc.port 8551: Sets the port for remote authentication.
10. — http.api personal,eth,net,web3,debug,txpool,admin: Specifies the Ethereum APIs to enable for remote access.
11. — authrpc.jwtsecret=/jwt/jwtsecret: Sets the location of the JWT secret for authentication.
12. — cache 1024: Allocates 1024 MB of memory for caching.
— http.corsdomain *: Allows cross-origin resource sharing from any domain.
13. — maxpeers=500: Sets the maximum number of peers (other Ethereum nodes) to connect to.
14. — metrics: Enables the collection of node metrics.
This Docker configuration sets up an Ethereum node (Geth) with various settings and configurations to allow interaction with the Ethereum mainnet and other Ethereum-related tasks. It uses Docker volumes to store blockchain data and authentication secrets and exposes specific ports for different Ethereum services. The Ethereum node is configured to restart automatically if it stops for any reason.
- Beacon Node [prysm]
Volumes: This section maps local directories to directories inside the Docker container. It allows data to be persisted and shared between the host system and the container.
volumes:
- ./eth2:/data
- ./jwt/jwtsecret:/jwt/jwtsecret
1. “./eth2:/data:” This maps the local directory “./eth2” to “/data” inside the Docker container.
2. “./jwt/jwtsecret:/jwt/jwtsecret:” This maps the local directory “./jwt/jwtsecret” to “/jwt/jwtsecret” inside the Docker container. It’s used to store authentication secrets.
Port : Required ports as mentioned in prysm documentation
ports:
- 4000:4000
- 13000:13000
- 12000:12000/udp
Command:This section specifies the command and its arguments that should be run inside the Docker container.
command:
[
" - datadir=/data",
" - jwt-secret=/jwt/jwtsecret",
" - execution-endpoint=http://10.26.2.71:8551",
" - mainnet",
" - accept-terms-of-use",
" - rpc-host=0.0.0.0",
" - grpc-gateway-host=0.0.0.0",
" - monitoring-host=0.0.0.0"
]
1. — datadir=/data: This parameter specifies the data directory where the Beacon Chain node will store its data. In this case, it’s set to `/data`.
2. — jwt-secret=/jwt/jwtsecret: This parameter specifies the location of the JWT secret file. JWT (JSON Web Token) is used for authentication and security purposes. Here, it’s configured to use the secret located at `/jwt/jwtsecret`.
3. — execution-endpoint=http://<System-Private-IP>:8551: This parameter defines the execution endpoint that the Beacon Chain node should connect to. It’s specified as `http://<System-private-IP>:8551`. This is likely the endpoint for communication with another service (possibly Geth) running at that IP and port.
4. — mainnet:This parameter indicates that the Beacon Chain node should operate on the Ethereum mainnet. It specifies the network mode.
5. — accept-terms-of-use: This parameter likely signifies that the user accepts the terms of use or licensing agreement associated with using the Prysm Beacon Chain node.
6. — rpc-host=0.0.0.0: This parameter configures the RPC (Remote Procedure Call) host address. Setting it to `0.0.0.0` means that the RPC interface is accessible from any network interface on the host.
7. — grpc-gateway-host=0.0.0.0: Similar to the previous parameter, this one configures the gRPC (Google Remote Procedure Call) gateway host address. It also allows access from any network interface on the host.
8. — monitoring-host=0.0.0.0: This parameter specifies the host address for monitoring. Like the previous two parameters, it’s set to `0.0.0.0`, allowing monitoring from any network interface on the host.
In summary, these command-line parameters configure various aspects of the Prysm Beacon Chain node, such as data directory, authentication, network settings, and endpoint connections. Each parameter serves a specific purpose in tailoring the behavior of the node to your requirements.
Execution Client in Ethereum 2.0:
In Ethereum 2.0 (Eth2), the blockchain network is designed to be more scalable and efficient than its predecessor, Ethereum 1.0. To achieve this, Eth2 introduces a separation of responsibilities between two crucial components: the execution client and the consensus client. Let’s first delve into the role of the execution client.
The execution client in Eth2 is primarily responsible for processing transactions, executing smart contracts, and managing the state of the shard chains. It’s the component that handles the “execution” aspect of the blockchain. One of the prominent execution clients in Ethereum 2.0 is Geth, which specializes in managing shard chains and executing transactions and smart contracts.
Consensus Client in Ethereum 2.0:
In contrast to the execution client, the consensus client in Ethereum 2.0 is focused on reaching consensus on the state of the blockchain. It validates and agrees upon the order of transactions and blocks in the network, ensuring that all nodes in the network have the same view of the blockchain’s history. The consensus client plays a vital role in maintaining network security and integrity.
A well-known consensus client in Ethereum 2.0 is prysm. Prysm is responsible for managing validators, participating in the consensus mechanism (Proof of Stake in Eth2), and maintaining the Beacon Chain. The Beacon Chain is the core chain that coordinates the network, finalizes blocks, and ensures agreement among validators.
To illustrate the collaborative roles of execution and consensus clients in Ethereum 2.0, let’s consider a practical example:
Alice initiates a transaction on Ethereum 2.0, aiming to send 5 ETH to Bob through a decentralized application (DApp). Here’s how execution and consensus clients come into play:
1. Execution Client (e.g., Geth): Alice’s transaction is picked up by the execution client, which processes the transaction. It updates account balances, executes any associated smart contract code, and prepares the transaction for validation.
2. Consensus Client (e.g., Prysm): The transaction, now prepared by the execution client, is handed over to the consensus client. Prysm validates the transaction, ensuring that Alice has sufficient funds, and verifies that the transaction complies with the network’s rules and security protocols.
3. Consensus and Finalization: The consensus client, Prysm, proposes a new block that contains Alice’s transaction to the Beacon Chain — the heart of Ethereum 2.0. Validators in the network (often managed by the consensus client) verify and vote on the validity of this proposed block.
4. Confirmation: Once a supermajority of validators reaches consensus on the validity of the block, it is finalized and added to the Beacon Chain. This, in turn, confirms Alice’s transaction, ensuring that it is included in the Ethereum 2.0 blockchain.
In this way, execution and consensus clients in Ethereum 2.0 work seamlessly together, with the execution client handling the transaction’s processing and preparation, while the consensus client ensures the transaction’s validation and agreement among network participants. This collaborative effort guarantees the secure and efficient operation of Ethereum 2.0, making it an essential advancement in blockchain technology.
Ethereum -> https://ethereum.org/en/developers/docs/intro-to-ethereum/
Geth -> https://geth.ethereum.org/docs/getting-started/installing-geth
Prysm -> https://docs.prylabs.network/docs/how-prysm-works/beacon-node
Ethereum private node -> https://ethereum.org/en/developers/docs/nodes-and-clients/run-a-node/