Maps to: CMU 15-440/640 Spring 2026, learning outcomes “fail fast and Byzantine failures” and “fundamental limits of failure resilience”. Reading: L. Lamport, R. Shostak and M. Pease, The Byzantine Generals Problem (ACM TOPLAS 4(3), 1982). Problem set: PS3 asks you to classify failures as fail-fast or Byzantine. This lecture teaches the concepts with different scenarios, and gives no answers. Sources:
- the reading above;
- F. Cristian, Understanding Fault-Tolerant Distributed Systems (CACM 1991);
- R. D. Schlichting and F. B. Schneider, Fail-Stop Processors (ACM TOCS 1983);
- M. J. Fischer, N. A. Lynch and M. S. Paterson, Impossibility of Distributed Consensus with One Faulty Process (JACM 1985);
- C. Dwork, N. Lynch and L. Stockmeyer, Consensus in the Presence of Partial Synchrony (JACM 1988);
- T. D. Chandra and S. Toueg, Unreliable Failure Detectors for Reliable Distributed Systems (JACM 1996);
- N. Hayashibara et al., The φ Accrual Failure Detector (SRDS 2004);
- M. Castro and B. Liskov, Practical Byzantine Fault Tolerance (OSDI 1999).
The slides are not public; this is not a transcript. Every number not attributed to a paper comes from
code/lecture14/, run on the author’s machine (Apple M4 Pro, macOS, Python 3.13 and 3.9). All of it is exhaustive enumeration or seeded simulation. Code:code/lecture14/. Reading time: ~85 minutes, plus ~5 to run the demos.
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- Place a failure in the hierarchy of failure models — crash-stop, crash-recover, omission, timing, Byzantine — and say what each costs to tolerate.
- Explain fail-fast design: how checks, checksums and invariants turn arbitrary (Byzantine) failures into clean stops, and what that costs.
- State the Byzantine generals problem (IC1, IC2), prove informally why three generals cannot tolerate one traitor, and explain the 3m + 1 bound.
- Run Lamport’s OM(m) algorithm by hand, and give its cost in rounds and messages.
- Explain how signed messages (SM(m)) remove the 3m + 1 bound, and what signatures do not provide (synchrony, freshness).
- Treat timeouts as unreliable failure detectors: the trade-off between detection time and false suspicions, and why a crashed process and a slow one cannot be told apart.
- State the FLP impossibility result and the ways practical systems live with it.
0.2 Prerequisites and scope
- Prerequisites:
- Lecture 13: fail-fast modules, process pairs, Heisenbugs;
- Lecture 4: timeouts, at-most-once execution, the end-to-end argument;
- Lecture 1: the two generals, and dsim.
- Scope: what faulty nodes can do, and the fundamental limits of agreement in their presence. Practical consensus for crash failures (Paxos) is Lectures 20–21. Blockchains (agreement without known membership) are Lecture 23. Cryptography and authentication are Lecture 26; here signatures are a black box.
0.3 Section → code map
| Section | Idea | Demo in code/lecture14/ |
|---|---|---|
| §1 | failure models and what clients can do | 01_failure_models.py |
| §2 | fail-fast checks | 02_fail_fast.py |
| §3 | three generals; OM(m) | 03_three_generals.py, 04_oral_messages.py |
| §4 | signed messages SM(m) | 05_signed_messages.py |
| §5 | failure detectors, FLP | 06_failure_detectors.py |
| all | the generals’ algorithms | byzantine.py |
0.4 Notation
- n nodes (generals, replicas); f or m faulty ones (Lamport writes m for traitors).
- A = attack, R = retreat; R is the default used when a message is missing.
- The commander sends an order; the other n − 1 generals are lieutenants.
- IC1: all loyal lieutenants decide the same value. IC2: if the commander is loyal, every loyal lieutenant decides the commander’s order.
- A round is a time slot of known length in which every message sent at its start arrives (synchrony).
1. How do things fail? The hierarchy of failure models
1.1 The intuition
Lecture 13 counted failures. This lecture asks what a failed component does. A disk that stops answering is easy to live with: you notice and use the other copy. A disk that answers with someone else’s data is much worse, because nothing tells you that something is wrong. The difference between these two is the most important distinction in fault tolerance.
A failure model is a contract: it says what a faulty component is allowed to do. The weaker the contract — the more a faulty component may do — the more machinery is needed to tolerate it. Choosing a failure model is therefore an engineering decision. It trades how much we pay against how much of reality the system can survive.
1.2 The hierarchy
Following Cristian (1991) and Schneider, from most benign to least:
| model | what a faulty node may do | example |
|---|---|---|
| crash-stop (fail-stop) | halt, forever; correct until then | a power supply dies |
| crash-recover | halt, then restart with its stable storage but without volatile state | a server reboots after a kernel panic |
| omission | fail to send or receive some messages | an overloaded router drops packets; a full queue |
| timing (performance) | respond, correctly, but outside the specified time | a garbage-collection pause; a swapping server; a clock that drifts |
| Byzantine (arbitrary) | anything: wrong values, inconsistent answers to different nodes, lies about what others said, collusion | silent data corruption; a firmware bug; a compromised machine |
Each class contains the ones above it. A crash is an omission of all later messages; an omission is an infinitely late message; a late message is one particular wrong behaviour. So a protocol that tolerates Byzantine faults also tolerates crashes, but not the other way round.
Schlichting and Schneider’s fail-stop processor is the cleanest model to build on. It halts instead of doing anything wrong. Other processors can detect that it halted. Its stable storage survives the halt. Real hardware is not fail-stop by nature, so §2 is about engineering it to be.
1.3 What a client can do: one faulty replica of three
Demo 01 runs three replicas of a counter service on dsim. Every request goes to all three; one replica, R0, is faulty in each of four ways. The client must decide which replies to believe, and the demo tries four rules (300 requests each; 5 ms of service time, 1–3 ms one-way delay, 40 ms deadline):
| R0’s failure | trust the primary (fail over at the deadline) | first reply | 2 matching replies (f + 1) | vote of all 3 |
|---|---|---|---|---|
| none | 100% ok, 9 ms | 100%, 8 ms | 100%, 9 ms | 100%, 10 ms |
| crash at 0.5 s | 100%, 34 ms | 100%, 8 ms | 100%, 9 ms | 100%, 35 ms |
| omission (30% of replies lost) | 100%, 18 ms | 100%, 8 ms | 100%, 9 ms | 100%, 19 ms |
| timing (replies 55–155 ms late) | 100%, 40 ms | 100%, 8 ms | 100%, 9 ms | 100%, 40 ms |
| Byzantine (instant, wrong) | 0% (all wrong) | 0% (all wrong) | 100%, 9 ms | 100%, 9 ms |
The table divides the failure models into two groups.
- Crash, omission and timing faults cost only time. Any strategy that eventually listens to a correct replica gets the right answer. A strategy that waits for the faulty one pays the deadline: the primary-only client takes 34 ms per request instead of 9 after the crash. A timing fault, seen by a client with a deadline, is just an omission.
- A Byzantine replica costs correctness. It can be the fastest replica, because it does not compute anything. So “first reply” and “trust the primary” were wrong 300 times out of 300. Only voting survives it: wait until f + 1 = 2 replies agree, since at most one can lie. With 2f + 1 = 3 replicas, the f + 1 correct ones always produce a matching pair.
1.4 Voting needs agreement on inputs
Voting has a hidden precondition. Correct replicas give the same answer only if they executed the same requests in the same order. Lecture 1 showed replicas diverging when updates arrive in different orders. Part B of demo 01 repeats this with two clients sending 400 non-commuting operations (“double x”, “add 1 to x”) to three correct replicas:
| how requests are ordered | all 3 replicas agree | a 2-of-3 majority exists |
|---|---|---|
| none: each replica applies them as they arrive | 0.2% of steps | 0.5% |
| a correct orderer assigns sequence numbers | 100% | 100% |
| a Byzantine orderer tells one replica a different order | 0.2% | 100% |
| … and tells another a third order | 0.3% | 0.5% |
Every replica here is correct, yet without an agreed order nothing can be voted on. A single correct node that hands out sequence numbers fixes the problem, which is how primary-backup systems work. If that node can be Byzantine, though, it can tell different replicas different stories, and the voting collapses.
So tolerating a Byzantine node takes agreement on the inputs despite a traitor. That is exactly the Byzantine generals problem of §3, and it needs more than 2f + 1 nodes.
1.5 What each model costs
The rest of the lecture justifies this table. Treat it as a map:
| goal | failure model | nodes needed to tolerate f faults |
|---|---|---|
| keep serving, with a perfect failure detector (synchronous) | crash | f + 1 (any survivor; primary-backup) |
| agree on a value (consensus), asynchronous network | crash | 2f + 1 (majorities intersect; Paxos, Lecture 20) |
| outvote wrong outputs, given agreed inputs | Byzantine | 2f + 1 (demo 01) |
| agree on a value with oral messages, synchronous rounds | Byzantine | 3f + 1 (§3) |
| agree on a value with signed messages, synchronous rounds | Byzantine | any number of nodes (§4) |
| agree on a value, partially synchronous network, even with signatures | Byzantine | 3f + 1 (Dwork, Lynch, Stockmeyer 1988; PBFT) |
2. Making faults fail-fast
2.1 Turning lies into silence
The cheapest way to handle Byzantine behaviour is to not have it. Fail-fast design means that a component checks itself constantly and stops at the first sign of inconsistency. It converts a potential wrong answer — a Byzantine failure — into a crash, which Lecture 13’s machinery handles: redundancy, restart, process pairs. Gray’s fail-fast modules (Lecture 13 §7.1) check:
- their inputs, so that garbage is refused at the door;
- their intermediate results and data structures (invariants, assertions);
- their outputs (postconditions).
The techniques are familiar:
- Checksums and CRCs on data at rest and in transit, and ECC memory;
- assertions and invariants in code: “the sum of all balances is constant”, “this pointer is not null”, “this list is sorted”;
- end-to-end checks (Lecture 4): verify at the endpoints what the intermediate layers might have damaged;
- duplicate and compare: run a computation twice, on two processors or with two implementations, and stop if the outputs differ. Lockstep hardware does this for processors; it detects hardware faults, not shared software bugs;
- watchdogs and health checks that kill or remove a component that stops making progress or answers nonsense. A load balancer that removes a misbehaving server makes it fail-fast at the service level.
2.2 Demo 02: a ledger with silent faults
Demo 02 runs a ledger of 100 accounts through 200,000 operations: 70% balance reads and 30% transfers. Two kinds of fault strike rarely:
- bit flips, memory errors that change one balance (8 occur);
- a lost-debit bug that credits the receiver but forgets to debit the sender (2 occur).
The same operations and faults are replayed under each check policy. After a stop, the ledger recovers to the last verified state and replays the operations since then. The faults are transient, so the replay is correct.
| checks | wrong reads served | stops: checksum / postcondition / audit / strict | mean ops from fault to repair |
|---|---|---|---|
| none | 16,419 | 0 / 0 / 0 / 0 | never repaired |
| record checksums | 76 | 8 / 0 / 0 / 0 | 1,062 |
| transfer postconditions | 5,685 | 0 / 2 / 0 / 0 | 54,077 |
| periodic audit of the total (every 1,000 ops) | 25 | 0 / 0 / 10 / 0 | 523 |
| checksums + postconditions | 0 | 8 / 2 / 0 / 0 | 83 |
| all three | 0 | 7 / 2 / 1 / 0 | 82 |
| all three + “no balance > 2,500” | 0 | 4 / 2 / 0 / 2,727 | 40 |
The table teaches four lessons.
- Without checks, a fault is Byzantine. The unchecked ledger never stopped. It served 16,419 wrong balances and ended more than a million units off. From the outside it looked perfectly healthy.
- A check catches only the fault it was designed for. Checksums fired once per bit flip and never for the lost debit: the buggy code updates the checksum consistently with its wrong value. Postconditions fired once per lost debit and never for a flip. To design checks, list the faults you expect.
- Detection latency is damage. The periodic audit catches both kinds, but on average 523 operations after the fault, and 25 wrong reads escape in the meantime. The earlier the check, the smaller the damage.
- Fail-fast trades availability for reliability. With checksums plus postconditions, no wrong answer was ever served. Every fault became a stop (10 in all) that recovery repaired. An over-strict check — “no balance may exceed 2,500”, which a legitimately rich account violates — fired 2,723 false alarms. After each recovery the same legal state tripped it again: a crash loop, like Lecture 13’s poison request. A wrong check is itself a fault.
2.3 The limits of fail-fast
Fail-fast works for accidental faults, because they rarely produce wrong-but-perfectly-consistent states. It fails in three situations:
- Plausible errors. A value that is wrong but satisfies every check, such as a lost debit without a postcondition, slips through. Coverage is never complete.
- Malice. An attacker who corrupts data can also recompute its checksum. Integrity against an adversary needs keyed checks — MACs and signatures (§4, Lecture 26).
- Disagreement among observers. A faulty node that tells different nodes different things (“two-faced” behaviour) cannot be caught by any check inside one node. Detecting it requires the nodes to compare notes, and doing that despite liars is the generals’ problem.
So fail-fast covers most accidental faults within one node. For faults that show up as disagreement between nodes, there is the theory that follows.
3. The Byzantine generals
3.1 The problem
Lamport, Shostak and Pease (1982) tell the story of several divisions of the Byzantine army camped around an enemy city. Each is commanded by a general, and the generals communicate only by messenger. They must agree on a common plan — attack or retreat — but some of the generals may be traitors trying to prevent agreement.
The paper reduces this to one commander sending an order to n − 1 lieutenants, with two interactive consistency conditions:
- IC1: all loyal lieutenants obey the same order.
- IC2: if the commander is loyal, every loyal lieutenant obeys the order he sends.
If the commander is loyal, IC1 follows from IC2. The hard case is a commander who may himself be a traitor.
Why does a systems course care about generals? Replace “general” with “replica” and “order” with “the next request to execute”. A replicated service that must survive arbitrary faults needs its correct replicas to agree on their inputs (§1.4) even if the replica that distributed them is faulty. This is the core of every Byzantine-fault-tolerant system and of permissioned blockchains.
For oral messages, the paper assumes:
- A1: every message that is sent is delivered correctly;
- A2: the receiver knows who sent it;
- A3: the absence of a message can be detected.
A3 is a synchrony assumption: it requires a known bound on delivery time. It will come back in §3.6 and §5.
3.2 Three generals cannot tolerate one traitor
With three generals — a commander and two lieutenants — and one traitor, no solution exists. The argument is about indistinguishability, not about any particular algorithm. Demo 03 Part A prints it:
| scenario | commander | L1 hears from C | L1 hears from L2 | IC2 says |
|---|---|---|---|---|
| 1 | loyal, orders A; L2 is the traitor | A | “C told me R” | L1 must decide A |
| 2 | traitor: A to L1, R to L2; both lieutenants loyal | A | “C told me R” | — |
- L1 sees exactly the same things in both scenarios, so whatever rule it follows, it decides the same. In scenario 1, IC2 forces A, so L1 decides A in scenario 2 too.
- By the mirror argument, L2’s view in scenario 2 — R from the commander, “C told me A” from L1 — is identical to a scenario in which the loyal commander ordered R and L1 is the traitor. There IC2 forces R, so L2 decides R in scenario 2.
- In scenario 2, L1 attacks and L2 retreats. IC1 is violated.
Is this just a weakness of simple rules? Demo 03 Part B tries every deterministic decision rule of two protocols for three generals. In the 2-round protocol, the commander sends and the lieutenants exchange what they heard. The 3-round protocol adds an echo round in which each lieutenant repeats back what it was told. Each rule pair is checked against every behaviour of one traitor:
| protocol | rules per lieutenant | rule pairs | rules that survive a lying lieutenant | pairs satisfying IC1 + IC2 |
|---|---|---|---|---|
| 2 rounds | 16 | 256 | 1 | 0 |
| 3 rounds | 256 | 65,536 | 1 | 0 |
The only rule that survives a lying fellow lieutenant is “obey the commander”. A commander who gives different orders then splits the lieutenants. More rounds give more information, but not the information that would help: nothing a loyal lieutenant can learn distinguishes the two scenarios.
3.3 Four generals can
With four generals and one traitor, a solution exists, and it is simple: take the majority. Each lieutenant sees three values: what the commander told it, and what the two other lieutenants say the commander told them.
- If a lieutenant lies, the two loyal lieutenants still each see two correct values out of three.
- If the commander lies, all three lieutenants see the same multiset of three values, because loyal lieutenants report honestly, and so they compute the same majority.
Demo 03 checks this exhaustively, along with the 3-general version of the same algorithm (Lamport’s OM(1), which §3.5 defines). Every traitor position is tried, with every behaviour per message: A, R, or silence.
| generals | cases (all traitors, all behaviours) | IC1/IC2 violated |
|---|---|---|
| 3 | 30 | 4 |
| 4 | 108 | 0 |
The 3-general failures all come from a lying lieutenant: his false report ties 1–1 with the loyal commander’s order, and a tie defaults to retreat. Perhaps surprisingly, a traitorous commander cannot break OM(1) even with three generals: split orders make both lieutenants tie and retreat. The impossibility proof only needs some winning behaviour, and the lying lieutenant provides it.
Part D asks a sharper question. Of all 256 symmetric decision rules for 4 generals (every function of the three values a lieutenant sees), which survive one traitor? Exactly one: the majority. The demo prints its truth table.
3.4 The 3m + 1 bound
Lamport et al. extend the three-general result by a simulation argument. Suppose some algorithm worked for 3m generals with m traitors. Then three generals could each simulate m of them, with the traitor simulating a group that contains all m traitors. That would solve the three-general problem with one traitor, which is impossible. So:
With oral messages, no algorithm tolerates m traitors unless there are more than 3m generals.
Demo 04 Part B tests this on Lamport’s algorithm with random and structured lies in every message and every placement of the traitors:
| generals | traitors | runs | IC1/IC2 violated | |
|---|---|---|---|---|
| 6 | 2 | n = 3m | 990 | 296 |
| 7 | 2 | n = 3m + 1 | 1,386 | 0 |
| 9 | 3 | n = 3m | 2,184 | 726 |
| 10 | 3 | n = 3m + 1 | 3,120 | 0 |
One more general makes the difference between frequent failure and none at all. For 6 generals, the search broke all 10 placements in which both traitors are lieutenants, and none of the 5 that include the commander. Impossibility does not mean every attack wins. It means some attack always exists.
3.5 Algorithm OM(m)
Lamport’s oral-messages algorithm is recursive:
- OM(0): the commander sends his value to every lieutenant; each lieutenant uses the value received (RETREAT if none arrives).
- OM(m), m > 0:
- The commander sends his value to every lieutenant.
- Each lieutenant i acts as the commander in OM(m − 1), sending the value it received to the other n − 2 lieutenants.
- Each lieutenant decides the majority of the value it received directly and the values it obtained from the others in step 2.
Theorem (Lamport et al.): OM(m) satisfies IC1 and IC2 if there are more than 3m generals and at most m traitors.
The proof is by induction on m, and its two cases match §3.3:
- If the commander is loyal, every loyal lieutenant relays his value correctly. The recursion (Lemma 1, which needs n > 2k + m for k traitors) gives every loyal lieutenant a majority of correct values: IC2.
- If the commander is a traitor, at most m − 1 traitors remain among more than 3m − 1 lieutenants. That is more than 3(m − 1), so by induction every sub-invocation OM(m − 1) gives all loyal lieutenants the same values. Taking the majority of the same values gives the same decision: IC1.
Demo 04 Part A runs OM(1) on dsim with four generals; G3 is a traitor who always lies, and G0 orders A (trace condensed: one line per sender):
0.000 ms G0 -> G1, G2, G3: {'path': (0,), 'v': 'A'}
2.000 ms G1 -> G2, G3: {'path': (0, 1), 'v': 'A'}
2.000 ms G2 -> G1, G3: {'path': (0, 2), 'v': 'A'}
2.000 ms G3 -> G1, G2: {'path': (0, 3), 'v': 'R'} <- the lie
G1 sees A from G0, “A” from G2 and “R” from G3; majority A. G2 sees the same. The path records whose report of whose report this is. It is how the dsim version (OMGeneral) evaluates the recursion as a tree, an implementation known as exponential information gathering. The self-test checks that it decides exactly what the recursive version does.
The price. OM(m) needs m + 1 rounds, and its messages multiply at each level: (n − 1) + (n − 1)(n − 2) + … (demo 04 Part C):
| traitors m | generals n = 3m + 1 | rounds | messages for ONE decision |
|---|---|---|---|
| 1 | 4 | 2 | 9 |
| 2 | 7 | 3 | 156 |
| 3 | 10 | 4 | 3,609 |
| 4 | 13 | 5 | 108,384 |
| 5 | 16 | 6 | 3,999,675 |
The number of rounds cannot be improved much: any deterministic algorithm needs at least f + 1 rounds to tolerate f faults, even mere crashes (Fischer and Lynch 1982; Dolev and Strong 1983). The number of messages can be improved: later algorithms are polynomial. But Byzantine agreement remains expensive, which is why most systems in this course assume crash failures.
3.6 The hidden assumption: synchrony
Assumption A3, “the absence of a message can be detected”, silently assumes that every message arrives within a known time. Lieutenants wait for the end of the round, and anything not received by then counts as missing (RETREAT). Demo 04 Part D runs OM(2) on 7 generals with no traitors at all. Rounds are 4 ms, and the one-way latency is uniform between 1 ms and a maximum that the demo varies:
| max latency | late messages per run | runs violating IC2 | runs violating IC1 |
|---|---|---|---|
| 3 ms | 0 | 0/200 | 0/200 |
| 4 ms | 0 | 0/200 | 0/200 |
| 5 ms | 23.5 | 179/200 | 114/200 |
| 6 ms | 27.2 | 200/200 | 27/200 |
| 12 ms | 16.9 | 200/200 | 0/200 |
As soon as the network is sometimes slower than the round, correct generals disagree with each other (IC1) or retreat against a loyal order (IC2). With very slow networks they all agree, but on the wrong thing, because most messages count as missing. A slow message is indistinguishable from a missing one, and an algorithm that relies on rounds is correct only as long as the rounds hold. §5 shows that without such bounds, no deterministic algorithm can guarantee agreement.
4. Signed messages
4.1 What signatures change
A traitor’s power with oral messages comes from lying about what others said: “the commander told me R”. The paper’s second algorithm removes that power with an extra assumption:
- A4: (a) a loyal general’s signature cannot be forged, and any alteration of a signed message can be detected; (b) anyone can verify a general’s signature.
With signatures, a traitor can still lie about his own orders: a traitorous commander can sign “attack” for one lieutenant and “retreat” for another. What he cannot do is put words in a loyal general’s mouth. To relay a message, a traitor can only pass on the signed copy he actually received, or say nothing.
In byzantine.py the signatures are HMAC-SHA256 tags checked by a trusted verifier. A traitor’s code is given only its own key, so it can sign as itself but cannot produce a loyal general’s tag. That stands in for public-key signatures, where everyone can verify and only the owner can sign.
4.2 Algorithm SM(m)
Each lieutenant i keeps a set V_i of orders it has seen:
- The commander signs his order and sends it to every lieutenant.
- When a lieutenant receives a validly signed order v that is not yet in V_i, it adds v to V_i. If the message carries fewer than m + 1 signatures, the lieutenant countersigns it and sends it to every lieutenant who has not signed it yet.
- When no more messages will arrive, it obeys choice(V_i): the single order if V_i has exactly one, and RETREAT otherwise.
Why it works: a loyal lieutenant passes on every new order it accepts. If a loyal lieutenant accepts an order carrying m + 1 signatures, at least one signer was loyal and already sent it to everyone. So all loyal lieutenants end with the same set V, and choice(V) gives them the same decision (IC1). If the commander is loyal, no other order can carry his signature, so V = {his order} (IC2). A loyal lieutenant who sees two different orders signed by the commander knows the commander is a traitor. That proof of lying is exactly what oral messages lack.
4.3 Demo 05: three generals are enough
Part A checks SM(1) with three generals against every behaviour of one traitor:
- a commander who signs any set of orders for each lieutenant (one, both or none);
- a lieutenant who relays, drops, forges or delays.
| traitor | cases | IC1/IC2 violated |
|---|---|---|
| commander | 16 | 0 |
| a lieutenant | 16 | 0 |
The case that defeats oral messages is a commander who orders A to L1 and R to L2. With signatures, the lieutenants exchange signed copies, both see {A, R}, both know the commander lied, and both retreat.
Part B goes further: m traitors among only m + 2 generals, colluding freely (random behaviours, m = 1 to 4). There were 0 violations in 5,100 runs, but only with one detail in place. A message carrying k signatures must arrive in round k. Our first implementation accepted signed messages whenever they arrived. A traitor who delayed a signed order and showed it to one loyal lieutenant in the last round broke agreement 17 times. That lieutenant had no round left to pass the order on, so the loyal generals ended with different sets V. Signatures remove the 3m + 1 bound, not the need for synchronous rounds.
4.4 Costs, and what signatures do not give
Part C compares the two algorithms:
| generals | oral: traitors tolerated | OM messages | signed: traitors tolerated | SM messages (no faults) | SM, commander signs both orders |
|---|---|---|---|---|---|
| 4 | 1 | 9 | 2 | 9 | 18 |
| 7 | 2 | 156 | 5 | 36 | 72 |
| 10 | 3 | 3,609 | 8 | 81 | 162 |
| 13 | 4 | 108,384 | 11 | 144 | 288 |
A loyal lieutenant in SM relays each value once, not each path, so SM is far cheaper in messages. But each message carries a growing chain of signatures, and real public-key signatures are expensive to compute and check. Practical BFT systems such as PBFT (Castro and Liskov 1999) use message authentication codes in the common case for this reason. Signatures also need a trusted way to learn everyone’s public keys: a key infrastructure (Lecture 26).
Signatures do not provide freshness either. Part D replays the commander’s genuine signed “R” from an earlier decision into a new one in which the loyal commander orders A:
| what the signature covers | loyal G1 decides | IC2 |
|---|---|---|
| only the order | R | violated |
| the order and the decision’s id | A (replay rejected) | holds |
A signature proves who said something, not when or in which context. Signed messages must carry their context — an instance number, a nonce, a timestamp — or old messages become weapons. Lecture 26 returns to replay attacks.
4.5 From generals to systems
The generals problem became the foundation of Byzantine-fault-tolerant state machine replication: replicas agree, despite traitors, on the order of client requests, then execute them and vote on the replies (§1.3–1.4). PBFT made this practical in 1999:
- 3f + 1 replicas, because the network is only partially synchronous, and Dwork, Lynch and Stockmeyer showed that Byzantine agreement then needs n ≥ 3f + 1 even with signatures;
- a few rounds of all-to-all messages per request;
- MACs instead of signatures in the normal case.
Permissioned blockchains use descendants of it (Lecture 23).
Most systems nevertheless assume crash failures plus fail-fast engineering, because BFT is expensive:
- 3f + 1 machines instead of 2f + 1;
- cryptography on every message;
- quadratic message counts;
- above all, independence: if every replica runs the same software, one bug makes them all Byzantine at once, a common-mode failure (Lecture 13 §4.4). Real Byzantine tolerance needs diverse implementations.
BFT is reserved for settings where the adversary is real: multiple organizations that do not trust each other, safety-critical control, cryptocurrencies.
5. Timeouts, failure detectors and the limits of agreement
5.1 Three models of time
Every algorithm so far assumed synchronous rounds. Real networks offer weaker guarantees:
| model | assumption | example |
|---|---|---|
| synchronous | known bounds on message delay and processing speed | a dedicated real-time bus |
| asynchronous | no bounds at all: messages arrive eventually, processes are slow arbitrarily | the theorist’s Internet |
| partially synchronous (Dwork, Lynch, Stockmeyer 1988) | bounds exist but are unknown, or hold only after some unknown time | the real Internet: usually fast, sometimes not |
In an asynchronous system, a crashed process and a very slow one are indistinguishable. Every way of detecting failures is a guess.
5.2 Failure detectors
Chandra and Toueg (1996) made this precise. A failure detector is a module that outputs a list of processes it suspects of having crashed. It is judged on two properties:
- completeness: every process that really crashed is eventually suspected;
- accuracy: no correct process is ever suspected. Weaker variants: some correct process is never suspected, or this holds only eventually.
The practical detector is Gray’s “I am alive” message, or heartbeat, plus a timeout: suspect a process that has been silent for longer than T. A short T gives fast detection and many false suspicions; a long T gives few mistakes and slow detection. Can a cleverer rule escape the trade-off?
5.3 Demo 06: detection time vs false suspicions
A process P sends a heartbeat every 100 ms over a network with 1–5 ms delay and 1% loss. Now and then P pauses — garbage collection, a VM migration, swapping — and then continues as if nothing happened. Pauses come about every 5 minutes, with lognormal lengths (median 150 ms; about 1 in 20 lasts over 0.7 s). The demo counts false suspicions over 2 hours of a healthy P, and detection time over 100 runs in which P really crashes:
| detector | false suspicions per hour | mean time to detect a crash |
|---|---|---|
| fixed timeout 150 ms | 353 | 106 ms |
| fixed timeout 250 ms | 9.0 | 206 ms |
| fixed timeout 500 ms | 2.0 | 456 ms |
| fixed timeout 1,000 ms | 0.5 | 956 ms |
| fixed timeout 2,000 ms | 0 | 1,956 ms |
| adaptive: mean + 4 × deviation | 346 | 82 ms |
| adaptive, never below 2 periods | 9.0 | 176 ms |
| φ-accrual, normal fit, φ > 8 | 336 | 121 ms |
| φ-accrual, exponential fit, φ > 3 | 1.5 | 653 ms |
| φ-accrual, exponential fit, φ > 8 | 0 | 1,816 ms |
Four observations:
- There are two causes of false suspicion. Below two heartbeat periods, a single lost heartbeat (1% of 36,000 an hour, about 360) trips the detector. Above that, only the pauses remain (12 an hour), and the longer the timeout, the fewer pauses outlast it.
- Adaptive detectors that learn the jitter are fast and wrong. The rule “mean + 4 deviations” (like TCP’s retransmission timer, Lecture 4) learned that gaps are 100 ± 4 ms and chose timeouts of about 120 ms. It detected crashes in 82 ms and cried wolf at every lost heartbeat. The φ-accrual detector (Hayashibara et al. 2004) with a normal fit behaved the same. The φ-accrual idea is sound: output a suspicion level φ = −log₁₀ P(a gap this long | the process is alive), and let each application choose its threshold. But the answer depends entirely on the distribution assumed. With an exponential fit (as Cassandra uses), the same idea gives few mistakes and slow detection.
- No rule escapes the trade-off. The fastest detector with no false suspicion in two hours took almost 2 seconds. Every rule is a point on the same curve. Adaptivity helps you find a good point; it does not remove the curve.
- The trade-off is application-specific. A load balancer can afford many false suspicions: it just retries elsewhere. A primary-backup system cannot. If the backup takes over while the primary is alive but paused, the result is two primaries, or “split brain”. That is why Lecture 7’s leases make a primary stop serving before the backup may take over, and why Lecture 20’s consensus protocols must stay safe even when the detector is wrong.
5.4 Crashed or slow? The FLP impossibility
Demo 06 Part B runs two worlds with the same seed:
- P crashes at 10 s;
- P pauses from 10 s to 13 s, then resumes.
The monitor’s view is identical until 13.01 s, when the paused process speaks again. At 11 s, 12 s and 12.9 s the last heartbeat is #99 at 9,901.6 ms in both runs. A detector that suspects P at 12 s is wrong in world 2; one that waits until it is sure never suspects P in world 1.
Fischer, Lynch and Paterson (1985) turned this intuition into one of the most important results in distributed computing:
FLP: in an asynchronous system in which even one process may crash, no deterministic algorithm can guarantee that all correct processes reach agreement, satisfying agreement and validity, and that they always terminate.
The proof idea, informally:
- Some initial configurations are bivalent: either decision is still reachable, depending on what happens next.
- From any bivalent configuration, the adversary can always delay one critical message long enough that the system stays bivalent. The delayed process might be slow or crashed, and the others cannot tell which.
- So there is an infinite run in which nobody decides.
FLP does not say that consensus is impossible in practice. It says that safety and liveness cannot both be guaranteed when timing is unbounded. Practical systems escape it in one of three ways:
| escape | idea | example |
|---|---|---|
| partial synchrony | always safe; guaranteed to terminate once the network behaves for long enough | Paxos, Raft, PBFT (Lectures 20–21) |
| randomization | terminate with probability 1 | Ben-Or (1983); many blockchain protocols |
| failure detectors | an eventually accurate detector (◇S) suffices for consensus | Chandra and Toueg (1996) |
The pattern for the rest of the course: never let a timeout decide safety. Use timeouts for liveness (to retry, to elect a new leader), and design the protocol so that a wrong suspicion causes delay, not inconsistency.
6. The limits, in one table
| question | answer | where |
|---|---|---|
| Byzantine agreement, oral messages | n > 3m; m + 1 rounds; messages ~ n^(m+1) | §3 |
| Byzantine agreement, signed messages, synchronous | any n; m + 1 rounds (a message with k signatures counts only in round k) | §4 |
| Byzantine agreement, partial synchrony | n ≥ 3f + 1, even with signatures | §1.5, §4.5 |
| outvoting Byzantine outputs given agreed inputs | 2f + 1 replicas, wait for f + 1 matching | §1.3 |
| crash consensus, asynchronous | impossible to guarantee termination (FLP); with partial synchrony, 2f + 1 | §5.4, Lecture 20 |
| rounds for any deterministic agreement with f faults (synchronous) | at least f + 1 | §3.5 |
| perfect failure detection in an asynchronous system | impossible: crashed and slow look the same | §5 |
7. Design rules
- Choose the failure model deliberately, and write it down. Most systems assume crash-recover plus omission and timing faults, and use engineering to keep Byzantine behaviour rare.
- Make components fail-fast: checksums end to end, invariants and postconditions on every state change, and stop at the first inconsistency. Design checks for the faults you expect, and keep them correct: a wrong check causes crash loops.
- Detect early: detection latency is damage.
- Do not trust the fastest answer when lies are possible; wait for f + 1 matching replies.
- Agree on inputs before voting on outputs. Replicas must execute the same requests in the same order.
- Byzantine agreement costs 3f + 1 nodes (or signatures and synchrony) and many messages; use it only when the threat is real, and with diverse implementations.
- Sign the context, not just the content: instance ids, nonces, sequence numbers.
- Treat timeouts as guesses. Tune them per application, count both detection time and false suspicions, and never let a suspicion alone decide safety: use leases, fencing or consensus.
- Remember FLP: aim for “always safe, live when the network behaves”.
Summary
- Failure models form a hierarchy: crash-stop ⊂ crash-recover ⊂ omission ⊂ timing ⊂ Byzantine.
- In demo 01, crash, omission and timing faults of one replica cost only time.
- A Byzantine replica that answered first with wrong values fooled “first reply” 300/300 times; waiting for 2 matching replies was always right.
- Voting needs agreed inputs: without an order, correct replicas agreed on 0.2% of steps.
- Fail-fast turns Byzantine faults into stops.
- Unchecked, a ledger served 16,419 wrong reads.
- Checksums caught only bit flips, postconditions only the lost-debit bug, an audit both but 523 operations late.
- Checksums + postconditions served no wrong read and stopped 10 times.
- An over-strict check crash-looped (2,723 false alarms).
- Three generals cannot tolerate one traitor:
- none of 256 (2-round) or 65,536 (3-round) rule pairs works;
- OM(1) fails 4 of 30 cases with 3 generals and 0 of 108 with 4;
- majority is the unique working symmetric rule for 4.
- OM(m) needs n > 3m:
- n = 3m broke 296/990 and 726/2,184 runs; n = 3m + 1 never;
- m + 1 rounds and 3,999,675 messages for m = 5;
- synchrony matters: with no traitors, latency above the round length broke IC2 in up to 200/200 runs.
- Signed messages (SM(m)):
- work with any n: 0/32 for 3 generals, 0/5,100 for m traitors among m + 2;
- but only with round discipline (17 violations when late messages were accepted);
- and only with context in the signature (a replay broke IC2 otherwise).
- Failure detectors trade detection time against false suspicions:
- a 150 ms timeout: 106 ms detection and 353 false alarms per hour (lost heartbeats);
- a 2 s timeout: 1,956 ms and none;
- jitter-adaptive detectors were fast and wrong.
- FLP: a crashed and a paused process looked identical until 13.01 s. No deterministic protocol can guarantee both safety and termination in an asynchronous system with one crash. Practical protocols stay safe always and live when timing behaves.
Common pitfalls
- Assuming crash failures and then accepting the first reply from a replica that can return garbage.
- Voting on outputs without agreeing on inputs (order of requests).
- Checksums against malice. An attacker recomputes them; use MACs or signatures.
- Checks that do not match the fault, or checks that reject legal states (crash loops).
- Believing that 2f + 1 replicas tolerate f Byzantine faults in agreement. It takes 3f + 1 with oral messages, and with signatures under partial synchrony.
- Forgetting the synchrony assumption in round-based algorithms: late messages are missing messages.
- Signing a value without its context (replays).
- A timeout tuned to the network’s jitter, which trips at every lost packet and every GC pause.
- Letting a failure detector decide safety: two primaries after a false suspicion.
- Reading FLP as “consensus is impossible” instead of “termination cannot be guaranteed without timing assumptions”.
Exercises
-
Weakest model, cheapest client. For each behaviour, name the weakest failure model that describes it, and the cheapest strategy from demo 01 that still returns correct answers if one of three replicas behaves this way: (a) a replica whose disk is full and which silently drops 10% of the writes it acknowledges; (b) a replica that is correct but stalls 3 s for garbage collection every minute; (c) a replica whose network card dies; (d) a replica that, after a bad deploy, returns results computed with last week’s exchange rates.
Answer
(a) It acknowledges writes it did not perform, so later reads return wrong data: Byzantine (a reply that looks right but is wrong). The client must wait for f + 1 = 2 matching replies, and the replicas must agree on the order of writes. (b) Timing: correct but late. "First reply" or "2 matching" (both ignore the slowest replica). (c) Crash (from the clients' point of view, all its messages are omitted). Any strategy that does not insist on that replica: "first reply" is cheapest. (d) Byzantine: wrong but plausible values. A local check cannot see it unless the rates carry a version or timestamp that a check verifies. Clients need 2 matching replies, and the correct replicas must have the current rates. -
Designing fail-fast checks. A caching proxy stores objects with their size and a hash. Faults: (i) a memory error corrupts a cached object; (ii) a bug stores object B under object A’s key; (iii) the origin server returns a truncated object with a valid HTTP status. For each fault, propose a check that detects it, say when it runs, and what the proxy should do when it fires.
Answer
(i) Verify the stored hash on every read (or with periodic scrubbing). On a mismatch, drop the entry and refetch from the origin: the cache becomes a miss, not a wrong answer. (ii) Store the key inside the entry, and check on every read that the entry's key equals the requested key (a per-record checksum alone would not catch this, because B's checksum is valid for B). On a mismatch, invalidate and refetch, and log a bug report: this is a Bohrbug and will recur. (iii) Compare the received length with the declared Content-Length, or with an end-to-end hash or ETag from the origin, before caching. On a mismatch, do not cache, retry once, and return an error rather than a truncated body. In all three cases the proxy fails fast: it refuses to serve what it cannot vouch for. -
OM(1) by hand. Four generals; the commander is a traitor and sends A to L1, A to L2 and R to L3. The lieutenants are loyal. What does each lieutenant see, and what does it decide? Now suppose instead the commander is loyal (orders R) and L1 is a traitor who tells L2 “A” and L3 “R”. What happens?
Answer
Case 1: each loyal lieutenant relays what it received, so every lieutenant sees the multiset {A, A, R} (its own value plus the two others'). All three decide majority = A. IC1 holds, and IC2 is vacuous because the commander is a traitor. Case 2: L2 sees R (from the commander), "A" (from L1) and "R" (from L3): majority R. L3 sees R, "R" (from L1) and "R" (from L2): R. Both loyal lieutenants decide R, the commander's order: IC1 and IC2 hold. -
Counting. (a) How many messages does OM(1) send with 7 generals, and how many traitors does it tolerate? (b) And OM(2)? (c) A system expects at most one Byzantine replica. Is it better to run OM(1) with 4 generals or OM(1) with 7?
Answer
(a) OM(1): 6 + 6 × 5 = 36 messages. It tolerates m = 1 traitor (it needs n > 3; with 7 generals, more than enough). (b) OM(2): 6 + 30 + 30 × 4 = 156 messages, tolerating 2 traitors (n = 7 > 6). (c) For one traitor, 4 generals suffice: 9 messages instead of 36, on fewer machines. Extra generals add cost without adding tolerance unless the algorithm runs with a higher m. More machines also mean more chances that two of them fail. -
SM(1) by hand. Three generals with signatures. The traitorous commander signs A for L1 and sends L2 nothing. Trace the messages and decisions. Then the commander is loyal (orders A) and L2 is a traitor that tries to forward “R signed by the commander”. What happens?
Answer
Case 1: L1 receives (A : C), adds A to V₁ and relays (A : C : L1) to L2. L2 receives it in round 1: it carries 2 signatures, so it counts in round 1, the signatures verify, and L2 adds A to V₂. Both have V = {A} and both decide A: IC1 holds. A commander who stays silent to one lieutenant cannot keep him out, because L1 relays. Case 2: L2 cannot produce the commander's signature on R; its forged message fails verification and L1 rejects it. L1 has V₁ = {A} and decides A: IC2 holds. -
How many replicas? You need to tolerate f = 2 faulty nodes. How many nodes are needed for: (a) a primary-backup service with a perfect failure detector, against crashes; (b) crash-tolerant consensus in a partially synchronous network; (c) Byzantine agreement with oral messages in synchronous rounds; (d) Byzantine state machine replication over the Internet, with signatures?
Answer
(a) f + 1 = 3: any survivor can serve, and the perfect detector says when to switch. (b) 2f + 1 = 5: any two majorities of 3 intersect, so decisions cannot conflict (Lecture 20). (c) 3f + 1 = 7 (§3.4). (d) 3f + 1 = 7. The Internet is at best partially synchronous, and Dwork, Lynch and Stockmeyer showed that n ≥ 3f + 1 is then necessary even with signatures. Signatures help SM(m) only with synchronous rounds. -
Tuning a detector. Heartbeats go every 200 ms; each is lost independently with probability 0.5%; the process never pauses. (a) With a timeout of 300 ms, about how many false suspicions per day? (b) With a timeout that tolerates two lost heartbeats in a row? (c) What is the mean detection time in each case?
Answer
(a) 432,000 heartbeats a day. A timeout of 300 ms trips whenever one heartbeat is lost (the gap becomes 400 ms): about 0.005 × 432,000 ≈ 2,160 false suspicions a day. (b) To tolerate two losses, use a timeout slightly above 3 periods, say 650 ms. A false suspicion then needs 3 consecutive losses: about 432,000 × 0.005³ ≈ 0.05 a day, one every ~20 days. (c) A crash occurs at a uniformly random point between heartbeats, so the last heartbeat was on average half a period (100 ms) before it. Detection comes at the last heartbeat plus the timeout: about 300 − 100 = 200 ms in (a), 650 − 100 = 550 ms in (b), plus the network delay. (Compare demo 06: 106 ms for a 150 ms timeout with a 100 ms period.) -
FLP in a design review. A colleague says: “Our replicated lock service always terminates. If the leader doesn’t answer in 5 s, the followers elect a new leader. And it never gives the lock to two clients.” What is wrong with the claim, and what should the guarantee say instead?
Answer
In an asynchronous network a leader can be slower than 5 s without having crashed (a GC pause, a partition). If the followers elect a new leader, the old one may still believe it is the leader. FLP says that no deterministic protocol can guarantee both agreement and termination in such a network. So either the protocol can block (no termination during long delays), or it can grant the lock twice. Two primaries may each grant the lock unless they are fenced, for example by leases that expire before re-election, or by epoch numbers that the storage checks. The honest guarantee: the lock is never granted to two clients (safety, always), and requests complete whenever the network delivers messages within the timeout for long enough (liveness under partial synchrony). Lectures 7 (leases) and 20 (Paxos) show how.
Related project and problem set (concepts only)
-
Problem Set 3 asks you to classify failure behaviours as fail-fast or Byzantine and to say how to make them fail-fast. §1–§2 give the concepts:
- the failure-model hierarchy;
- fail-fast as a design choice;
- checks that fit the fault;
- detection latency.
The scenarios here are different, and the answers are not here.
-
Project 4 (two-phase commit over a lossy network) must cope with crash-recover nodes and omitted or delayed messages. §1 and §5 explain the failure model and why its timeouts can only be guesses. Lectures 16–18 build the protocol concepts. No project code here.
Further reading
- L. Lamport, R. Shostak and M. Pease, “The Byzantine Generals Problem”, ACM TOPLAS 4(3), 1982.
- F. Cristian, “Understanding Fault-Tolerant Distributed Systems”, CACM 34(2), 1991 — the failure classification.
- R. D. Schlichting and F. B. Schneider, “Fail-Stop Processors: An Approach to Designing Fault-Tolerant Computing Systems”, ACM TOCS 1(3), 1983.
- M. J. Fischer, N. A. Lynch and M. S. Paterson, “Impossibility of Distributed Consensus with One Faulty Process”, JACM 32(2), 1985.
- C. Dwork, N. Lynch and L. Stockmeyer, “Consensus in the Presence of Partial Synchrony”, JACM 35(2), 1988.
- T. D. Chandra and S. Toueg, “Unreliable Failure Detectors for Reliable Distributed Systems”, JACM 43(2), 1996.
- N. Hayashibara, X. Défago, R. Yared and T. Katayama, “The φ Accrual Failure Detector”, SRDS 2004.
- M. Castro and B. Liskov, “Practical Byzantine Fault Tolerance”, OSDI 1999.
- F. B. Schneider, “Implementing Fault-Tolerant Services Using the State Machine Approach: A Tutorial”, ACM Computing Surveys 22(4), 1990.
Preview of Lecture 15 — Checkpointing and message logging
Lecture 13 showed that a long computation on many machines must save its progress. Lecture 15 asks how:
- the optimal checkpoint interval (Young and Daly);
- what a consistent global checkpoint is (cuts, orphan messages, messages in transit);
- why uncoordinated checkpoints can roll a whole system back to its start (the domino effect);
- how the Chandy–Lamport snapshot records a consistent state without stopping anyone;
- how message logging and deterministic replay let one process recover alone — the approach of Borg et al.’s Auragen and TARGON/32 systems, the course’s readings.
术语表 (Glossary, English → 中文)
| English | 中文 |
|---|---|
| failure model | 失效模型(故障模型) |
| crash-stop / fail-stop | 崩溃停止 / 失效停止 |
| crash-recover | 崩溃恢复 |
| omission failure | 遗漏失效 |
| timing (performance) failure | 时序(性能)失效 |
| Byzantine (arbitrary) failure | 拜占庭(任意)失效 |
| fail-fast | 快速失败 |
| fail-silent | 失效静默 |
| invariant / assertion / postcondition | 不变式 / 断言 / 后置条件 |
| checksum / CRC / ECC | 校验和 / 循环冗余校验 / 纠错码 |
| silent data corruption | 静默数据损坏 |
| detection latency / coverage | 检测延迟 / 覆盖率 |
| false alarm (false positive) | 误报 |
| duplicate and compare | 双份比较 |
| voting / majority | 表决 / 多数 |
| state machine replication | 状态机复制 |
| sequencer (orderer) | 定序器 |
| Byzantine generals problem | 拜占庭将军问题 |
| commander / lieutenant | 司令 / 副官 |
| traitor / loyal | 叛徒 / 忠诚者 |
| interactive consistency | 交互一致性 |
| oral messages / signed messages | 口头消息 / 签名消息 |
| indistinguishability | 不可区分性 |
| exponential information gathering | 指数信息收集 |
| round (synchronous round) | 轮次(同步轮) |
| digital signature / MAC (HMAC) | 数字签名 / 消息认证码 |
| forgery / replay attack | 伪造 / 重放攻击 |
| freshness / nonce | 新鲜性 / 随机数(一次性数) |
| public-key infrastructure (PKI) | 公钥基础设施 |
| Byzantine fault tolerance (BFT) | 拜占庭容错 |
| N-version programming (design diversity) | N 版本编程(设计多样性) |
| synchronous / asynchronous / partially synchronous system | 同步 / 异步 / 部分同步系统 |
| failure detector | 故障检测器 |
| completeness / accuracy | 完备性 / 准确性 |
| heartbeat / timeout | 心跳 / 超时 |
| false suspicion | 误判(误怀疑) |
| φ accrual failure detector | φ 累积故障检测器 |
| split brain | 脑裂 |
| fencing / lease | 隔离(栅栏) / 租约 |
| consensus | 共识 |
| FLP impossibility | FLP 不可能性 |
| bivalent configuration | 双价配置 |
| safety / liveness | 安全性 / 活性 |
| randomized consensus | 随机化共识 |