Introduction to Ethereum's Data Storage
Ethereum's data storage can be categorized into three types:
- State Data: Stores account-related state information using StateDB. Each account is represented as a StateObject.
- Blockchain: The core data structure of Ethereum, similar to Bitcoin but with evolutionary improvements.
- Underlying Data: Stores all Ethereum data in a key-value format within LevelDB.
Key Components of Ethereum's Data Structure
State Data Storage (StateDB)
State data is stored as a Merkle Patricia Trie (MPT) in StateDB. MPT combines features of Merkle Trees and Patricia Tries for efficient key-value storage and verification.
MPT Characteristics:
- Supports arbitrary-length key-value pairs.
- Enables rapid node validation (Merkle Tree feature).
- Efficient key-value lookup.
MPT Node Types:
shortNode: A branch node with a single child.fullNode: A branch node with multiple children.valueNode: A leaf node storing data (value = concatenated keys from root to node).hashNode: A leaf node storing hash references to other nodes.
Blockchain Structure
Ethereum's blockchain shares two key similarities with Bitcoin:
- Parent Hash Linking: Blocks are chained via parent block hashes.
- Block Composition: Each block consists of a header and body.
Ethereum Block Header Fields
| Field | Description | PoS 2.0 Status |
|---|---|---|
ParentHash | Hash of the parent block. | Retained |
CoinBase | Miner's wallet address (reward recipient). | Retained |
UncleHash | Merkle root hash of uncle blocks (PoW-only). | Removed |
Root | MPT root hash of StateDB (stores all account data). | Retained |
TxHash | Merkle root hash of transactions in the block. | Retained |
ReceiptHash | MPT root hash of transaction receipts (includes gas costs and logs). | Retained |
Bloom | Bloom filter for fast log search in receipts. | Retained |
Difficulty | Mining difficulty factor (PoW-only). | Removed |
Nonce | Random value for PoW validation (PoW-only). | Removed |
MixHash | Final random value for PoW verification (PoW-only). | Removed |
Number | Block number. | Retained |
Time | Block creation timestamp. | Retained |
GasLimit | Maximum gas allowed per block. | Retained |
GasUsed | Actual gas consumed by transactions in the block. | Retained |
extraData | Custom data (≤32 bytes) added by block creators. | Retained |
Transaction (Tx) Structure
Ethereum transactions include:
- GasPrice: Price per gas unit (wei). Higher prices prioritize mining.
- GasLimit: Maximum gas allocated for execution.
- Recipient: Receiver address.
- Amount: Transferred value.
- Payload: Contract execution data (critical for smart contracts).
- R,S,V: Cryptographic signatures.
👉 Learn more about Ethereum gas mechanics
Fork Resolution: Bitcoin vs. Ethereum
Bitcoin's Approach (Longest Chain Rule)
- Process: Nodes adopt the chain with the most cumulative PoW.
- Orphan Blocks: Discarded blocks with no reward.
- Impact: Transactions in orphan blocks return to the mempool.
Ethereum's Approach (Uncle Blocks)
- Process: Valid but non-canonical blocks ("uncles") earn partial rewards.
Rewards:
- Uncle block miners receive reduced rewards.
- Main block miners get bonuses for including uncles (max 2 uncles/block).
- Advantage: Reduces PoW resource waste during forks.
FAQ Section
1. What is MPT in Ethereum?
MPT (Merkle Patricia Trie) is a hybrid data structure combining Merkle Trees and Patricia Tries for efficient state storage and verification.
2. Why were PoW fields removed in Ethereum 2.0?
Ethereum 2.0 transitions to Proof-of-Stake (PoS), eliminating PoW-specific fields like Difficulty, Nonce, and MixHash.
3. How does Ethereum handle transaction fees?
Fees are calculated as GasUsed × GasPrice and paid to miners/validators.
4. What’s the purpose of the Bloom filter?
It enables fast checks for transaction logs in receipts without full data scans.
5. Can uncle blocks appear in Ethereum 2.0?
No. Uncle blocks are exclusive to PoW and are deprecated in PoS.