Tendermint Consensus Interview Questions

Tendermint consensus algorithm interview questions covering the Byzantine Fault Tolerant consensus used in Cosmos chains.

Q1: How does Tendermint consensus work?

Answer:

Tendermint is a Byzantine Fault Tolerant consensus algorithm used in Cosmos chains.

Sequence Diagram:

Overall Flow Diagram:

Individual Node Decision Diagram:

Tendermint Phases:

1. Propose:

  • Proposer selected (round-robin by voting power)
  • Creates block with transactions
  • Broadcasts proposal

2. Prevote:

  • Validators receive proposal
  • Validate block
  • Broadcast prevote (yes/no)
  • Need 2/3+ prevotes to continue

3. Precommit:

  • After 2/3+ prevotes, broadcast precommit
  • Need 2/3+ precommits to commit
  • If timeout: Move to next round

4. Commit:

  • Block committed when 2/3+ precommits received
  • State updated
  • Move to next height

Key Properties:

  • Finality: Blocks are final (no reorgs)
  • Safety: Tolerates up to 1/3 Byzantine validators
  • Liveness: Continues with 2/3+ honest validators
  • Fast: ~1-6 second block time

Example:

 1type TendermintState struct {
 2    Height int64
 3    Round  int32
 4    Step   Step
 5}
 6
 7type Step int
 8
 9const (
10    StepPropose Step = iota
11    StepPrevote
12    StepPrecommit
13    StepCommit
14)
15
16func (s *TendermintState) Propose(block *Block) {
17    // Proposer creates and broadcasts block
18    s.Step = StepPropose
19    broadcastProposal(block)
20}
21
22func (s *TendermintState) Prevote(blockID BlockID) {
23    // Validators vote on proposal
24    s.Step = StepPrevote
25    if validateBlock(blockID) {
26        broadcastPrevote(blockID, true)
27    } else {
28        broadcastPrevote(blockID, false)
29    }
30}
31
32func (s *TendermintState) Precommit(blockID BlockID) {
33    // After 2/3+ prevotes, precommit
34    if countPrevotes(blockID) >= getQuorum() {
35        s.Step = StepPrecommit
36        broadcastPrecommit(blockID, true)
37    }
38}
39
40func (s *TendermintState) Commit(blockID BlockID) {
41    // After 2/3+ precommits, commit block
42    if countPrecommits(blockID) >= getQuorum() {
43        s.Step = StepCommit
44        commitBlock(blockID)
45        s.Height++
46        s.Round = 0
47    }
48}

Use Cases:

  • Cosmos chains
  • Binance Chain
  • Terra

Related Snippets