Consensus
Chapter 5: Blockchain Consensus Mechanisms
Section titled “Chapter 5: Blockchain Consensus Mechanisms”Overview
Section titled “Overview”Consensus mechanisms are the protocols that ensure all nodes in a blockchain network agree on a single version of the truth. Understanding consensus is crucial for node operators, as it affects node behavior, security, and performance.
5.1 What is Consensus?
Section titled “5.1 What is Consensus?”Consensus in blockchain refers to the process by which network participants agree on:
- Which transactions are valid
- The order of transactions
- The current state of the blockchain
- Which blocks should be added to the chain
┌─────────────────────────────────────────────────────────────────┐│ CONSENSUS PROCESS │├─────────────────────────────────────────────────────────────────┤│ ││ Transaction Created ││ │ ││ ▼ ││ ┌──────────────┐ ┌──────────────┐ ││ │ Node A │ │ Node B │ ││ │ Validates │ │ Validates │ ││ └──────┬───────┘ └──────┬───────┘ ││ │ │ ││ │ ┌────────────────┴────────────────┐ ││ │ │ │ ││ ▼ ▼ ▼ ││ ┌──────────────┐ ┌──────────────┐ ││ │ Vote │ │ Vote │ ││ │ "Valid" │ │ "Valid" │ ││ └──────┬───────┘ └──────┬───────┘ ││ │ ┌─────────────────┘ ││ │ │ ││ ▼ ▼ ││ ┌─────────────────────────────────────────────┐ ││ │ CONSENSUS REACHED │ ││ │ Block Added to Chain │ ││ └─────────────────────────────────────────────┘ ││ │└─────────────────────────────────────────────────────────────────┘5.2 Proof of Work (PoW)
Section titled “5.2 Proof of Work (PoW)”How PoW Works
Section titled “How PoW Works”Miners compete to solve a complex mathematical puzzle. The first to solve it gets to add the next block.
┌─────────────────────────────────────────────────────────────────┐│ PROOF OF WORK PROCESS │├─────────────────────────────────────────────────────────────────┤│ ││ Block Header ││ ┌─────────────────────────────────────────────────────────┐ ││ │ version │ prev_hash │ merkle_root │ timestamp │ nonce │ ││ └─────────────────────────────────────────────────────────┘ ││ ││ Target: Hash must be less than: ││ ┌─────────────────────────────────────────────────────────┐ ││ │ 0000000000000000000a7c1... (adjustable difficulty) │ ││ └─────────────────────────────────────────────────────────┘ ││ ││ Mining Loop: ││ ┌─────────────────────────────────────────────────────────┐ ││ │ for nonce in range(2^32): │ ││ │ hash = sha256(block_header + nonce) │ ││ │ if hash < target: │ ││ │ found! → Submit block │ ││ └─────────────────────────────────────────────────────────┘ ││ ││ Properties: ││ - Energy intensive (electricity) ││ - Hardware specialized (ASICs) ││ - 51% attack requires massive resources ││ │└─────────────────────────────────────────────────────────────────┘Difficulty Adjustment
Section titled “Difficulty Adjustment”Networks adjust difficulty to maintain consistent block times:
Bitcoin: Every 2016 blocks (~2 weeks)
new_difficulty = old_difficulty × (time_for_2016_blocks / 20160_minutes)Ethereum (PoW era):
- Difficulty bomb: Gradually increases to encourage transition to PoS
- Adjusted per block based on parent timestamp
PoW Characteristics
Section titled “PoW Characteristics”| Aspect | Description |
|---|---|
| Block Time | Bitcoin: 10 min, Ethereum: 12-14 sec |
| Finality | Probabilistic (6 confirmations for BTC) |
| Energy | Very high (TWh annually for Bitcoin) |
| Hardware | ASIC miners required |
5.3 Proof of Stake (PoS)
Section titled “5.3 Proof of Stake (PoS)”How PoS Works
Section titled “How PoS Works”Validators stake cryptocurrency as collateral. The protocol randomly selects validators to propose and validate blocks based on their stake.
┌─────────────────────────────────────────────────────────────────┐│ PROOF OF STAKE PROCESS │├─────────────────────────────────────────────────────────────────┤│ ││ Validators Staking ││ ││ Validator A ──▶ 100 ETH stake ││ Validator B ──▶ 50 ETH stake ││ Validator C ──▶ 200 ETH stake ││ Validator D ──▶ 75 ETH stake ││ ││ Selection Algorithm: ││ ┌─────────────────────────────────────────────────────────┐ ││ │ Random selection weighted by stake │ ││ │ Probability = validator_stake / total_staked │ ││ │ │ ││ │ Example: If total = 425 ETH │ ││ │ - Validator A: 100/425 = 23.5% │ ││ │ - Validator B: 50/425 = 11.8% │ ││ │ - Validator C: 200/425 = 47.1% │ ││ │ - Validator D: 75/425 = 17.6% │ ││ └─────────────────────────────────────────────────────────┘ ││ ││ Block Production: ││ 1. Select validator to propose block ││ 2. Other validators attest (vote) ││ 3. 2/3+ attestations → checkpoint finalized ││ │└─────────────────────────────────────────────────────────────────┘Ethereum PoS (Beacon Chain)
Section titled “Ethereum PoS (Beacon Chain)”After “The Merge,” Ethereum uses PoS with these components:
| Component | Description |
|---|---|
| Beacon Chain | PoS coordination layer |
| Validators | Stakers running consensus client |
| Epoch | 32 slots (6.4 minutes) |
| Slot | 12 seconds (block time) |
| Checkpoint | First slot of each epoch |
| Finality | 2 epochs (12.8 minutes) |
Slashing Conditions
Section titled “Slashing Conditions”Validators can lose stake (slashed) for:
- Double Proposing: Signing two different blocks at same height
- Double Voting: Attesting to two conflicting blocks
- Surround Voting: Creating conflicting attestations
PoS Characteristics
Section titled “PoS Characteristics”| Aspect | Description |
|---|---|
| Block Time | 12 seconds (Ethereum) |
| Finality | ~12 minutes (2 epochs) |
| Energy | Very low (99.9% reduction vs PoW) |
| Hardware | Standard server (no ASICs) |
5.4 Delegated Proof of Stake (DPoS)
Section titled “5.4 Delegated Proof of Stake (DPoS)”How DPoS Works
Section titled “How DPoS Works”Token holders vote for a small number of delegates who validate transactions on their behalf.
┌─────────────────────────────────────────────────────────────────┐│ DELEGATED PROOF OF STAKE │├─────────────────────────────────────────────────────────────────┤│ ││ ┌─────────────────────────────────────────────────────────┐ ││ │ TOKEN HOLDERS VOTING │ ││ │ │ ││ │ User A ──▶ 1000 tokens ──▶ Vote for Delegate 1 │ ││ │ User B ──▶ 500 tokens ──▶ Vote for Delegate 2 │ ││ │ User C ──▶ 2000 tokens ──▶ Vote for Delegate 1 │ ││ │ │ ││ └─────────────────────────────────────────────────────────┘ ││ │ ││ ▼ ││ ┌─────────────────────────────────────────────────────────┐ ││ │ TOP 21 DELEGATES BECOME VALIDATORS │ ││ │ │ ││ │ Delegate 1 ──▶ 15% of votes ──▶ Block Producer │ ││ │ Delegate 2 ──▶ 10% of votes ──▶ Block Producer │ ││ │ Delegate 3 ──▶ 8% of votes ──▶ Block Producer │ ││ │ ... │ ││ │ │ ││ └─────────────────────────────────────────────────────────┘ ││ ││ Block Production: ││ - Delegates take turns producing blocks ││ - Typically 1-3 second block times ││ - High throughput ││ │└─────────────────────────────────────────────────────────────────┘DPoS Examples
Section titled “DPoS Examples”| Blockchain | Delegates | Block Time |
|---|---|---|
| EOS | 21 | 0.5 sec |
| Tron | 27 | 3 sec |
| Cosmos | 100 (active) | 5-7 sec |
| Solana | Varies (PoH+PoS) | 0.4 sec |
5.5 Practical Byzantine Fault Tolerance (PBFT)
Section titled “5.5 Practical Byzantine Fault Tolerance (PBFT)”How PBFT Works
Section titled “How PBFT Works”A consensus algorithm where a leader proposes blocks and validators vote on them. Can tolerate up to 1/3 Byzantine (malicious) nodes.
┌─────────────────────────────────────────────────────────────────┐│ PBFT CONSENSUS PHASES │├─────────────────────────────────────────────────────────────────┤│ ││ Phase 1: Pre-Prepare ││ ┌─────────────────────────────────────────────────────────┐ ││ │ Leader ──▶ Proposes Block │ ││ │ │ │ ││ │ ▼ │ ││ │ All Validators receive pre-prepare message │ ││ └─────────────────────────────────────────────────────────┘ ││ │ ││ ▼ ││ Phase 2: Prepare ││ ┌─────────────────────────────────────────────────────────┐ ││ │ Validator 1 ──▶ Prepare ──▶ All other validators │ ││ │ Validator 2 ──▶ Prepare ──▶ All other validators │ ││ │ Validator 3 ──▶ Prepare ──▶ All other validators │ ││ │ │ ││ │ Need 2f+ prepare messages to proceed │ ││ │ (f = number of Byzantine faults tolerated) │ ││ └─────────────────────────────────────────────────────────┘ ││ │ ││ ▼ ││ Phase 3: Commit ││ ┌─────────────────────────────────────────────────────────┐ ││ │ Validator 1 ──▶ Commit ──▶ All other validators │ ││ │ ... │ ││ │ │ ││ │ Need 2f+ commit messages to finalize │ ││ └─────────────────────────────────────────────────────────┘ ││ │ ││ ▼ ││ Block Finalized ││ │└─────────────────────────────────────────────────────────────────┘Tendermint (Cosmos)
Section titled “Tendermint (Cosmos)”Cosmos uses a BFT-based consensus called Tendermint:
- Validators: 100-200 typically
- Block Time: 5-7 seconds
- Finality: Immediate (1 block)
- Byzantine Tolerance: Up to 1/3 malicious validators
5.6 Comparison of Consensus Mechanisms
Section titled “5.6 Comparison of Consensus Mechanisms”┌─────────────────────────────────────────────────────────────────────────────┐│ CONSENSUS COMPARISON │├──────────────┬─────────┬─────────┬─────────┬──────────────┬─────────────┤│ Mechanism │ PoW │ PoS │ DPoS │ PBFT/Tendermint│ PoH+PoS │├──────────────┼─────────┼─────────┼─────────┼──────────────┼─────────────┤│ Block Time │ 10-15s │ 12s │ 0.5-3s │ 5-7s │ 0.4s │├──────────────┼─────────┼─────────┼─────────┼──────────────┼─────────────┤│ Finality │ 60 min │ 12 min │ 3s │ Immediate │ Immediate │├──────────────┼─────────┼─────────┼─────────┼──────────────┼─────────────┤│ Transactions │ 7 TPS │ 15-30 │ 1000+ │ 1000+ │ 65,000 ││ │ (BTC) │ TPS │ TPS │ TPS │ TPS │├──────────────┼─────────┼─────────┼─────────┼──────────────┼─────────────┤│ Energy Use │ Very │ Low │ Low │ Low │ Low ││ │ High │ │ │ │ │├──────────────┼─────────┼─────────┼─────────┼──────────────┼─────────────┤│ Decentral- │ High │ High │ Medium │ Medium │ Medium ││ ization │ │ │ │ │ │├──────────────┼─────────┼─────────┼─────────┼──────────────┼─────────────┤│ Examples │ BTC, │ ETH2, │ EOS, │ Cosmos, │ Solana ││ │ ETH(legacy)│ ADA │ Tron │ Hyperledger │ │└──────────────┴─────────┴─────────┴─────────┴──────────────┴─────────────┘5.7 Node Role in Consensus
Section titled “5.7 Node Role in Consensus”Validator Node Operations
Section titled “Validator Node Operations”┌─────────────────────────────────────────────────────────────────┐│ VALIDATOR NODE OPERATIONS │├─────────────────────────────────────────────────────────────────┤│ ││ ┌─────────────────────────────────────────────────────────┐ ││ │ PROPOSER DUTY │ ││ │ │ ││ │ 1. Select transactions from mempool │ ││ │ 2. Create block │ ││ │ 3. Execute state transitions │ ││ │ 4. Sign and broadcast block │ ││ │ │ ││ └─────────────────────────────────────────────────────────┘ ││ │ ││ ▼ ││ ┌─────────────────────────────────────────────────────────┐ ││ │ ATTESTOR DUTY │ ││ │ │ ││ │ 1. Receive proposed block │ ││ │ 2. Validate block │ ││ │ 3. Sign attestation (vote) │ ││ │ 4. Broadcast attestation │ ││ │ │ ││ └─────────────────────────────────────────────────────────┘ ││ │└─────────────────────────────────────────────────────────────────┘Full Node Consensus Participation
Section titled “Full Node Consensus Participation”Non-validating full nodes still participate by:
- Validating all blocks and transactions independently
- Propagating valid blocks to peers
- Rejecting invalid blocks
- Maintaining chain fork information
5.8 Fork Choice Rules
Section titled “5.8 Fork Choice Rules”When there are multiple valid chains, nodes use fork choice rules to determine which chain to follow.
Ethereum: LMD-GHOST
Section titled “Ethereum: LMD-GHOST”Latest Message-Driven Greedy Heaviest Observed SubTree
At slot N:1. Start at genesis2. At each step, follow the subtree with the most recent attestation3. Select block with most validator supportBitcoin: Longest Chain
Section titled “Bitcoin: Longest Chain”1. Count total work (cumulative difficulty)2. Follow chain with highest total work3. Orphaned blocks are discarded5.9 Interview Questions
Section titled “5.9 Interview Questions”| Question | Answer |
|---|---|
| What is the difference between PoW and PoS? | PoW uses computational work; PoS uses staked tokens |
| What is finality in blockchain? | The point at which a block cannot be reversed |
| What is slashing in PoS? | Penalty for validator misbehavior |
| What is 51% attack? | When attacker controls majority of hash/stake |
Summary
Section titled “Summary”- Consensus mechanisms ensure agreement on blockchain state
- PoW: Energy-intensive, secure (Bitcoin)
- PoS: Energy-efficient, randomized selection (Ethereum)
- DPoS: Fast, elected validators (EOS, Tron)
- PBFT/Tendermint: BFT consensus, fast finality (Cosmos)
- Node operators must understand consensus to manage validators
Next Chapter
Section titled “Next Chapter”In Chapter 6: Ethereum Network & Ecosystem, we’ll explore Ethereum in detail.
Last Updated: 2026-02-20