Networking Layer

 

Networking Layer 


The two brains inside one Ethereum node

Every modern Ethereum node has two separate programs running:

1️⃣ Execution Client (EL)

πŸ‘‰ Think “WHAT happened?”

  • Handles:

    • Transactions

    • Smart contract execution

    • Account balances

    • EVM

  • Examples: Geth, Nethermind, Erigon

2️⃣ Consensus Client (CL)

πŸ‘‰ Think “DO we all agree this happened?”

  • Handles:

    • Blocks

    • Validators

    • Attestations

    • Finality (PoS logic)

  • Examples: Prysm, Lighthouse, Teku

πŸ’‘ These two must talk to each other, but they also talk to other nodes.

That’s why networking looks complex.


Why TWO P2P networks?

Because different data has different needs.

LayerWhat it gossipsWhy
Execution P2PTransactionsNeed fast spread
Consensus P2PBlocks, attestationsNeed global agreement

So Ethereum uses:

  • Execution-layer P2P network

  • Consensus-layer P2P network

Separate highways 🚧


Step 1: How a new node finds friends (Discovery)

Question:

How does a brand-new node find anyone at all?

Answer: Bootnodes + Discovery

Think like this:

  • You install Ethereum

  • You know nobody

  • Ethereum ships with a few phone numbers hardcodedbootnodes


Discovery uses UDP (WHY?)

UDP = fast + cheap + no connection

Perfect for:

  • “Hey, I exist”

  • “Who else is here?”

❌ Not for real conversations
✅ Only for finding peers


Discovery flow (very important)

start client ↓ connect to bootnode ↓ PING → PONG (bonding) ↓ FIND_NEIGHBOURS ↓ get peer list ↓ PING → PONG with peers

After this:
πŸ‘‰ “Okay, I know people now”


What is ENR (Ethereum Node Record)?

Think of ENR as a node’s visiting card:

  • Public key

  • IP address

  • Ports

  • Supported protocols

  • Consensus info (for CL)

Nodes exchange ENRs to know how to talk.


Step 2: Real conversations (DevP2P / libP2P)

Discovery only introduces people.

Now real talking starts.


Execution Layer networking (EL)

Stack:

UDP → Discovery (find peers) TCP → DevP2P → RLPx → Sub-protocols

Why TCP here?

Because now nodes:

  • exchange transactions

  • need reliability

  • need encryption

  • need session management


RLPx (secure channel)

RLPx does:

  • cryptographic handshake

  • key exchange

  • encrypted communication

Then nodes say “hello” πŸ‘‹

Hello message includes:

  • client type

  • protocol version

  • supported sub-protocols

Only common protocols are used.


What does Execution layer gossip?

Only this now:

Pending transactions

❌ Blocks (moved to consensus layer after PoS)


Consensus Layer networking (CL)

Consensus does NOT use DevP2P.

It uses:

UDP → discv5 TCP → libP2P

Much more modern.


Why libP2P?

Because consensus needs:

  • high-speed gossip

  • topic-based messaging

  • better scalability

Used in:

  • IPFS

  • Filecoin

  • Ethereum consensus


Two communication styles in CL

1️⃣ Gossip (one → many)

Used for:

  • Beacon blocks

  • Attestations

  • Slashings

Fast spread πŸ”₯

2️⃣ Request–Response (one → one)

Used for:

  • “Give me block X”

  • “Give me blocks from slot A to B”

Precise data 🎯


Why SSZ instead of RLP?

Think performance.

SSZ:

  • Fixed offsets

  • Easy partial decoding

  • Built for Merkle trees

  • Unique encoding (no ambiguity)

Perfect for consensus + hashing.


Step 3: Execution ↔ Consensus communication (Engine API)

Now the most important mental model 

Execution and Consensus are like two apps on the same machine talking via local RPC.

They do NOT gossip with each other over the internet.


When node is NOT block producer

Let’s walk slowly 

1️⃣ Consensus client receives block (from gossip)
2️⃣ Checks:

  • sender valid?

  • metadata correct?

3️⃣ Sends block’s execution payload to execution client
4️⃣ Execution client:

  • runs transactions

  • checks state hashes

5️⃣ Says back:

  • “Yes valid” or “Invalid”

6️⃣ Consensus:

  • adds block

  • attests

  • gossips attestation


When node IS block producer (important)

1️⃣ Consensus client learns:

“You are the proposer”

2️⃣ Consensus → Execution:

“Create a block”

3️⃣ Execution client:

  • pulls transactions from mempool

  • executes them

  • builds execution payload

4️⃣ Consensus client:

  • wraps it into beacon block

5️⃣ Beacon block is gossiped

6️⃣ Other nodes validate → attest → finalize

Comments

Popular posts from this blog

Frontend-to-Blockchain Flow

Top-to-bottom map of how an Ethereum node is structured

Arbitrum vs Optimism Rollups