Ethereum Block Structure: A Deep Dive into go-ethereum Source Code

·

Today, we’ll explore the blockchain architecture of Ethereum by analyzing the go-ethereum (geth) source code, focusing on the block data structure and its components.

Key Details:

  • Source: go-ethereum (Frost v1.8.2).
  • Scope: Block header, body, and related consensus mechanisms.

1. Ethereum’s Modular Architecture

Ethereum’s ecosystem comprises several core modules:


2. go-ethereum Source Directory Breakdown

The project’s structure is logically organized:

| Directory | Purpose |
|-------------------------|--------------------------------------|
| accounts/ | Wallet and account management. |
| consensus/ | Ethash (PoW) and other algorithms. |
| core/ | EVM, state trie, and blockchain logic.|
| crypto/ | Cryptographic functions. |
| miner/ | Block mining and creation. |
| rlp/ | Recursive Length Prefix encoding. |

👉 Explore the full directory tree


3. Block Structure Explained

3.1 Block Header

Defined in core/types/block.go, a block contains:

type Block struct {
  header        *Header
  uncles        []*Header
  transactions  []*Transaction
  td            *big.Int  // Total difficulty
}

Header Fields:

Example Header:

{
  "ParentHash": "0x...",
  "Difficulty": "2944102190231396",
  "GasLimit": 8000029,
  "Nonce": "0x..."
}

3.2 Block Body

The body holds:

type Body struct {
  Transactions []*Transaction
  Uncles       []*Header
}

3.3 Genesis Block

The first block in Ethereum (mainnet):

DefaultGenesisBlock() *Genesis {
  return &Genesis{
    Nonce:     66,
    GasLimit: 5000,
    Difficulty: big.NewInt(17179869184),
  }
}

👉 View Genesis Block


3.4 Block Creation

New blocks are minted via miner/worker.go:

func NewBlock(header *Header, txs []*Transaction, uncles []*Header) *Block {
  // Validates and assembles the block.
}

4. Blockchain Management

The BlockChain struct (in core/blockchain.go) tracks:


5. Miner Workflow

  1. Start Mining: miner.start().
  2. Pending Block: Created by worker.pendingBlock().
  3. Seal Block: Consensus engine validates the block.

FAQs

Q1: What’s stored in the block header?

The header includes metadata like hashes, timestamps, and difficulty metrics.

Q2: How are uncles rewarded?

Uncles receive a fraction of the block reward to incentivize network security.

Q3: What’s RLP encoding?

Recursive Length Prefix is Ethereum’s compact serialization method for data structures.


👉 Read more about Ethereum’s architecture