Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Consensus is for Everyone: An Introduction

Tess Rinearson
November 07, 2019
45

Consensus is for Everyone: An Introduction

The 2019 version of my introduction to consensus algorithms, geared more towards generalist programmers.

Tess Rinearson

November 07, 2019
Tweet

Transcript

  1. 5

  2. 7

  3. 8

  4. 10 why does this node get to suggest a value?

    what if this one wants to suggest a value? or this one?
  5. Consensus is for Everyone: An Introduction to Distributed Consensus also

    a lot of other problems that computer scientists get excited about (clock skew!!!) 14
  6. Consensus is for Everyone: An Introduction to Distributed Consensus every

    node must decide on a value the value must be the same for every node that value must be produced by some process 16
  7. Consensus is for Everyone: An Introduction to Distributed Consensus every

    node must decide on a value the value must be the same for every node that value must be produced by some process 16 termination
  8. Consensus is for Everyone: An Introduction to Distributed Consensus every

    node must decide on a value the value must be the same for every node that value must be produced by some process 16 termination agreement
  9. Consensus is for Everyone: An Introduction to Distributed Consensus every

    node must decide on a value the value must be the same for every node that value must be produced by some process 16 termination agreement validity
  10. Consensus is for Everyone: An Introduction to Distributed Consensus “We

    found few people who were comfortable with Paxos, even among seasoned researchers. We… were not able to understand the complete protocol until after reading several simplified explanations and designing our own alternative protocol, a process that took almost a year.” (from the Raft paper) 19
  11. Consensus is for Everyone: An Introduction to Distributed Consensus 20

    • a lot of behavior is unspecified • the variants that make it more complete can be very complex the trouble with Paxos
  12. Consensus is for Everyone: An Introduction to Distributed Consensus 22

    Naive Solution • proposer node sends new value to every other node in the system Paxos • proposer node sends out ballots that other nodes can vote on • each round of consensus requires two rounds of voting
  13. 24 Step 1: Prepare the ballot number nʹ value: prepared:

    n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n
  14. 24 prepare(nʹ) prepare(nʹ) prepare(nʹ) prepare(nʹ) Step 1: Prepare the ballot

    number nʹ prepare(nʹ) value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n
  15. 25 Step 2: Acknowledge ballot value: prepared: nʹ accepted: n

    value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n
  16. 25 ack(nʹ, n) ack(nʹ, n) ack(nʹ, n) ack(nʹ, n) Step

    2: Acknowledge ballot ack(nʹ, n) value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n
  17. 26 I have received acks from 5/5 nodes Step 3a:

    Count acks value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n
  18. 27 Step 3b: Tell nodes to accept the value value:

    prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n
  19. 27 accept(nʹ, x) accept(nʹ, x) accept(nʹ, x) accept(nʹ, x) Step

    3b: Tell nodes to accept the value accept(nʹ, x) value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n
  20. 28 Step 4: Nodes adopt the value value: x prepared:

    nʹ accepted: nʹ value: x prepared: nʹ accepted: nʹ value: x prepared: nʹ accepted: nʹ value: x prepared: nʹ accepted: nʹ value: x prepared: nʹ accepted: nʹ
  21. 30 Step 1: Prepare the ballot number nʹ value: prepared:

    n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n
  22. 30 prepare(nʹ) prepare(nʹ) prepare(nʹ) prepare(nʹ) Step 1: Prepare the ballot

    number nʹ prepare(nʹ) value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n
  23. 30 prepare(nʹ) prepare(nʹ) prepare(nʹ) prepare(nʹ) Step 1: Prepare the ballot

    number nʹ prepare(nʹ) value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n
  24. 31 Step 2: Acknowledge ballot value: prepared: nʹ accepted: n

    value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n
  25. 31 ack(nʹ, n) ack(nʹ, n) ack(nʹ, n) Step 2: Acknowledge

    ballot ack(nʹ, n) value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n
  26. 32 I have received acks from 4/5 nodes Step 3a:

    Count acks value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n value: prepared: nʹ accepted: n
  27. Consensus is for Everyone: An Introduction to Distributed Consensus we

    received acks from a majority of nodes, so we can proceed 33
  28. Consensus is for Everyone: An Introduction to Distributed Consensus what

    if two nodes propose values at the same time? 34
  29. 35 Step 1: Prepare the ballot number nʹ value: prepared:

    n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n
  30. 35 prepare(nʹ) prepare(nʹ) prepare(nʹ) prepare(nʹ) Step 1: Prepare the ballot

    number nʹ prepare(nʹ) value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n
  31. Consensus is for Everyone: An Introduction to Distributed Consensus 36

    A I’m Proposer A, so my ballot are numbered with <n, a> B I’m Proposer B, so my ballot are numbered with <n, b>
  32. 37 Step 1: Prepare the ballot number nʹ value: prepared:

    n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n B A
  33. 37 prepare(<nʹ, a>) Step 1: Prepare the ballot number nʹ

    prepare(<nʹ, b>) value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n value: prepared: n accepted: n B A
  34. 38 Step 2: Acknowledge ballot value: prepared: nʹ,b accepted: n

    value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n B A
  35. 38 ack(<nʹ, b>,n) ack(<nʹ,b>, n) ack(<nʹ,b>, n) Step 2: Acknowledge

    ballot ack(<nʹ,b>, n) value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n B A ack(<nʹ,b>, n)
  36. 39 I have received acks from 5/5 nodes Step 3a:

    Count acks value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n I have received acks from 0/5 nodes, so I must stop value: prepared: nʹ,b accepted: n
  37. 40 Step 3b: Tell nodes to accept the value value:

    prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n
  38. 40 accept(<nʹ,b> x) accept(<nʹ,b>, x) accept(<nʹ,b>, x) accept(<nʹ,b>, x) Step

    3b: Tell nodes to accept the value accept(<nʹ,b>, x) value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n value: prepared: nʹ,b accepted: n
  39. 41 Step 4: Nodes adopt the value value: x prepared:

    nʹ,b accepted: nʹ,b value: x prepared: nʹ,b accepted: nʹ,b value: x prepared: nʹ,b accepted: nʹ,b value: x prepared: nʹ,b accepted: nʹ,b value: x prepared: nʹ,b accepted: nʹ,b
  40. Consensus is for Everyone: An Introduction to Distributed Consensus we

    maintained consistency across all the nodes 42
  41. 45 I want the next value to be x, so

    I’ll tell the leader.
  42. 45 I want the next value to be x, so

    I’ll tell the leader. “please adopt x”
  43. 47

  44. 53 A Replicated Log value: x term: 1 index: 1

    value: y term: 1 index: 2 value: z term: 2 index: 3 value: a term: 3 index: 4 represents the period between each election the position of this entry within the log this is an entry
  45. Consensus is for Everyone: An Introduction to Distributed Consensus 54

    • If two entries in different logs have the same index and term, then they store the same command. • If two entries in different logs have the same index and term, then the logs are identical in all preceding entries. the Log-Matching Property
  46. 55 term: 1 index: 2 term: 1 index: 1 term:

    1 index: 3 term: 1 index: 2 term: 1 index: 1
  47. 55 term: 1 index: 2 term: 1 index: 1 term:

    1 index: 3 term: 1 index: 2 term: 1 index: 1 I’d like to append to the log. My most recent entry has term 1 and index 3.
  48. 55 term: 1 index: 2 term: 1 index: 1 term:

    1 index: 3 term: 1 index: 2 term: 1 index: 1 I’d like to append to the log. My most recent entry has term 1 and index 3. Uh oh, I’m missing that entry. Can you replay your log from after index 2?
  49. Consensus is for Everyone: An Introduction to Distributed Consensus everyone

    was following the rules: these are non-Byzantine failures 57
  50. Consensus is for Everyone: An Introduction to Distributed Consensus 59

    “attack” “attack” also, don’t attack
  51. Consensus is for Everyone: An Introduction to Distributed Consensus PBFT

    keeps working even if 1/3 of the nodes are malicious 65
  52. Consensus is for Everyone: An Introduction to Distributed Consensus classic

    PBFT requires you to vet your member set (no good for public networks!) 67
  53. 72 nonce: 123 hash: fa6c nonce: 9a4 hash: 002a nonce:

    a19 hash: 8e43 nonce: 89 hash: 9876 nonce: abc hash: 89a0
  54. nonce: 123 hash: fa6c nonce: 9a4 hash: 002a nonce: a19

    hash: 8e43 nonce: 89 hash: 9876 nonce: abc hash: 89a0 * in Bitcoin, nodes gossip; not every node is connected to every other node
  55. nonce: 123 hash: fa6c nonce: 9a4 hash: 002a nonce: a19

    hash: 8e43 nonce: 89 hash: 9876 nonce: abc hash: 89a0 block, hash block, hash block, hash block, hash * in Bitcoin, nodes gossip; not every node is connected to every other node
  56. 74 nonce: 123 hash: fa6c nonce: 9a4 hash: 002a nonce:

    89 hash: 9876 nonce: abc hash: 89a0 block, hash block, hash block, hash block, hash nonce: a19 hash: 8e43
  57. 74 nonce: 123 hash: fa6c nonce: 9a4 hash: 002a nonce:

    89 hash: 9876 nonce: abc hash: 89a0 block, hash block, hash block, hash block, hash LGTM ✔ LGTM ✔ nonce: a19 hash: 8e43 LGTM ✔ LGTM ✔
  58. Consensus is for Everyone: An Introduction to Distributed Consensus every

    node must decide on a value the value must be the same for every node that value must be produced by some process 76 termination agreement validity Reminder
  59. nonce: 123 hash: fa6c nonce: 9a4 hash: 002a nonce: bc8

    hash: 0011 nonce: 89 hash: 9876 nonce: abc hash: 89a0
  60. nonce: 123 hash: fa6c nonce: 9a4 hash: 002a nonce: bc8

    hash: 0011 nonce: 89 hash: 9876 nonce: abc hash: 89a0
  61. 78 nonce: 9a4 hash: 002a nonce: bc8 hash: 0011 nonce:

    f6e hash: 0002 nonce: 092 hash: 0013 A Blockchain, with a fork
  62. 79 nonce: 9a4 hash: 002a nonce: f6e hash: 0002 nonce:

    092 hash: 0013 nonce: bc8 hash: 0011 A Blockchain, with a fork
  63. 79 nonce: 9a4 hash: 002a nonce: f6e hash: 0002 nonce:

    092 hash: 0013 nonce: bc8 hash: 0011 nonce: 9bb hash: 0020 A Blockchain, with a fork
  64. 79 nonce: 9a4 hash: 002a nonce: f6e hash: 0002 nonce:

    092 hash: 0013 nonce: 9bb hash: 0020 A Blockchain, with a fork
  65. Consensus is for Everyone: An Introduction to Distributed Consensus 80

    • accidental forks • tricks like ASICs (application-specific integrated circuits, special hardware) can make it less fair • boils the ocean the trouble with Proof of Work
  66. Consensus is for Everyone: An Introduction to Distributed Consensus 89

    • How do nodes choose their personal quorums? • What should a node do if one of its trusted peers misbehaves? Out-of-band questions
  67. Consensus is for Everyone: An Introduction to Distributed Consensus 93

    • probabilities are tied to amount staked • either amount held or a “security deposit” • nodes exhibiting Byzantine behavior will be “slashed” Proof of Stake
  68. Consensus Paxos Raft Byzantine-safe PBFT Sybil-safe Trust no one Doesn’t

    boil the ocean Proof of Work Proof of Stake Fed. Con.
  69. Consensus is for Everyone: An Introduction to Distributed Consensus what

    if we let the other nodes vote on it? 96 …sounds like PBFT
  70. Consensus is for Everyone: An Introduction to Distributed Consensus what

    if we let the other nodes vote on it? 96 …sounds like PBFT
  71. Consensus is for Everyone: An Introduction to Distributed Consensus 99

    new height propose prevote nil prevote block invalid block valid block wait for prevotes from +2/3 precommit block precommit nil +2/3 2/3 wait for precommits from +2/3 commit new round 2/3 +2/3
  72. Consensus Paxos Raft Byzantine-safe PBFT Sybil-safe Trust no one Doesn’t

    boil the ocean Proof of Work Proof of Stake Fed. Con.
  73. Consensus Paxos Raft Byzantine-safe PBFT Sybil-safe Trust no one Doesn’t

    boil the ocean Non-kleptocratic Proof of Work Proof of Stake Fed. Con.
  74. Consensus is for Everyone: An Introduction to Distributed Consensus •

    Get in touch: @_tessr or [email protected] • Please don’t forget to rate this session • Thank you to Peter Bourgon, Jeremy Rubin and Peter Alvaro for their help with this talk thanks! 106
  75. Consensus is for Everyone: An 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 • A Brief Tour of FLP Impossibility (Henry Robinson): https://www.the-paper-trail.org/post/2008-08-13-a-brief-tour- of-flp-impossibility/ • In Search of an Understandable Consensus Algorithm (Raft): https://raft.github.io/raft.pdf • Raft: Consensus made simple(r) (Brian Storti): https://www.brianstorti.com/raft/ • 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 • Mastering Bitcoin (Andreas Antonopolous): https://github.com/bitcoinbook/bitcoinbook/blob/develop/ ch10.asciidoc#forks • Ethereum Proof of Stake FAQ: https://github.com/ethereum/wiki/wiki/Proof-of-Stake-FAQs • Consensus Compare: Casper vs. Tendermint (Chjango Unchained): 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/ references &
 further reading 107