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:
- Blockchain Management: Core ledger maintenance.
- Miner: Block creation and PoW/PoS consensus.
- Swarm: Distributed storage.
- Smart Contracts: Solidity, LLL, and EVM execution.
- P2P Networking: Whisper and DevP2P protocols.
- Cryptography: SHA-3, RLP encoding, and keccak256 hashing.
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:
- ParentHash: Previous block’s hash.
- TxHash: Merkle root of transactions.
- Difficulty: PoW complexity metric.
- GasLimit/Used: Network capacity metrics.
Example Header:
{
"ParentHash": "0x...",
"Difficulty": "2944102190231396",
"GasLimit": 8000029,
"Nonce": "0x..."
}3.2 Block Body
The body holds:
- Transactions: List of
Transactionobjects. - Uncles: Stale blocks’ headers (for rewards).
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),
}
}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:
- HeaderChain: Linked list of headers.
- StateDB: World state trie.
- Consensus Engine: PoW/PoS logic.
5. Miner Workflow
- Start Mining:
miner.start(). - Pending Block: Created by
worker.pendingBlock(). - 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