1 of 57

Reaching consensus with Tendermint

2 of 57

3 of 57

in this talk

  • a couple known problems in distributed systems
  • an overview of Raft
  • an overview of Tendermint
  • writing a Go app using CometBFT

4 of 57

not in this talk

  • precise or formal definitions

5 of 57

A simple state machine

6 of 57

7 of 57

8 of 57

A single node scenario

9 of 57

10 of 57

11 of 57

12 of 57

What to do in case of multiple nodes?

13 of 57

14 of 57

Two generals problem

15 of 57

16 of 57

17 of 57

18 of 57

19 of 57

20 of 57

21 of 57

22 of 57

Two generals problem

impossible

23 of 57

24 of 57

Raft

25 of 57

Raft: leader election

26 of 57

27 of 57

28 of 57

29 of 57

30 of 57

31 of 57

this is called eventual consistency

32 of 57

Byzantine generals problem

even harder than the two

generals problem,

when you have bad friends

33 of 57

34 of 57

35 of 57

36 of 57

37 of 57

BFT algorithms

Byzantine-Fault Tolerant

38 of 57

Tendermint

Currently, CometBFT is the only production ready implementation

39 of 57

40 of 57

41 of 57

42 of 57

43 of 57

44 of 57

Tendermint: leader election

  • Only valid for the current round
  • Deterministic, round-robin
  • A simple example:

Round: 123

Validators count: 5

Current leader: 123 % 5 = 3

45 of 57

Leader sends

proposal

46 of 57

Prevote phase

Each nodes checks if the proposal is valid or not, without actually writing anything to their state.

47 of 57

Prevote phase

48 of 57

Prevote phase

Each nodes wait for

at least ⅔ of OKs.

⅔ * 5 ~= 4

49 of 57

Prevote phase

Each nodes wait for

at least ⅔ of OKs.

⅔ * 5 ~= 4

50 of 57

Precommit phase

Works exactly the same as the Prevote phase.

Each node acts independently. When it sees ⅔+ prevotes, it moves to the precommit phase.

51 of 57

Commit phase

Each node updates its local state (i.e. to disk) when it sees ⅔+ Precommit votes.

The non-validator nodes will commit the new state too.

52 of 57

Repeat

Round: 124

Validators count: 5

Current leader: 124 % 5 = 4

53 of 57

Let’s recap

54 of 57

Building a Go app

55 of 57

type Application interface {

CheckTx(ctx, req) (res, error)

FinalizeBlock(ctx, req) (res, error)

Commit(ctx, req) (res, error)

...

56 of 57

type Application interface {

...

Query(ctx,req) (res, error)

}

57 of 57

Demo

MeteorKV @ https://github.com/Pitasi/x