Chapter

08

Messages in a world that loses them

Part II · Safety and the language

  • 5 lessons
  • 3 h 37 min of core lessons
  • Skills: hostile-env, abstraction

Lessons

About

The network loses messages, delivers some twice, and delivers others out of order. How do you model reordering without a line about it?

With a set. This chapter models a network as the set of messages in flight, and shows what that one choice gives you for free: every arrival order, duplicates whenever the receiver leaves a message in the set, and loss whenever it never takes one. You will see where a set is the wrong container, what a queue promises and what believing it costs, why the alternating bit protocol depends on that promise, and how an idempotent receiver turns "at least once" into the effect of "once".

Before you start

  • Chapters 05 to 07: sets, functions and EXCEPT, interleaving, and actions with parameters.
  • Chapter 03's habits: a witness and full coverage for every pass.
  • Time: the chapter page shows the estimate, generated from the lessons.

What else is here

  • specs/: ConfigPush, DepositLink, PingSet and PingBag, AlternatingBit, PaymentRetry, TaskBoard, and the variants the lessons run.
  • review/ (08-review): a teammate's order-tracking model.
  • ai/1-assumes-fifo/ (08-ai1): an agent's pull request on newsletter preferences.
  • ai/2-correct-dedup/ (08-ai2): an agent's deduplication of device events. Decide, with evidence, whether its claim holds.
  • gate/ (08-gate): notifications, delivered at least once and displayed once; gate/twin/ (08-gate-twin): sensor readings counted once. The skeletons supply the interface; you write everything else.

Run it

From the repository root:

shell
./tla check 08-01
./tla check 08-review
./tla check --gate 08

Skills

hostile-env (modelling a hostile environment), abstraction (choosing the abstraction).

Elsewhere

  • Web version: https://indicogni.com/learn/tla-plus/08-messages/
  • Recaps: CONCEPTS.md. Hints and explanation checks: HINTS.md. Predictions without answers: PREDICT.md.
  • Solutions: solutions/chapters/08-messages/, including the gate references and their mutants.
  • Further reading: the alternating bit protocol was introduced by K. A. Bartlett, R. A. Scantlebury and P. T. Wilkinson, "A note on reliable full-duplex transmission over half-duplex links", Communications of the ACM 12(5), 1969. This chapter's version, names and constants are the course's own.

Beyond the lessons

  • 08-review Review a teammate’s spec · chapters/08-messages/review/ · ./tla check 08-review
  • 08-ai1 AI item · chapters/08-messages/ai/1-assumes-fifo/ · ./tla check 08-ai1
  • 08-ai2 AI item · chapters/08-messages/ai/2-correct-dedup/ · ./tla check 08-ai2
  • 08-gate Gate · ./tla check --gate 08

    Hints

    Hint 1

    Write TypeOK and Init first, then Send and HandleAck, which each change one variable. Run your cfg after each action, and expect Deliver to need the most thought.

    Hint 2

    Nothing is ever taken out of net or acks. Deliver and Redeliver differ only in whether the phone has seen n. Deliver changes three variables. Redeliver writes only acks, and in every reachable state that leaves acks as it was, because the first acknowledgement is still there. Write every new value from unprimed values.

    Hint 3 (nearly the answer; opening it marks a pass as "passed with help")

    Safety has two halves, one per clause of the owner's sentence. The first is about shown. The second relates unacked and shown: when may a notification leave unacked?

  • 08-gate-twin Gate twin, another domain · ./tla check --gate 08 --twin

    Hints

    Hint 1

    Write TypeOK and Init first, then Transmit and Confirm, which each change one variable. Run your cfg after each action, and expect Store to need the most thought.

    Hint 2

    Nothing is ever taken out of uplink or confirms. Store and Reconfirm differ only in whether the collector has stored r. Store changes three variables. Reconfirm writes only confirms, and in every reachable state that leaves confirms as it was, because the first confirmation is still there. Write every new value from unprimed values.

    Hint 3 (nearly the answer; opening it marks a pass as "passed with help")

    Safety has two halves, one per clause of the operator's sentence. The first is about counted. The second relates outbox and counted: when may a reading leave the outbox?

  • CP2 Checkpoint CP2 follows this chapter: mixed items from every chapter so far, with no hints.