A friendly, visual introduction to various consensus algorithms. Given at Crypto Springs, a generalist blockchain conference.
Tess Rinearson, @_tessr© Interstellar Inc. 2018all together now:an introduction todistributed consensus
View Slide
© Interstellar Inc. 2018 2
© Interstellar Inc. 2018 3xxxxxGOAL: Consistency acrossall nodes
© Interstellar Inc. 2018 4
© Interstellar Inc. 2018 4x?x?x?x?
© Interstellar Inc. 2018 5
© Interstellar Inc. 2018 5ok ✔ok ✔ok ✔ok ✔
© Interstellar Inc. 2018 5ok ✔ok ✔ok ✔ok ✔x
© Interstellar Inc. 2018 5ok ✔ok ✔ok ✔ok ✔xxxxx
An Introduction to Distributed Consensus© Interstellar Inc. 2018 6this works, but italso sucks!
© Interstellar Inc. 2018 7why does thisnode get tosuggest a value?what if this onewants to suggesta value?or this one?
© Interstellar Inc. 2018 8what if there’s a network partition?
© Interstellar Inc. 2018 9what if we have A LOT of nodes???
© Interstellar Inc. 2018 10what if one of the nodes goes offline?
© Interstellar Inc. 2018An Introduction to Distributed Consensusalso a lot of other problems thatcomputer scientists get excited about(clock skew!!!)11
An Introduction to Distributed Consensus© Interstellar Inc. 2018 12solution: Paxos
An Introduction to Distributed Consensus© Interstellar Inc. 2018 13no one actuallyunderstands Paxos
© Interstellar Inc. 2018An Introduction to Distributed Consensus“We found few people who were comfortable with Paxos,even among seasoned researchers. We… were not ableto understand the complete protocol until after readingseveral simplified explanations and designing our ownalternative protocol, a process that took almost a year.”(from the Raft paper)14
© Interstellar Inc. 2018An Introduction to Distributed Consensus15•a lot of behavior isunspecified•the variants that make itmore complete can be verycomplexthe trouble withPaxos
An Introduction to Distributed Consensus© Interstellar Inc. 2018 16you can understand(basic) Paxos
© Interstellar Inc. 2018An Introduction to Distributed Consensus17Naive Solution•proposer node sends new valueto every other node in thesystemPaxos•proposer node sends outballots that other nodes canvote on•each round of consensusrequires two rounds of voting
© Interstellar Inc. 2018An Introduction to Distributed Consensus18value: ?prepared: naccepted: n
© Interstellar Inc. 2018 19Step 1: Prepare the ballotnumber nʹvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: n
© Interstellar Inc. 2018 19prepare(nʹ)prepare(nʹ)prepare(nʹ)prepare(nʹ)Step 1: Prepare the ballotnumber nʹprepare(nʹ)value:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: n
© Interstellar Inc. 2018 20Step 2: Acknowledge ballotvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: n
© Interstellar Inc. 2018 20ack(nʹ, n)ack(nʹ, n)ack(nʹ, n)ack(nʹ, n)Step 2: Acknowledge ballotack(nʹ, n)value:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: n
© Interstellar Inc. 2018 21I have received acksfrom 5/5 nodesStep 3a: Count acksvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: n
© Interstellar Inc. 2018 22Step 3b: Tell nodes toaccept the valuevalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: n
© Interstellar Inc. 2018 22accept(nʹ, x)accept(nʹ, x)accept(nʹ, x)accept(nʹ, x)Step 3b: Tell nodes toaccept the valueaccept(nʹ, x)value:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: n
© Interstellar Inc. 2018 23Step 4: Nodes adopt thevaluevalue: xprepared: nʹaccepted: nʹvalue: xprepared: nʹaccepted: nʹvalue: xprepared: nʹaccepted: nʹvalue: xprepared: nʹaccepted: nʹvalue: xprepared: nʹaccepted: nʹ
© Interstellar Inc. 2018An Introduction to Distributed Consensuswhat if a node goes offline?24
© Interstellar Inc. 2018 25Step 1: Prepare the ballotnumber nʹvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: n
© Interstellar Inc. 2018 25prepare(nʹ)prepare(nʹ)prepare(nʹ)prepare(nʹ)Step 1: Prepare the ballotnumber nʹprepare(nʹ)value:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: n
© Interstellar Inc. 2018 25prepare(nʹ)prepare(nʹ)prepare(nʹ)prepare(nʹ)Step 1: Prepare the ballotnumber nʹprepare(nʹ)value:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: n
© Interstellar Inc. 2018 26Step 2: Acknowledge ballotvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: n
© Interstellar Inc. 2018 26ack(nʹ, n)ack(nʹ, n)ack(nʹ, n)Step 2: Acknowledge ballotack(nʹ, n)value:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: n
© Interstellar Inc. 2018 27I have received acksfrom 4/5 nodesStep 3a: Count acksvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: n
© Interstellar Inc. 2018An Introduction to Distributed Consensuswe received acks from a majority ofnodes, so we can proceed28
© Interstellar Inc. 2018An Introduction to Distributed Consensuswhat if two nodes propose values atthe same time?29
© Interstellar Inc. 2018 30Step 1: Prepare the ballotnumber nʹvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: n
© Interstellar Inc. 2018 30prepare(nʹ)prepare(nʹ)prepare(nʹ)prepare(nʹ)Step 1: Prepare the ballotnumber nʹprepare(nʹ)value:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: nvalue:prepared: naccepted: n
© Interstellar Inc. 2018 31Step 2: Acknowledge ballotvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: n
© Interstellar Inc. 2018 31ack(nʹ, n)ack(nʹ, n)ack(nʹ, n)Step 2: Acknowledge ballotack(nʹ, n)value:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: n
© Interstellar Inc. 2018 32I have received acksfrom 4/5 nodesStep 3a: Count acksvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nI have received acks from1/5 nodes, so I must stop
© Interstellar Inc. 2018 33Step 3b: Tell nodes toaccept the valuevalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: n
© Interstellar Inc. 2018 33accept(nʹ, x)accept(nʹ, x)accept(nʹ, x)accept(nʹ, x)Step 3b: Tell nodes toaccept the valueaccept(nʹ, x)value:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: nvalue:prepared: nʹaccepted: n
© Interstellar Inc. 2018 34Step 4: Nodes adopt thevaluevalue: xprepared: nʹaccepted: nʹvalue: xprepared: nʹaccepted: nʹvalue: xprepared: nʹaccepted: nʹvalue: xprepared: nʹaccepted: nʹvalue: xprepared: nʹaccepted: nʹ
© Interstellar Inc. 2018An Introduction to Distributed Consensuswe maintained consistency across allthe nodes35
© Interstellar Inc. 2018ConsensusPaxos Raft
© Interstellar Inc. 2018An Introduction to Distributed Consensuseveryone was following the rules:these are non-Byzantine failures37
An Introduction to Distributed Consensus© Interstellar Inc. 2018 38the Byzantine Generals
© Interstellar Inc. 2018An Introduction to Distributed Consensus39
© Interstellar Inc. 2018An Introduction to Distributed Consensus39“attack”“attack”also, don’t attack
© Interstellar Inc. 2018An Introduction to Distributed Consensus40prepare(n)prepare(n+100000)
© Interstellar Inc. 2018An Introduction to Distributed Consensus40prepare(n)prepare(n+100000)help I’m stuck
An Introduction to Distributed Consensus© Interstellar Inc. 2018 41how can a systemtolerate Byzantinefaults?
An Introduction to Distributed Consensus© Interstellar Inc. 2018 42solution: PBFT
© Interstellar Inc. 2018An Introduction to Distributed Consensus43requestpre-preparepreparecommitreply
An Introduction to Distributed Consensus© Interstellar Inc. 2018 44
© Interstellar Inc. 2018ConsensusPaxos RaftByzantine-safePBFT
© Interstellar Inc. 2018An Introduction to Distributed ConsensusPBFT keeps working even if 1/3 ofthe nodes are malicious46
An Introduction to Distributed Consensus© Interstellar Inc. 2018 47problem: Sybil attacks
© Interstellar Inc. 2018An Introduction to Distributed Consensusclassic PBFT requires you to vetyour member set(no good for public networks!)48
© Interstellar Inc. 2018ConsensusPaxos RaftByzantine-safePBFTSybil-safe
An Introduction to Distributed Consensus© Interstellar Inc. 2018 50what about proof ofwork?
© Interstellar Inc. 2018 51nonce: 123hash: fa6cnonce: 9a4hash: 002anonce: a19hash: 8e43nonce: 89hash: 9876nonce: abchash: 89a0
nonce: 123hash: fa6cnonce: 9a4hash: 002anonce: a19hash: 8e43nonce: 89hash: 9876nonce: abchash: 89a0* in Bitcoin, nodes gossip; not every node is connected to every other node
nonce: 123hash: fa6cnonce: 9a4hash: 002anonce: a19hash: 8e43nonce: 89hash: 9876nonce: abchash: 89a0block, hashblock, hashblock, hashblock, hash* in Bitcoin, nodes gossip; not every node is connected to every other node
© Interstellar Inc. 2018An Introduction to Distributed Consensus53•multiple nodes can proposeblocks simultaneously•longest* chain is the valid one• nodes are incentivized tochoose the most-work chain,so they’ll eventually convergeProof of Work
© Interstellar Inc. 2018ConsensusPaxos RaftByzantine-safePBFTSybil-safeProof of Work
© Interstellar Inc. 2018An Introduction to Distributed Consensus55•tricks like ASICs(application-specificintegrated circuits, specialhardware) can make it lessfair•boils the oceanthe trouble withProof of Work
© Interstellar Inc. 2018ConsensusPaxos RaftByzantine-safePBFTSybil-safeDoesn’t boil the oceanProof of Work
© Interstellar Inc. 2018ConsensusPaxos RaftByzantine-safePBFTSybil-safeDoesn’t boil the oceanProof of WorkProof of Stake
© Interstellar Inc. 2018An Introduction to Distributed Consensus59•probabilities are tied toamount staked• either amount held or a“security deposit”Proof of Stake
© Interstellar Inc. 2018An Introduction to Distributed Consensushow can we know if a nodemisbehaved?60
© Interstellar Inc. 2018An Introduction to Distributed Consensuswhat if we let the othernodes vote on it?61…sounds like PBFT
An Introduction to Distributed Consensus© Interstellar Inc. 2018 62Tendermint
© Interstellar Inc. 2018An Introduction to Distributed Consensus63• PBFT is vulnerable to Sybilattacks• gate membership throughProof of Stake•slash collateral for badbehaviorTendermint
© Interstellar Inc. 2018An Introduction to Distributed Consensusin proof of stake,resources = control64
© Interstellar Inc. 2018ConsensusPaxos RaftByzantine-safePBFTSybil-safeDoesn’t boil the oceanNon-kleptocraticProof of WorkProof of Stake
An Introduction to Distributed Consensus© Interstellar Inc. 2018 66federated consensus
© Interstellar Inc. 2018ConsensusPaxos RaftByzantine-safePBFTSybil-safeTrust no oneDoesn’t boil the oceanNon-kleptocraticProof of WorkProof of Stake
An Introduction to Distributed Consensus© Interstellar Inc. 2018 68the StellarConsensus Protocol(SCP)
© Interstellar Inc. 2018 69AI trust A to issue tokens,stay solvent, redeemtokens, and validatetheir transactions
ps://thenextweb.com/insider/2015/02/16/ways-people-described-computers-1990s-hilarious/
© Interstellar Inc. 2018 71A BI trust AI trust AI trust BI trust A and B
© Interstellar Inc. 2018 72A BI trust AI trust AI trust BI trust A and B
© Interstellar Inc. 2018 72A Bok ✔ok ✔ok ✔I trust AI trust AI trust BI trust A and B
© Interstellar Inc. 2018 73A Bok ✔ok ✔ok ✔I trust AI trust AI trust BI trust A and B
© Interstellar Inc. 2018 73A Bok ✔ok ✔ok ✔ ok ✔I trust AI trust AI trust BI trust A and B
© Interstellar Inc. 2018ConsensusPaxos RaftByzantine-safePBFTSybil-safeTrust no oneDoesn’t boil the oceanNon-kleptocraticProof of WorkProof of StakeSCP
© Interstellar Inc. 2018 75ConsistencyAvailabilityPartitionTolerance
© Interstellar Inc. 2018 76EfficiencyFairnessMinimizedTrustFederated Consensus (SCP)Proof of WorkProof of Stake
© Interstellar Inc. 2018An Introduction to Distributed Consensus•Get in touch: @_tessr or[email protected]•Thank you to Peter Bourgon andJeremy Rubin for their help withthis talkthanks!77
© Interstellar Inc. 2018An Introduction to Distributed Consensus•Paxos: http://www.cs.yale.edu/homes/aspnes/pinewiki/Paxos.html•Leslie Lamport on Paxos: https://lamport.azurewebsites.net/pubs/pubs.html#lamport-paxos•In Search of an Understandable Consensus Algorithm (Raft): https://raft.github.io/raft.pdf•The Morning Paper: Practical Byzantine Fault Tolerance: https://blog.acolyer.org/2015/05/18/practical-byzantine-fault-tolerance•On the Practicality of ‘Practical’ Byzantine Fault Tolerance: https://arxiv.org/abs/1110.4854v1•Ethereum Proof of Stake FAQ: https://github.com/ethereum/wiki/wiki/Proof-of-Stake-FAQs•Consensus Compare: Casper vs. Tendermint: https://blog.cosmos.network/consensus-compare-casper-vs-tendermint-6df154ad56ae•Tendermint Consensus Overview: https://tendermint.com/docs/introduction/introduction.html#consensus-overview•The Stellar Consensus Protocol: A Federated Model for Internet-level Consensus: https://www.stellar.org/papers/stellar-consensus-protocol.pdf•Monty Python picture from https://welovebudapest.com/en/event/gyalog-galopp/•Mr. Jones picture from https://www.amazon.com/Indiana-Jones-Complete-Adventure-Collection/dp/B001E75QH0references & further reading78