12-02
Chapter 12 · Taming the state space, choosing your evidence
Predict the growth curve
00Recall
One card from 12-01 on why liveness needs the whole graph, one from 03-04 on what depth measures, and one from 03-03 on what a pass with too few states means. The last one returns in a new costume: a cap that makes a check finish by checking less.
12-01-a from Inside TLC
Why can TLC check an invariant the moment it computes a state, but not a liveness property?
Show answer
An invariant is a claim about one state. A liveness property is refuted by a loop of states, so TLC needs the graph's edges and a second search over the whole graph.
03-04-b from Reading the numbers
What does the depth in TLC's summary line measure, and in what unit?
Show answer
The length of a shortest path from an initial state to the reachable state farthest from it, counted in states: an initial state is at depth one, so the farthest state is one step fewer than the depth away.
03-03-a from Break it on purpose
TLC reports no violation and zero distinct states. What has it shown about your invariants?
Show answer
Nothing. With no reachable states, every invariant holds vacuously.
Skip recall Recall is never required.
01Commit
Here are two points of a curve. TwoPhaseCommit with two participants has 29 distinct states. With three it has 99. Nothing else changes between the two cfgs.
Commit a
TwoPhaseCommit.n4.cfg runs the same spec with four participants. How many distinct states will TLC report?
Your answer is a whole number.
Answer 353
- Exactly right
- Right. You saw that each participant multiplies the count by about three and a half, and applied that factor once more.
- Within 10 %
- Within 10 %. You saw that each participant multiplies the count, and estimated the factor a little off.
- Under by more than half
- Under by more than half. You probably added the difference between the first two points again. Each participant multiplies the count; it does not add to it.
- More than double
- More than double. You probably multiplied every value each variable could take. Most of those combinations are unreachable: a participant cannot be committed while the coordinator is still collecting.
- Anything else
- Between half and double the answer, but more than 10 % off: you had the right shape and the wrong factor. Divide the second count you were given by the first, and apply that factor once more. Growth by a constant factor per participant is what "exponential in N" means.
specs/AuditedCommit.tla runs transactions back to back and keeps an audit log of every event, which nobody in the protocol reads. The log grows for ever, so TLC would never finish. A teammate adds CONSTRAINT LogCap, where LogCap == Len(audit) <= 3, and keeps the same two invariants.
Commit b
What does ./tla report for AuditedCommit.capped.cfg?
- A pass, with every action firing: the cap only makes the check finish.
- A pass, with a coverage gap: some action can never fire within three events.
- It still never finishes: the log can be any of infinitely many sequences.
Answer A pass, with a coverage gap: some action can never fire within three events.
- If you picked A
- A state constraint tells TLC to stop exploring from any state that breaks it. Every behavior longer than the cap is gone, and with it every action that needs more events than that.
- If you picked C
- There are only finitely many logs of length three or less over a finite set of events. The cap does make the model finite. The question is what it costs.
02Lab
./tla check chapters/12-state-space-and-evidence/specs/TwoPhaseCommit.n4.cfg
./tla check chapters/12-state-space-and-evidence/specs/AuditedCommit.capped.cfg
./tla check chapters/12-state-space-and-evidence/specs/AuditedCommit.view.cfg12-state-space-and-evidence/specs/TwoPhaseCommit.n412-state-space-and-evidence/specs/TwoPhaseCommit.n4 TwoPhaseCommit.n4.cfg (Participants={p1, p2, p3, p4})
parse ok
model check: no violation found in 353 distinct states (1373 generated, depth 10)
expected outcome met: pass
coverage: all 7 actions fired
witness AllCommitted reached (trace of 10 states)12-state-space-and-evidence/specs/AuditedCommit.capped12-state-space-and-evidence/specs/AuditedCommit.capped AuditedCommit.capped.cfg (Participants={p1, p2, p3})
parse ok
model check: no violation found in 215 distinct states (743 generated, depth 4)
expected outcome met: coverage-gap LearnCommitReveal for commit a
TLC reports 353 distinct states for four participants, with a depth of 10. The three points are 29, 99 and 353: each participant multiplies the count by about three and a half.
Reveal for commit b
A pass with a coverage gap: LearnCommit never fires. A participant can learn of a commit only after every participant has voted and the coordinator has committed, and that is already more events than the cap allows. The check explored 215 distinct states and never saw a single commit reach a participant.
03Reason
If you added the difference again, you drew a straight line through two points of a curve. It is the most natural guess and the most expensive one to get wrong.
Look at what a state of TwoPhaseCommit is: one local state for each participant, the coordinator's state, and the set of messages sent. Add a participant and every existing state can be combined with each of the new participant's possibilities: still working, ready with its vote on the network, given up, committed, aborted. Not every combination is reachable, but a fixed share of them is, so each participant multiplies the count by roughly the same factor.
The facts agree: 99 divided by 29 is about 3.4, and 353 divided by 99 is about 3.6. A constant factor per component is exponential growth. It is not a flaw of TLC; it is how many futures a system with independent parts really has. Interleavings do not add to the count, because TLC stores each state once however many orders reach it.
Write something before openingthe depth grows by two with each participant. Why two?
Each extra participant adds exactly two events to the longest shortest path: its vote, and learning the outcome. One farthest state is the happy end, where everyone has committed, and the shortest way there takes one vote and one learn per participant plus the coordinator's commit.
The audit log is a different kind of growth: unbounded. Restart begins a new transaction, the log keeps every event, and no two states with different logs are equal, so the reachable set is infinite. TLC would run until the disk filled, and you would learn nothing.
You have two tools to make a model like this finite, and each one changes the question.
A state constraint (CONSTRAINT P in the cfg) tells TLC not to explore from any state where P is false. It does not change the spec; it cuts the search. LogCap cut every behavior longer than three events, and the coverage gap told you so. Every violation that lived on a cut behavior goes with it: a constraint buys speed with coverage, and ./tla's coverage and witness checks are how you see the bill.
./tla check chapters/12-state-space-and-evidence/specs/AuditedCommit.peek.cfgWrite something before openinghow can a state outside the constraint appear in a trace?
TLC computes every successor of every state it explores and checks the invariants in each one, including a successor that breaks the constraint. The constraint decides only whether that successor is explored further. So TLC looks one step past the cap, never two. The trace has 5 states, and the run had found the same 215 distinct states as the capped run, though it stopped before exploring them all. Nothing is wrong with TLC; "stop at three" was never what a constraint means.
A view (VIEW E in the cfg) changes what TLC fingerprints: the value of the expression E instead of the whole state. Two states with the same view count as one. AuditedCommit defines Protocol == << part, coord, sent >>, everything except the log. Nothing in the protocol reads the log, and the only property that mentions it, TypeOK's conjunct audit \in Seq(Events), is true in every reachable state. So two states that differ only in their logs have exactly the same futures, and no checked property can tell them apart.
AuditedCommit.view.cfg finds no violation in 99 distinct states, with every action firing and the witness reached. That is the same count as TwoPhaseCommit.n3, which is no coincidence: with the log out of the picture, a run of transactions is one transaction, restarted.
Write something before openinga third tool filters steps instead of states. AuditedCommit.happy.cfg adds ACTION_CONSTRAINT NobodyGivesUp to the view. What does TLC still look at?
TLC explores through no GiveUp step, so the model is every behavior in which no participant gives up (the coordinator may still abort), 80 distinct states, and it answers a smaller question: is the protocol consistent when nobody gives up? But as with CONSTRAINT, TLC still checks the invariants in the state a rejected step leads to. AuditedCommit.offpath.cfg, with the same action constraint, fails in a trace of 2 states on an invariant that only GiveUp can break. Run both cfgs.
Write something before openingyou raise the cap in LogCap until the coverage gap disappears. Is the capped check now as good as the view?
No. A clean coverage line says that every action fired at least once somewhere in the search, not that every behavior was searched. The cap still cuts every behavior longer than it, so a bug that needs a second transaction after a restart, or a long run of retries, can sit beyond the edge, where nobody looks. The view cut nothing: it merged states whose futures are identical. The rule of thumb: when you can argue that a variable is never read, drop it with a view; when you cannot, a constraint is honest only if the claim names the bound, and the bound is chosen for a reason you can write down.
04In your editor
Check this lesson's exercises with:
./tla check 12-02Before each run, write the distinct count you expect in NOTES.md.
05Practice
Warm-up. A step counter for a dashboard makes TwoPhaseCommit infinite, and a teammate's cap makes it finish by checking almost nothing. Replace the cap with a view.
Core. A task board with a reviewer carries two counters. One of them is read by a rule, and the other is not. Write the view, and find out what happens if you drop the wrong one.
12-02-ex1Warm-up5 min
12-02-ex1 · The counter nobody reads
Tier: warm-up. Time: about 5 minutes.
CountedCommit.tla is TwoPhaseCommit with a step counter for the metrics dashboard, and transactions that restart forever. The counter never repeats, so the reachable states never run out. A teammate made the check finish with CONSTRAINT TickCap, which stops after three steps.
- Run
./tla check 12-02-ex1. It finishes, and./tlareports a coverage gap. Which action never fires, and why can it not fire within three steps? - Fill gap g1 in
CountedCommit.tla:Protocolis the tuple of variables TLC should compare when it decides whether it has seen a state before. Leave out the variable nothing reads. - Fill gap g1 in
CountedCommit.cfg: replace the cap withVIEW Protocol. - Run the check again. Before you do, predict the distinct count: compare it with
TwoPhaseCommit.n3inspecs/.
The cfg has two witnesses. VotedThenAborted needs a participant's yes vote on the network when it learns of an abort, which a view that forgets the messages cannot tell apart from a participant that never voted.
Hints: HINTS.md, under "12-02-ex1 hint 1" to "hint 3". The solution is in solutions/chapters/12-state-space-and-evidence/exercises/02-ex1-the-counter-nobody-reads/; open it after you have a passing answer of your own.
If TLC finds no violation but an action never fires or a witness is not reached, ./tla prints "goal not met" and exits with code 1.
Done when: ./tla check 12-02-ex1 prints "goal met: pass".
./tla check 12-02-ex1
Repo chapters/12-state-space-and-evidence/exercises/02-ex1-the-counter-nobody-reads/
Hints
Hint 1
Which actions read ticks? Can the value of any invariant depend on it? If both answers are "no", two states that differ only in ticks have the same future and the same verdicts.
Hint 2
A view is a tuple of the variables TLC should compare. It is used in the cfg as VIEW Name, in place of the constraint.
Hint 3 (nearly the answer)
Protocol is a tuple of the three protocol variables of TwoPhaseCommit, and the cfg's gap becomes one VIEW line naming it.
12-02-ex2Core8 min
12-02-ex2 · What the view forgets
Tier: core. Time: about 8 minutes.
ReviewedBoard.tla is the task board with a reviewer, who may send a finished task back at most MaxReopens times. Two counters ride along: reopens, one per task, and clock, a step count for the dashboard. A teammate's CONSTRAINT ClockCap stops the check after one step.
- Run
./tla check 12-02-ex2and read the coverage gap. - Fill gap g1 in
ReviewedBoard.tla:BoardView, the tuple of variables TLC should compare. A variable may go only if nothing can tell two states apart by it: no guard, no update of another variable, no property. - Fill gap g1 in
ReviewedBoard.cfg: replace the cap withVIEW BoardView. - Run again. Then try the view without
reopensin a copy of the folder, and predict first what./tlawill say about the witnessSentBackToTheLimit.
The witness is the course's check of your view: it needs the reviewer to send one task back as often as the rule allows, which a view that forgets the wrong counter cannot reach.
Hints: HINTS.md, under "12-02-ex2 hint 1" to "hint 3". The solution is in solutions/chapters/12-state-space-and-evidence/exercises/02-ex2-what-the-view-forgets/.
If TLC finds no violation but an action never fires or a witness is not reached, ./tla prints "goal not met" and exits with code 1.
Done when: ./tla check 12-02-ex2 prints "goal met: pass".
./tla check 12-02-ex2
Repo chapters/12-state-space-and-evidence/exercises/02-ex2-what-the-view-forgets/
Hints
Hint 1
Go through the actions one by one and list every variable each one reads, in guards or on the right of an update. A variable on nobody's list can go.
Hint 2
clock is written everywhere and read nowhere. reopens is read by one guard. If you drop it, which states would TLC merge, and do they have the same futures?
Hint 3 (nearly the answer)
BoardView keeps three of the four variables: the two that describe each task's place on the board, and the counter that Reopen's guard reads.
06Explain it
Open NOTES.md and answer the three prompts under 12-02, about the Core exercise.
What I built, and why it is correct:
Which assumption, if false, breaks it:
What TLC did not check here:Compare your answers with "12-02 check your explanation" in HINTS.md.
After you writeCheck your explanation
A good answer: "BoardView keeps status, owner and reopens and drops clock, because no guard or update reads clock and the only property that mentions it, TypeOK's clock \in Nat, holds in every state, so states that differ only in it have the same futures and the same verdicts. It relies on nothing reading clock; a timeout rule that did would make the view hide behaviors. TLC checked one board of two workers, two tasks and two reopens per task, and the view says nothing about the dashboard that reads the clock."
A weak answer: "I removed the counters from the view, and when that failed I put one back." It does not say why reopens matters, so the next view will be a guess too.
Done?