Reaching consensus with Tendermint
https://anto.pt/gomad24
in this talk
not in this talk
A simple state machine
A single node scenario
What to do in case of multiple nodes?
Two generals problem
Two generals problem
impossible
Raft
Raft: leader election
this is called eventual consistency
Byzantine generals problem
even harder than the two
generals problem,
when you have bad friends
BFT algorithms
Byzantine-Fault Tolerant
Tendermint
Currently, CometBFT is the only production ready implementation
Tendermint: leader election
Round: 123
Validators count: 5
Current leader: 123 % 5 = 3
Leader sends
proposal
Prevote phase
Each nodes checks if the proposal is valid or not, without actually writing anything to their state.
Prevote phase
Prevote phase
Each nodes wait for
at least ⅔ of OKs.
⅔ * 5 ~= 4
Prevote phase
Each nodes wait for
at least ⅔ of OKs.
⅔ * 5 ~= 4
Precommit phase
Works exactly the same as the Prevote phase.
Each node acts independently. When it sees ⅔+ prevotes, it moves to the precommit phase.
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.
Repeat
Round: 124
Validators count: 5
Current leader: 124 % 5 = 4
Let’s recap
Building a Go app
type Application interface {
CheckTx(ctx, req) (res, error)
FinalizeBlock(ctx, req) (res, error)
Commit(ctx, req) (res, error)
...
type Application interface {
...
Query(ctx,req) (res, error)
}
Demo
MeteorKV @ https://github.com/Pitasi/x