Professional Documents
Culture Documents
Week 6
Week 6
S1:
while (moreGoods == 1)
DeliverGoods();
S2:
if (allOrderComplete == 0) goto S1;
else {
S3:
printf("Goods transfer complete");
}
State Machine Replication Replicate the state machine
on multiple independent
servers
State Machine Replication T1:
I have delivered 100kg
potatoes
T1
State Machine Replication
T1
T2:
I have delivered
50kg tomatoes
T2
State Machine Replication
T1
T2
State Machine Replication
T1
Consensus on the
Ordering of the
transactions
T2
State Machine Replication T1
T2
T1 T1
T2 T2
State Machine Replication T1
T2
T1 Independently T1
T2 execute the T2
transactions
on the state
machine
State Machine Replication T1
T2
T1 Independently T1
T2 execute the T2
transactions
on the state
machine
State Machine Replication
S2
S2
Consensus on the
Final State
S2
State Machine Replication
S2
S2
S2
Importance of Consensus
S2
S3
S2
Importance of Consensus
S2
Majority Voting – S3
Agree on S2
S2
Conclusion
• Consensus is still required within a closed environment
• Paxos
State Machine Replication as Consensus
• CFT Consensus
• Paxos (Proposed by Lamport, the most fundamental CFT) --
used in DynamoDB
• RAFT (Much simpler than Paxos) -- Used in Fabric Transaction
Ordering
CFT Consensus
We'll see how Paxos works
• CFT Consensus
• Paxos (Proposed by Lamport, the most fundamental CFT) --
used in DynamoDB
• RAFT (Much simpler than Paxos) -- Used in Fabric Transaction
Ordering
CFT in a Synchronous System
CFT in a Synchronous System
Let's go for
a dinner
CFT in a Synchronous System
Let's go for
a dinner
Perfect!
I'm in ...
Let's go ...
CFT in a Synchronous System
Let's go for
a dinner Majority agreed …
Perfect!
Perfect consensus
I'm in ...
Let's go ...
CFT in an Asynchronous System
Let's go for
a dinner
CFT in an Asynchronous System
Let's go for
a dinner
I'm in
CFT in an Asynchronous System
Let's go for
a dinner
I'm in
I'm okay
CFT in an Asynchronous System
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
CFT in an Asynchronous System
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
prefer movie
CFT in an Asynchronous System
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
CFT in an Asynchronous System
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
CFT in an Asynchronous System
Let's go for
a dinner Consensus on a
I'm in Movie
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
CFT in an Asynchronous System
Nopes ! We decided
for a movie!
CFT in an Asynchronous System
Nopes ! We decided
for a movie!
Umm! May
not like, but that's
the only option for
me :(
CFT in an Asynchronous System
How many
We are going for people can be
dinner, right?
sleeping at a time?
Nopes ! We decided
for a movie!
Umm! May
not like, but that's
the only option for
me :(
CFT in an Asynchronous System
Nopes ! We decided
for a movie!
2
Umm! May
not like, but that's
the only option for
me :(
Asynchronous CFT
• If there are F faulty nodes (crash fault), we need atleast 2F+1
nodes to reach consensus
• CFT
Paxos – The Roles of Individuals
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
Paxos – The Roles of Individuals
Proposer Proposer
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
Paxos – The Roles of Individuals
Acceptor Proposer Acceptor Acceptor Proposer
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
Acceptor Acceptor
Acceptor Proposer Acceptor Acceptor Proposer
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
Learner Learner
Learner Acceptor Learner Learner Acceptor
Acceptor Proposer Acceptor Acceptor Proposer
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
Learner Learner
Learner Acceptor Learner Learner Acceptor
Acceptor Proposer Acceptor Acceptor Proposer
Let's go for
a dinner
I'm in
A node can have any or all of
the three roles Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
Learner Learner
Learner Acceptor Learner Learner Acceptor
Acceptor Proposer Acceptor Acceptor Proposer
Let's go for
a dinner
A node can have any or all of the three roles
I'm in
However, the nodes must knowCan howwe go
I'm okay for a movie?
many acceptors aI majority
would
is
Movie is a prefer movie
better idea
I'm okay with
movie too ...
Learner Learner
Learner Acceptor Learner Learner Acceptor
Acceptor Proposer Acceptor Acceptor Proposer
Let's go for
a dinner
Two majorities will always overlap in
I'm in
atleast I'm
one okay nodes Can we go
for a movie?
5 acceptors, majority = 3,I would
Movie is a 2 proposers: prefer movie
better idea
To accept based on majority voting, at least one acceptor
I'm okay with
movie need
too ... to choose between one of the two proposals
Paxos Basics
Acceptor
Acceptor
Acceptor
Paxos Algorithm
Proposer
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
PROMISE 100
Acceptor
Acceptor
Acceptor
PROMISE 100
Acceptor
Acceptor
Acceptor
PROMISE 100
Acceptor
Acceptor
Acceptor
PROMISE 100
Acceptor
Acceptor
Acceptor
PROMISE 100 ACCEPT 100, "Dinner"
Acceptor
Acceptor
Acceptor
PROMISE 100 ACCEPT 100, "Dinner"
Acceptor
Acceptor
Acceptor
ACCEPT 100, "Dinner"
Paxos – Multiple Proposers
PREPARE 150
Proposer Proposer
PROMISE 150,
accepted 100,
Acceptor "Dinner"
Acceptor
Acceptor
ACCEPT 100, "Dinner"
• Acceptor received a PREPARE message with IDp:
• Did it promised to ignore requests with this IDp?
• YES: Ignore
• NO: Will promise to ignore any request lower than IDp
• Has it ever accepted anything? (Assume accepted ID = IDa)
• YES: Reply with PROMISE IDp accepted IDa, VALUE
• NO: Reply with PROMISE IDp
Paxos – Multiple Proposers
PREPARE 150
Proposer Proposer
PROMISE 150,
accepted 100,
Acceptor "Dinner"
Acceptor
Acceptor
ACCEPT 100, "Dinner"
• Leader Election
• Multi-Paxos
Paxos – Message Exchanges
PREPARE 100 ACCEPT-REQUEST 100, "Dinner"
Proposer
Learner
Acceptor
Acceptor
Acceptor
PROMISE 100 ACCEPT 100, "Dinner"
Proposer 2
Acceptor 1
Acceptor 2
Acceptor 3
Majority Voting
Proposer 1
PREPARE 100
Proposer 2
Acceptor 1
PROMISE 100
Acceptor 2
Acceptor 3
Majority Voting
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100
Acceptor 2
Acceptor 3
Majority Voting
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100
Acceptor 2
PROMISE 100
Acceptor 3
Majority Voting
If the majority of the acceptors
PREPARE 100
Proposer 1 promised on ID100, ID50 cannot
PREPARE 50 get through (those acceptors will
Proposer 2
ignore)
Acceptor 1
PROMISE 100
Acceptor 2
PROMISE 100
Acceptor 3
Majority Voting
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 ignore
Acceptor 3
Majority Voting
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 ignore
Acceptor 3
Majority Voting
Proposer 1
PREPARE 100 Not a majority
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 ignore
Acceptor 3
PROMISE 50
Majority Voting
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 ignore
Acceptor 3
PROMISE 50 PROMISE 100
Majority Voting – Case 2
Proposer 1
PREPARE 100
Proposer 2
Acceptor 1
PROMISE 100
Acceptor 2
Acceptor 3
Majority Voting – Case 2
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
Acceptor 3
Majority Voting – Case 2
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 50
Acceptor 3
Majority Voting – Case 2
PREPARE 100 Becomes the
Proposer 1
majority
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 50
Acceptor 3
PROMISE 50
Majority Voting – Case 2
Proposer 1
PREPARE 100
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 50
Acceptor 3
PROMISE 50
Majority Voting – Case 2
Proposer 1
PREPARE 100
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 50 PROMISE 100
Acceptor 3
PROMISE 50
Majority Voting – Case 2
Proposer 1
PREPARE 100
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 50 PROMISE 100
Acceptor 3
PROMISE 50 PROMISE 100
Majority Voting – Case 2
Proposer 1
PREPARE 100
Acceptor 1
PROMISE 100 ignore ignore
ignore
Acceptor 2
PROMISE 50 PROMISE 100 ignore
Acceptor 3
PROMISE 50 PROMISE 100
Majority Voting – Case 2 100 Becomes the
majority
Proposer 1
PREPARE 100
Acceptor 1
PROMISE 100 ignore ignore
ignore
Acceptor 2
PROMISE 50 PROMISE 100 ignore
Acceptor 3
PROMISE 50 PROMISE 100
Liveness
Proposer 1
PREPARE 100
Proposer 2
Acceptor 1
Acceptor 2
Acceptor 3
Liveness
Proposer 1
PREPARE 100
Proposer 2
Acceptor 1
PROMISE 100
Acceptor 2
PROMISE 100
Acceptor 3
Liveness
Proposer 1
PREPARE 100
PREPARE 150
Proposer 2
Acceptor 1
PROMISE 100
Acceptor 2
PROMISE 100
Acceptor 3
Liveness
Proposer 1
PREPARE 100
PREPARE 150
Proposer 2
Acceptor 1
PROMISE 100 PROMISE 150
Acceptor 2
PROMISE 100 PROMISE 150
Acceptor 3
Liveness
PREPARE 100 ACCEPT-REQUEST 100, "Dinner"
Proposer 1
PREPARE 150
Proposer 2
Acceptor 1
PROMISE 100 PROMISE 150
Acceptor 2
PROMISE 100 PROMISE 150
Acceptor 3
Liveness
PREPARE 100 ACCEPT-REQUEST 100, "Dinner"
Proposer 1
PREPARE 150
Proposer 2
ignore
Acceptor 1
PROMISE 100 PROMISE 150
ignore
Acceptor 2
PROMISE 100 PROMISE 150
Acceptor 3
Liveness
PREPARE 100 ACCEPT-REQUEST 100, "Dinner" PREPARE 200
Proposer 1
PREPARE 150
Proposer 2
ignore
Acceptor 1
PROMISE 100 PROMISE 150
ignore
Acceptor 2
PROMISE 100 PROMISE 150
Acceptor 3
Liveness
PREPARE 100 ACCEPT-REQUEST 100, "Dinner" PREPARE 200
Proposer 1
PREPARE 150
Proposer 2
ignore
Acceptor 1
PROMISE 100 PROMISE 150 PROMISE 200
ignore
Acceptor 2
PROMISE 100 PROMISE 150 PROMISE 200
Acceptor 3
Liveness
PREPARE 100 ACCEPT-REQUEST 100, "Dinner" PREPARE 200
Proposer 1 There is no termination guarantee
PREPARE 150 on Paxos
Proposer 2
ignore
Acceptor 1
PROMISE 100 PROMISE 150 PROMISE 200
ignore
Acceptor 2
PROMISE 100 PROMISE 150 PROMISE 200
Acceptor 3
Majority of Accepts
• Majority of acceptors accept a request with an ID and a
value
• Consensus has been reached
• The consensus is on the value
Acceptor
Acceptor
Acceptor
PROMISE 100 ACCEPT 100, "Leader"
Multi-Paxos
• Applications often needs a continuous stream of agreed
values
• Commit the transactions in a replicated database – each
transaction needs a consensus to be agreed upon by the
replicas
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 PROMISE 50
Acceptor 3
Blockchain and its applications
Prof. Sandip Chakraborty
• BFT Agreement
Malicious Behavior on Paxos
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 PROMISE 50
Acceptor 3
Malicious Behavior on Paxos
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 PROMISE 50
Acceptor 3
PROMISE 50
Malicious Behavior on100Paxos
is the
majority
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 PROMISE 50
Acceptor 3
PROMISE 50
Malicious Behavior on100Paxos
is the
majority
50 is the
Proposer 1
PREPARE 100 majority
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 PROMISE 50
Acceptor 3
PROMISE 50
Malicious Behavior on Paxos
Proposer 1
A-R 100, "Dinner"
Acceptor 1
ACCEPT 100, ignore
"Dinner"
Acceptor 2
ACCEPT 100, ACCEPT 50,
"Dinner" "Movie"
Acceptor 3
ACCEPT 50,
"Movie"
We agreed
Malicious Behavior on Paxos
for Dinner
Proposer 1
A-R 100, "Dinner"
Acceptor 1
ACCEPT 100, ignore
"Dinner"
Acceptor 2
ACCEPT 100, ACCEPT 50,
"Dinner" "Movie"
Acceptor 3
ACCEPT 50,
"Movie"
We agreed
Malicious Behavior on Paxos
for Dinner No, we
A-R 100, "Dinner" agreed for
Proposer 1
Movie
A-R 50, "Movie"
Proposer 2
Lieutenant - 1
Commander
Lieutenant - 2
Byzantine Generals Problem
Attack
Lieutenant - 1
Commander
Lieutenant - 2
Attack
Byzantine Generals Problem
Faulty Attack
Commander
Lieutenant - 1
Commander
Lieutenant - 2
Retreat
Byzantine Generals Problem We need a consensus
mechanism to decide
who is faulty
Faulty Attack
Commander
Lieutenant - 1
Commander
Lieutenant - 2
Retreat
Byzantine Generals Problem
Faulty Attack
Commander
Lieutenant - 1
Attack
Commander
Lieutenant - 2
Retreat
Byzantine Generals Problem
Faulty Attack
Commander
Lieutenant - 1
Attack Retreat
Commander
Lieutenant - 2
Retreat
Byzantine Generals Problem
Can we reach
consensus?
Faulty Attack
Commander
Lieutenant - 1
Attack Retreat
Commander
Lieutenant - 2
Retreat
Byzantine Generals Problem
Good Attack
Commander
Lieutenant - 1
Commander
Attack Lieutenant - 2
Byzantine Generals Problem
Good Attack
Commander
Lieutenant - 1
Attack Retreat
Commander
Attack Lieutenant - 2
Faulty
Lieutenant
Byzantine Generals Problem
Good Attack
Commander
Lieutenant - 1
Consensus is NOT POSSIBLE with one
commander and two lieutenants,
when one is faulty Attack Retreat
Commander
Attack Lieutenant - 2
Faulty
Lieutenant
Byzantine Generals Problem – Case 2
Faulty
Commander Attack
Attack
Retreat
Byzantine Generals Problem – Case 2
Faulty
Commander Attack
Attack
Retreat
Retreat
Retreat
Byzantine Generals Problem – Case 2
Faulty
Commander Attack
Attack Attack
Attack
Retreat
Attack
Retreat
Retreat
Attack
Byzantine Generals Problem – Case 2
Faulty Attack: 2
Commander Attack Retreat: 1
Attack Attack
Attack
Retreat
Attack
Retreat
Retreat
Attack: 2 Attack: 2
Attack
Retreat: 1 Retreat: 1
Byzantine Generals Problem – Case 2
Faulty Attack: 2
Commander Attack Retreat: 1
Attack Attack
Consensus is reached !Attack
Retreat
Attack
Retreat
Retreat
Attack: 2 Attack: 2
Attack
Retreat: 1 Retreat: 1
Byzantine Generals Problem – Case 2
Good
Commander Attack
Attack
Attack
Byzantine Generals Problem – Case 2
Good
Commander Attack
Attack
Attack
Retreat
Faulty Attack
Lieutenant
Byzantine Generals Problem – Case 2
Good
Commander Attack
Attack Attack
Attack
Attack
Attack
Retreat
Faulty
Commander
Attack
Attack
Byzantine Generals Problem – Case 2
Good Attack: 2
Commander Attack Retreat: 1
Attack Attack
Attack
Attack
Attack
Retreat
Faulty
Commander
Attack
Attack: 3 Attack: 3
Attack
Retreat: 0 Retreat: 0
Byzantine Generals Problem – Case 2
Good Attack: 2
Commander Attack Retreat: 1
Attack Attack
Consensus is reached !Attack
Attack
Attack
Retreat
Faulty
Commander
Attack
Attack: 3 Attack: 3
Attack
Retreat: 0 Retreat: 0
Asynchronous Byzantine Agreement
• F faulty nodes – need 3F + 1 nodes to reach consensus
Asynchronous Byzantine Agreement
• F faulty nodes – need 3F + 1 nodes to reach consensus
• Faulty nodes create partition in the network
Asynchronous Byzantine Agreement
• F faulty nodes – need 3F + 1 nodes to reach consensus
• Faulty nodes create partition in the network
3F
Asynchronous Byzantine Agreement
• F faulty nodes – need 3F + 1 nodes to reach consensus
• Faulty nodes create partition in the network
F F F
Asynchronous Byzantine Agreement
• F faulty nodes – need 3F + 1 nodes to reach consensus
• Faulty nodes create partition in the network
F F F
PL PF PR
Asynchronous Byzantine Agreement
• F faulty nodes – need 3F + 1 nodes to reach consensus
• Faulty nodes create partition in the network
F F F
0 1
0 1
PL PF PR
Asynchronous Byzantine Agreement
Either PL or PR
• F faulty nodes – need 3F + 1 nodes to reach consensus must break the
• Faulty nodes create partition in the network tie
F F F
0 1
0 1
PL PF PR
Asynchronous Byzantine Agreement
Put
• F faulty nodes – need 3F + 1 nodes to reach consensus one additional
• Faulty nodes create partition in the network node to PL / PR
F F F
0 1
0 1
PL PF PR
Asynchronous Byzantine Agreement
Put
• F faulty nodes – need 3F + 1 nodes to reach consensus one additional
• Faulty nodes create partition in the network node to PL / PR
F+1 F F
0 1
Breaks the
tie to
reach 0 1
consensus
PL PF PR
Conclusion
• Paxos does not work with Byzantine faults
• Much harder to solve than crash faults