Ethereum is a peer-to-peer network where thousands of computers, called nodes, communicate using shared rules. These rules, known as the "networking layer," help nodes find each other and share information. This communication happens in two ways: broadcasting data to many nodes (gossiping) and sending specific messages between individual nodes.
Ethereum nodes have two main parts: execution clients and consensus clients. Each has its own job and network. Execution clients share transactions in an encrypted P2P network, storing them in a local pool. When a validator creates a new block, these transactions are sent to the consensus client through a local connection. The consensus client packages them into Beacon blocks and shares them on its P2P network. This setup requires two separate P2P networks: one for sharing transactions and another for sharing blocks, ensuring smooth and secure communication between nodes.
The Ethereum execution layer uses two main networking protocol stacks to keep the network running:
Both stacks work together in parallel. The discovery stack ensures that new nodes can join the network, while the DevP2P stack handles communication between nodes, enabling them to interact seamlessly. This combination ensures that Ethereum's peer-to-peer network remains decentralized and efficient.
When a new Ethereum node joins the network, it needs to find other nodes to connect with. This process is called discovery.
What Are Bootnodes?
Bootnodes are special nodes with hardcoded addresses in Ethereum clients.
Their sole purpose is to introduce new nodes to the network by providing a list of active peers.
They do not participate in tasks like syncing the blockchain and are only used the first time a client connects to the network.
How It Works:
Ethereum nodes use peer discovery protocols to locate and connect with other nodes in the network. This is essential for maintaining Ethereum's decentralized peer-to-peer (P2P) network. Currently, Ethereum uses Discovery Protocol Version 4 (Discv4) and is transitioning to Discovery Protocol Version 5 (Discv5). Here's how these protocols work:
Steps to Discover Peers:
A new node sends a PING message to a bootnode or a known peer.
The PING contains:
The bootnode responds with a PONG message that includes the hash sent in the PING.
If the hashes match, the connection is verified, and the nodes are considered bonded (trusted).
Once bonded, the new node sends a FIND_NEIGHBOURS request to the bootnode.
The bootnode replies with a list of neighboring peers (nodes that are close to the new node's ID in the network).
The new node performs a PING-PONG exchange with each neighbor received from the bootnode.
Successful exchanges bond the new node with these neighbors, allowing them to communicate.
Enhancements Over Discv4:
Ethereum Node Records (ENR): A structured object introduced in Discv5 to manage identifying information. Key components of ENR include:
Dynamic IP Handling: ENR supports nodes with changing IP addresses, improving network flexibility.
Future-Proof Design: The ENR format is versatile, accommodating future changes in network structure.
Additional Features:
Why ethereum discovery is built on UDP protocol over TCP protocol?
The Ethereum discovery protocol uses UDP because it's fast and simple, without the need for setting up connections or handling errors. This makes it perfect for quickly finding other nodes in the network. UDP just sends information efficiently without waiting for confirmation. For more detailed tasks, like syncing data, Ethereum uses TCP, which ensures reliable communication with features like error checking and resending data if something goes wrong. This way, Ethereum uses UDP for speed during discovery and TCP for reliability during data exchange.
After discovering peers, Ethereum nodes use the DevP2P stack, starting with the RLPx protocol to establish secure communication.
RLPx is a key protocol in Ethereum's DevP2P stack that helps nodes connect and communicate securely. It uses RLP (Recursive Length Prefix) encoding to compress and organize data efficiently for transmission. The protocol ensures encrypted and authenticated communication, creating a secure connection between nodes. Once this connection is established, nodes can interact using various subprotocols for exchanging blockchain data or for syncing state, enabling smooth and reliable network operations.
Cryptographic Handshake: The nodes exchange public keys and initiate encryption using ECIES (Elliptic Curve Integrated Encryption Scheme). This generates a shared secret, ensuring secure communication between the nodes.
Hello Exchange: Following the handshake, the nodes send "hello" messages containing key details, including:
Supported subprotocols.
Client version.
Node ID.
Port and protocol version information. This allows both nodes to identify each other's capabilities and set up a compatible connection.
Session Maintenance:
Transaction and Data Exchange
After nodes are connected, the wire protocol manages how they communicate. It originally handled tasks like:
Syncing chains: Ensuring all nodes are up-to-date with the blockchain.
Propagating blocks: Sharing new blocks across the network.
Exchanging transactions: Sharing pending transactions between nodes for future blocks.
However, with Ethereum's shift to Proof of Stake (PoS), syncing blocks and chain data is now part of the consensus layer, while transaction exchange continues under execution clients.
Light Ethereum Subprotocol (LES)
The LES protocol is for light clients, which are nodes that don’t store the whole blockchain. They rely on full nodes to provide data when needed. Light clients save space and resources, but they depend on full nodes to share information with them. However, because full nodes aren’t incentivized to serve light clients, LES has not been used much.
Snap Protocol
The Snap protocol is an extension that helps Ethereum nodes exchange state snapshots (recent data states). This allows nodes to verify accounts and storage without downloading too much data, speeding up the process of syncing with the network.
Witness Protocol (Wit)
The Witness Protocol lets Ethereum nodes share state witnesses, helping them stay updated with the latest blockchain state. This is especially useful for clients syncing to the latest block, reducing the amount of data they need to download.
Whisper Protocol (Deprecated)
The Whisper protocol was designed for secure messaging between nodes, without storing any messages on the blockchain. However, it had problems with scalability and wasn’t widely adopted. As a result, it has been deprecated, and other projects are now working on similar secure messaging solutions.
The Ethereum consensus layer ensures that all Ethereum nodes agree on the state of the blockchain, keeping everything in sync. It works separately from the execution layer (where transactions are executed) but needs to interact closely with it.
Just like the execution clients, the consensus clients need a way to discover other nodes (peers) in the network. They use a protocol called discV5 over UDP. This is different from the old DevP2P system and integrates libP2P, a newer and more flexible technology.
Each consensus node in the Ethereum network has an Ethereum Node Record (ENR), which helps other nodes identify and connect to it. The ENR contains:
After discovering peers, the consensus layer uses libP2P to keep the communication going. It uses two main methods for communication:
Gossip: This helps spread important updates like new blocks and attestations quickly across the network. It’s like passing a note between people in class, making sure everyone gets the same information fast.
Request-Response: This is a more specific way for one node to ask another for particular data, like a block with certain information. It’s like requesting a copy of a specific page from a book.
In Ethereum's consensus layer, SSZ (Simple Serialization) is used instead of the usual RLP (Recursive Length Prefix) format. This is because SSZ is faster and more efficient when dealing with large data and makes it easier to verify information in Merkle trees, which are used to keep the blockchain secure.
The execution layer (which processes transactions) and the consensus layer (which secures the blockchain) need to talk to each other. This happens through a local RPC connection. They share a common Ethereum Node Record (ENR), which keeps track of information like the client's public key and which layer it belongs to.
create block
method in execution client (local RPC)
References: