From 83f542f4a2833daedf8fb2792d0e9167583bed6b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 07:07:50 -0800 Subject: [PATCH 1/6] chore(quest): claim quest/m1/route-inductive.md Quest-Claim: 778a2e14d7634e53 From c5b34ac2eee79f7c5bc0d714a86eeac6aa4407d3 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 11:38:49 -0800 Subject: [PATCH 2/6] test(net): Apalache reads the route model but cannot step it The route spec carries Apalache's type annotations and its folds in place of RECURSIVE operators, so both tools read one file. TLC loads the folds from Apalache's library (nix/apalache.nix, the `tla` recipe) and finds the same distinct states on every exhaustive config. Apalache 0.63 runs out of memory on one step of the smallest mesh with a loop, so the inductive check stalls here; the quest records the measurements and the decision it needs. Co-Authored-By: Claude Opus 5.5 --- flake.nix | 4 + nix/apalache.nix | 39 ++++ quest/m1/route-inductive.md | 47 +++++ rs/justfile | 31 ++- rs/moq-net/verify/route/RouteHandoff.tla | 250 ++++++++++++++++------- 5 files changed, 295 insertions(+), 76 deletions(-) create mode 100644 nix/apalache.nix diff --git a/flake.nix b/flake.nix index c5f396ac3f7..d55b07228d8 100644 --- a/flake.nix +++ b/flake.nix @@ -602,6 +602,10 @@ # C++ dependency build out of the default shell and flake checks. moxygen = pkgs.callPackage ./nix/moxygen.nix { }; + # `just rs tla` and `just rs apalache`: nixpkgs has no Apalache. Kept + # out of the dev shell like the TLC the recipes fetch themselves. + apalache = pkgs.callPackage ./nix/apalache.nix { }; + runner-userns-profile = import ./nix/runner/unshare.nix { inherit pkgs; }; # Nightly's `just rs send-depth` proves native Send futures on it. diff --git a/nix/apalache.nix b/nix/apalache.nix new file mode 100644 index 00000000000..7ac58218b79 --- /dev/null +++ b/nix/apalache.nix @@ -0,0 +1,39 @@ +{ + lib, + stdenvNoCC, + fetchurl, + makeWrapper, + unzip, + jdk21_headless, +}: +# Apalache, the symbolic TLA+ model checker, which nixpkgs does not package. +# `share/tla` holds its `Apalache.tla`, whose folds TLC also evaluates, so a +# spec checked by both tools extends it under TLC too. +stdenvNoCC.mkDerivation (finalAttrs: { + pname = "apalache"; + version = "0.63.0"; + src = fetchurl { + url = "https://github.com/apalache-mc/apalache/releases/download/v${finalAttrs.version}/apalache-${finalAttrs.version}.tgz"; + hash = "sha256-p1bpavJJvzPNdilmeklHLLJqyCJ8SFg9oTm0FINNWd8="; + }; + nativeBuildInputs = [ + makeWrapper + unzip + ]; + installPhase = '' + runHook preInstall + install -Dm444 lib/apalache.jar $out/lib/apalache.jar + install -Dm555 bin/apalache-mc $out/bin/apalache-mc + wrapProgram $out/bin/apalache-mc --set JAVA_HOME ${jdk21_headless} --prefix PATH : ${jdk21_headless}/bin + mkdir -p $out/share/tla + unzip -p lib/apalache.jar tla2sany/StandardModules/Apalache.tla > $out/share/tla/Apalache.tla + runHook postInstall + ''; + meta = { + description = "Symbolic model checker for TLA+"; + homepage = "https://apalache-mc.org"; + license = lib.licenses.asl20; + mainProgram = "apalache-mc"; + platforms = lib.platforms.unix; + }; +}) diff --git a/quest/m1/route-inductive.md b/quest/m1/route-inductive.md index 7c3defcf326..225fc47f5da 100644 --- a/quest/m1/route-inductive.md +++ b/quest/m1/route-inductive.md @@ -62,8 +62,55 @@ stay constants the config states. Say both bounds in the `verify-route` skill. - Run it through the `tla` recipes with Apalache from the flake. If five relays does not fit Nightly, record the largest mesh that does and its time. +Found 2026-11-12, trying it on the route model itself +([moq-dev/moq#8564](https://github.com/moq-dev/moq/pull/8564)): + +- The spec there carries Apalache's type annotations and its folds in place + of `RECURSIVE` operators, and `just rs apalache typecheck + moq-net/verify/route/RouteHandoff.tla` passes. TLC reads the same file + through Apalache's library (`nix/apalache.nix`, the `tla` recipe) and finds + the same distinct states as before on every exhaustive config. +- No mesh fits. Apalache 0.63 could not finish one step with `SimplePaths` + as the only invariant, on a host with 16 GB of heap to give it: + + | Check | Mesh | Result | + | --- | --- | --- | + | One step from `Init`, all 7 transitions | publisher and 3 relays | out of heap after 26 minutes | + | One `Deliver` on one session, from any typed state | publisher and 3 relays | out of heap after 6 minutes | + | The same, `--smt-encoding=arrays` | publisher and 3 relays | still in its optimizer pass after 85 minutes | + | The same | publisher and 2 relays, the smallest mesh with a loop | past 19 GB in 8 minutes, killed | + +- Why: every step runs `Update`, which rebuilds a node's whole state, so the + solver encodes every neighbour's and key's route with its path, the views, + what the node sent, and its reader's events, for every step. That state, + not the invariant, is what does not fit. +- The rules split along the model. The claim rules (`Truthful`, + `NoRevival`, `NoFalseEnd`, `NoRegression`) need no paths: a view's floor + only grows while a route covers it, each floor is the publisher's claims at + its revision, and an item is the revision that set it. They should hold + however routes come and go, which is argued, not yet checked. The loop + rules (`SimplePaths`, `LoopsAreStale`, `StaleIsChased`) need routes, DEAD, + holds, and doubts, but no claims, views, or events. + Public API: none. Wire: none. +## Waiting + +- Maintainer: how to prove the rules for runs of any length, now that + Apalache cannot check the route model itself. Options: (A, recommended) + split it: this quest proves the claim rules on a small model whose routes + come and go freely, and a new quest proves the loop rules on a model + without claims after measuring that Apalache fits it, each tied to + `RouteHandoff.tla` by a refinement TLC checks on its configs; (B) a TLAPS + proof on the route model, rejected 2026-11-10 because its steps break on + each model change, which the router quest is still making; (C) delete the + quest and rest on TLC's bounded runs and the sweeps; (D) retry on a host + with far more memory, which the two-relay result above makes unlikely to + fit any useful mesh. A recommends itself because the claim rules are the + ones bounded runs cover least, and a model without paths should fit five + relays. An agent cannot pick: it changes the method the 2026-11-10 + decision chose. + ## Related - [Route sweeps are checked against the TLA+ model](/quest/m1/route-trace-validation.md) - ties the same spec to the code diff --git a/rs/justfile b/rs/justfile index a211ef3fdc3..3facee93f4a 100644 --- a/rs/justfile +++ b/rs/justfile @@ -20,8 +20,37 @@ default: # Model-check a TLA+ spec with TLC, e.g. `just rs tla moq-net/verify/route/RouteHandoff.tla`. # Pass `-config rs/.cfg` for a config not named after the spec. +[positional-arguments] tla spec *args: - nix shell --inputs-from . nixpkgs#tlaplus --command tlc -workers auto -cleanup -metadir "$(mktemp -d)" {{ args }} rs/{{ spec }} + #!/usr/bin/env bash + set -euo pipefail + root=$PWD + spec=rs/$1 + shift + args=() + while [ $# -gt 0 ]; do + case $1 in + -config) args+=("$1" "$(realpath "$2")"); shift 2 ;; + *) args+=("$1"); shift ;; + esac + done + # Apalache's library lends TLC the folds a spec Apalache also checks uses. + # TLC reads `TLA-Library` only for a spec named without a directory. + lib=$(nix build "$root#apalache" --no-link --print-out-paths)/share/tla + cd "$(dirname "$spec")" + export JAVA_TOOL_OPTIONS="-DTLA-Library=$lib" + exec nix shell --inputs-from "$root" nixpkgs#tlaplus --command tlc -workers auto -cleanup -metadir "$(mktemp -d)" "${args[@]}" "$(basename "$spec")" + +# Check a TLA+ spec with Apalache, e.g. `just rs apalache typecheck moq-net/verify/route/RouteHandoff.tla`. +# Its output goes to a temporary directory; set `JVM_ARGS=-Xmx16g` for a larger heap. +[positional-arguments] +apalache command spec *args: + #!/usr/bin/env bash + set -euo pipefail + command=$1 + spec=rs/$2 + shift 2 + exec nix shell .#apalache --command apalache-mc "$command" --out-dir="$(mktemp -d)" "$@" "$spec" # Prove a Tamarin model's lemmas, e.g. `just rs tamarin moq-net/verify/route-key/RouteKey.spthy`. # Pass `-D=` for a variant the model defines. diff --git a/rs/moq-net/verify/route/RouteHandoff.tla b/rs/moq-net/verify/route/RouteHandoff.tla index 9ec5db5494a..59bc54e7276 100644 --- a/rs/moq-net/verify/route/RouteHandoff.tla +++ b/rs/moq-net/verify/route/RouteHandoff.tla @@ -27,18 +27,49 @@ (* each opening is a new session with a new hop. A claim's attributes are *) (* the revision that last set them. *) (***************************************************************************) -EXTENDS Integers, Sequences, FiniteSets +EXTENDS Integers, Sequences, FiniteSets, Apalache + +(* Types, for Apalache: TLC ignores the annotations. *) +\* @typeAlias: hop = <>; +\* @typeAlias: path = Seq($hop); +\* @typeAlias: items = Str -> Int; +\* @typeAlias: heard = {on: Bool, path: $path, state: Str, rev: Int, items: $items}; +\* @typeAlias: route = {on: Bool, held: Bool, next: Int, path: $path}; +\* @typeAlias: sent = {on: Bool, held: Bool, path: $path, rev: Int, items: $items, src: Str}; +\* @typeAlias: view = {floor: Int, items: $items}; +\* @typeAlias: shown = {item: Int, avail: Bool}; +\* @typeAlias: node = {rx: Int -> Str -> $heard, rt: Str -> $route, view: Str -> $view, +\* dead: Set($hop), doubt: Set(Int), wait: Set(Int), tx: Int -> Str -> $sent, +\* told: Int -> Set($hop), shown: Str -> $shown}; +\* @typeAlias: msg = {t: Str, k: Str, path: $path, rev: Int, items: $items, hop: $hop, +\* moved: Set(<>), gone: Bool}; +\* @typeAlias: events = {ended: Str -> Int, revivals: Int, falseEnds: Int, regressions: Int, +\* unstable: Int}; +\* @typeAlias: update = {s: $node, out: Int -> Seq($msg), ev: $events, dead: Set($hop)}; +\* @typeAlias: ov = {rev: Int, items: $items}; +\* @typeAlias: rep = {on: Bool, hop: $hop}; +TypeAliases == TRUE CONSTANTS + \* @type: Set(Int); Nodes, \* relays and the publisher; ordered as `select` breaks ties + \* @type: Int; Origin, \* the publisher + \* @type: Set(Set(Int)); Links, \* sessions, as 2-element sets of nodes + \* @type: Set(Set(Int)); Dear, \* the links that cost 2; the rest cost 1 + \* @type: Set(Int); Scoped, \* relays that ask every neighbour for prefix "a" alone + \* @type: Set(Str); Claims, \* claim paths + \* @type: Set(Str); Narrow, \* the claims inside prefix "a" + \* @type: Int; MaxRev, \* the publisher's claim changes + \* @type: Int; MaxFlaps, \* session opens and closes + \* @type: Bool; Patient \* TRUE: a doubt lifts only once no DEAD about its node is in flight Relays == Nodes \ {Origin} @@ -52,6 +83,7 @@ Absent == -2 Keys == {"root", "a"} \* The keys in the order a node sends them in. +\* @type: Seq(Str); KeySeq == <<"root", "a">> \* Whether a route keyed `k` covers claim `c`. @@ -63,90 +95,130 @@ Ask(n) == IF n \in Scoped THEN "a" ELSE "root" \* The keys a stream to `p` carries. Streams(p) == IF p \in Scoped THEN {"a"} ELSE Keys +\* @type: $items; NoItems == [c \in Claims |-> None] +\* @type: ($items, Str) => $items; Restrict(items, k) == [c \in Claims |-> IF Covers(k, c) THEN items[c] ELSE None] +\* @type: $view; EmptyView == [floor |-> None, items |-> NoItems] +\* @type: $view; NoView == [floor |-> Absent, items |-> NoItems] \* A hop is <>: the node, and the session to `peer` of \* that generation it learned the route on. The publisher names itself. +\* @type: $hop; OHop == <> \* A route a neighbour offered (`Heard`). `state` is "live", "dead" (its path \* holds a hop this node knows is dead, and the neighbour has not said what \* became of it), or "held". +\* @type: $heard; NoHeard == [on |-> FALSE, path |-> <<>>, state |-> "live", rev |-> None, items |-> NoItems] \* The route a node uses for a key (`Route`). Held: no path, and `next` is the \* neighbour it holds under, or None on its own account. +\* @type: $route; NoRoute == [on |-> FALSE, held |-> FALSE, next |-> None, path |-> <<>>] \* What a node last sent a neighbour for a key (`Sent`). `src` is the key of \* the node's own route the offer reflects, kept after an end. +\* @type: (Str) => $sent; NoSent(k) == [on |-> FALSE, held |-> FALSE, path |-> <<>>, rev |-> None, items |-> NoItems, src |-> k] +\* @type: $shown; NotShown == [item |-> None, avail |-> FALSE] \* Messages: one record shape so TLC can compare them. +\* @type: $msg; Blank == [t |-> "", k |-> "root", path |-> <<>>, rev |-> None, items |-> NoItems, hop |-> OHop, moved |-> {}, gone |-> FALSE] +\* @type: (Str, $path) => $msg; OfferMsg(k, path) == [Blank EXCEPT !.t = "offer", !.k = k, !.path = path] +\* @type: (Str) => $msg; HoldMsg(k) == [Blank EXCEPT !.t = "hold", !.k = k] +\* @type: (Str) => $msg; EndMsg(k) == [Blank EXCEPT !.t = "end", !.k = k] +\* @type: (Str, $view) => $msg; ClaimsMsg(k, v) == [Blank EXCEPT !.t = "claims", !.k = k, !.rev = v.floor, !.items = v.items] +\* @type: ($hop, Set(<>), Bool) => $msg; DeadMsg(hop, moved, gone) == [Blank EXCEPT !.t = "dead", !.hop = hop, !.moved = moved, !.gone = gone] VARIABLES + \* @type: Set(Set(Int)); up, \* open sessions + \* @type: Set(Int) -> Int; gen, \* gen[l]: the generation of the session on link l + \* @type: <> -> Seq($msg); q, \* q[<>]: messages from m to n, in order + \* @type: Int; rev, \* the publisher's claim revision + \* @type: $items; own, \* the publisher's claims + \* @type: Seq($items); hist, \* hist[r + 1]: the publisher's claims at revision r + \* @type: Int -> $node; st, \* st[n]: node n's state for the publisher + \* @type: Int -> Str -> Int; ended, \* ended[n][c]: the item n's reader last saw END for, until n forgets c + \* @type: Int; revivals, \* reader STARTs of an item the reader saw END for + \* @type: Int; falseEnds, \* reader ENDs while the publisher still has that item + \* @type: Int; regressions, \* reader UPDATEs to an older item + \* @type: Int; unstable, \* claim changes a path change or a lifted doubt alone made + \* @type: Int -> Set($hop); learnt, \* learnt[n]: every hop n was ever told is dead + \* @type: Int; flaps, + \* @type: Int; burst, \* messages sent since the last quiet point + \* @type: Int; churn \* external changes since the last quiet point vars == <> Dirs == {<> \in Nodes \X Nodes : {m, n} \in Links} +\* @type: (Int, Set(Set(Int))) => Set(Int); Peers(n, ups) == {m \in Nodes : {n, m} \in ups} ----------------------------------------------------------------------------- (* Paths. *) +\* @type: ($path, Int) => Bool; Names(path, n) == \E i \in DOMAIN path : path[i][1] = n +\* @type: ($path, $hop) => Bool; HasHop(path, h) == \E i \in DOMAIN path : path[i] = h +\* @type: ($path, Set($hop)) => Bool; DeadIn(path, D) == \E i \in DOMAIN path : path[i] \in D \* The relay that offered `path` learned it from `n`. +\* @type: ($path, Int) => Bool; Child(path, n) == Len(path) >= 2 /\ path[Len(path) - 1][1] = n \* What the route costs the last node on its path. +\* @type: ($path) => Int; PathCost(path) == - LET F[i \in 0..Len(path)] == - IF i <= 1 THEN 0 ELSE F[i - 1] + Cost[{path[i - 1][1], path[i][1]}] - IN F[Len(path)] + ApaFoldSet(LAMBDA c, i : IF i = 1 THEN c ELSE c + Cost[{path[i - 1][1], path[i][1]}], + 0, DOMAIN path) +\* @type: ($route) => Bool; Live(r) == r.on /\ ~r.held ----------------------------------------------------------------------------- (* Selection on node n's state s (paths.rs: `select`, `pending`, `hopes`). *) +\* @type: ($node, $path) => Bool; Doubted(s, path) == \E i \in DOMAIN path : path[i][1] \in s.doubt \* A route a neighbour offered that this node may use: live, and its path does \* not name this node. +\* @type: (Int, $node, Int, Str) => Bool; Usable(n, s, m, k) == s.rx[m][k].on /\ s.rx[m][k].state = "live" /\ ~Names(s.rx[m][k].path, n) \* The key of this node's own route an offer of key k to p reflects. A stream \* to a scoped relay carries one route, "a": the node's route for "a" where it \* has a live one, else its root route, which covers "a". +\* @type: ($node, Int, Str) => Str; SrcKey(s, p, k) == IF p \notin Scoped THEN k ELSE IF Live(s.rt["a"]) THEN "a" @@ -154,6 +226,7 @@ SrcKey(s, p, k) == ELSE IF s.rt["a"].on THEN "a" ELSE "root" \* A neighbour that learned this node's route for k has yet to answer its loss. +\* @type: (Int, $node, Str) => Bool; Pending(n, s, k) == \E p \in Nodes : \E j \in Keys : /\ s.rx[p][j].on @@ -162,11 +235,13 @@ Pending(n, s, k) == /\ s.tx[p][j].src = k \* A neighbour offers a route that only doubt keeps this node off. +\* @type: (Int, $node, Str) => Bool; Hopes(n, s, k) == \E m \in Nodes : Usable(n, s, m, k) /\ Doubted(s, s.rx[m][k].path) \* `select` for one key: the cheapest usable route, staying on the next hop \* among equals, then the lowest key. Doubt keeps a node from moving to a route, \* not on the one it uses. With none left, hold or let go. +\* @type: (Int, $node, Str, Set(Int) -> Int) => $route; SelectKey(n, s, k, gens) == LET was == s.rt[k] current == IF was.on THEN was.next ELSE None @@ -188,10 +263,12 @@ SelectKey(n, s, k, gens) == ELSE [on |-> TRUE, held |-> TRUE, next |-> IF under THEN current ELSE None, path |-> <<>>] \* The publisher's own route covers everything. +\* @type: Str -> $route; OwnRoutes == [k \in Keys |-> IF k = "root" THEN [on |-> TRUE, held |-> FALSE, next |-> None, path |-> <>] ELSE NoRoute] +\* @type: (Int, $node, Set(Int) -> Int) => $node; Select(n, s, gens) == IF n = Origin THEN s ELSE [s EXCEPT !.rt = [k \in Keys |-> SelectKey(n, s, k, gens)]] @@ -200,12 +277,15 @@ Select(n, s, gens) == (* What a node knows of the claims: one view per key, the newest floor any *) (* route covering that key gave it, kept while it holds a covering route. *) +\* @type: ($node, Str) => Bool; Presence(s, k) == s.rt[k].on \/ (k = "a" /\ s.rt["root"].on) \* A route this node believes: live, and it did not cross this node. +\* @type: (Int, $node, Int, Str) => Bool; Believed(n, s, m, j) == s.rx[m][j].on /\ s.rx[m][j].state = "live" /\ ~Names(s.rx[m][j].path, n) +\* @type: (Int, $node, Str) => $view; NewView(n, s, k) == IF ~Presence(s, k) THEN NoView ELSE LET base == IF s.view[k].floor = Absent THEN EmptyView ELSE s.view[k] @@ -219,12 +299,14 @@ NewView(n, s, k) == ELSE [floor |-> s.rx[best[1]][best[2]].rev, items |-> Restrict(s.rx[best[1]][best[2]].items, k)] +\* @type: (Int, $node, $ov) => $node; Know(n, s, ov) == IF n = Origin THEN [s EXCEPT !.view = [k \in Keys |-> [floor |-> ov.rev, items |-> Restrict(ov.items, k)]]] ELSE [s EXCEPT !.view = [k \in Keys |-> NewView(n, s, k)]] \* How the reader sees each claim: from the narrowest key's view, available \* while a live route covers it. +\* @type: ($node) => Str -> $shown; ShownNow(s) == [c \in Claims |-> LET v == s.view[KeyOf(c)] IN @@ -238,6 +320,7 @@ ShownNow(s) == \* What this node wants a neighbour p to hold for key k: a path, a hold, an \* end, or to keep what it was sent while the next hop this node holds under \* waits for those behind it. +\* @type: (Int, $node, Str, Int) => {kind: Str, path: $path, src: Str}; Want(n, s, k, p) == LET src == SrcKey(s, p, k) r == s.rt[src] @@ -249,6 +332,7 @@ Want(n, s, k, p) == ELSE [kind |-> "hold", path |-> <<>>, src |-> src] \* `advertise` for one key on the stream to p. +\* @type: (Int, $node, Int, Str) => {tx: $sent, out: Seq($msg)}; Advertise1(n, s, p, k) == LET t == s.tx[p][k] w == Want(n, s, k, p) @@ -268,6 +352,7 @@ Advertise1(n, s, p, k) == out |-> (IF offer THEN <> ELSE <<>>) \o (IF claims THEN <> ELSE <<>>)] +\* @type: (Int, $node, Set(Set(Int))) => {s: $node, out: Int -> Seq($msg)}; Advertise(n, s, ups) == LET a == [p \in Peers(n, ups) |-> [k \in Keys |-> Advertise1(n, s, p, k)]] IN [s |-> [s EXCEPT !.tx = [p \in Nodes |-> @@ -275,15 +360,14 @@ Advertise(n, s, ups) == out |-> [p \in Nodes |-> IF p \in Peers(n, ups) THEN a[p]["root"].out \o a[p]["a"].out ELSE <<>>]] -\* Messages for the keys in `ks`, in key order. +\* The message f(k) for each key k in `ks`, in key order. +\* @type: (Set(Str), Str => $msg) => Seq($msg); Each(ks, f(_)) == - LET F[i \in 0..Len(KeySeq)] == - IF i = 0 THEN <<>> - ELSE F[i - 1] \o (IF KeySeq[i] \in ks THEN f(KeySeq[i]) ELSE <<>>) - IN F[Len(KeySeq)] + ApaFoldSeqLeft(LAMBDA out, k : IF k \in ks THEN Append(out, f(k)) ELSE out, <<>>, KeySeq) \* `report` to one neighbour p: what became of the routes this node sent it \* through `hop`, in one DEAD where it is the first word on that hop. +\* @type: (Int, $node, Int, $hop) => {tx: Str -> $sent, told: Set($hop), out: Seq($msg)}; Report1(n, s, p, hop) == LET t == s.tx[p] through == {k \in Keys : t[k].on /\ HasHop(t[k].path, hop)} @@ -305,13 +389,14 @@ Report1(n, s, p, hop) == out == IF first \/ (gone /\ ends # {}) THEN <> \o (IF gone THEN <<>> - ELSE Each(parents, LAMBDA k : <>) \o Each(ends, LAMBDA k : <>)) - ELSE Each({k \in through : w[k].kind = "path"}, LAMBDA k : <>) - \o Each(holds, LAMBDA k : <>) - \o Each(ends, LAMBDA k : <>) + ELSE Each(parents, HoldMsg) \o Each(ends, EndMsg)) + ELSE Each({k \in through : w[k].kind = "path"}, LAMBDA k : OfferMsg(k, w[k].path)) + \o Each(holds, HoldMsg) + \o Each(ends, EndMsg) IN IF through = {} THEN [tx |-> t, told |-> s.told[p], out |-> <<>>] ELSE [tx |-> tx1, told |-> s.told[p] \cup {hop}, out |-> out] +\* @type: (Int, $node, Set(Set(Int)), $hop) => {s: $node, out: Int -> Seq($msg)}; Report(n, s, ups, hop) == LET r == [p \in Peers(n, ups) |-> Report1(n, s, p, hop)] IN [s |-> [s EXCEPT !.tx = [p \in Nodes |-> IF p \in Peers(n, ups) THEN r[p].tx ELSE s.tx[p]], @@ -321,6 +406,7 @@ Report(n, s, ups, hop) == \* `collect`: forget each doubt no route names any more, each dead hop no route \* names once the timer it started has fired, and each told hop no route sent \* names. +\* @type: ($node) => $node; Collect(s) == LET heard == {s.rx[x[1]][x[2]].path : x \in {y \in Nodes \X Keys : s.rx[y[1]][y[2]].on}} IN [s EXCEPT @@ -334,6 +420,7 @@ Collect(s) == (* show. Returns the node's new state, its messages per neighbour, and its *) (* reader's events. *) +\* @type: $rep; NoReport == [on |-> FALSE, hop |-> OHop] \* The reader's events: changes to `ended` and the counters. A claim leaving @@ -341,6 +428,7 @@ NoReport == [on |-> FALSE, hop |-> OHop] \* `quiet` marks a step that only changed a path or lifted a doubt: in one, a \* claim the reader sees changes only to what a newer floor says, or goes \* offline after it was held unavailable. +\* @type: ($node, $node, Str -> $shown, Str -> $shown, $ov, Str -> Int, Bool) => $events; Events(s0, s, old, now, ov, eb, quiet) == LET present(c) == Presence(s, KeyOf(c)) isEnd(c) == old[c].item # None /\ now[c].item = None /\ present(c) @@ -359,6 +447,7 @@ Events(s0, s, old, now, ov, eb, quiet) == unstable |-> IF ~quiet THEN 0 ELSE Cardinality({c \in Claims : old[c].item # now[c].item /\ before(c) /\ ~newer(c) /\ ~release(c)})] +\* @type: (Int, $node, $ov, Set(Set(Int)), Set(Int) -> Int, Str -> Int, $rep, Bool) => $update; Update(n, s0, ov, ups, gens, eb, rep, quiet) == LET s1 == Select(n, s0, gens) s2 == Know(n, s1, ov) @@ -375,15 +464,15 @@ Update(n, s0, ov, ups, gens, eb, rep, quiet) == \* The publisher ignores every message it hears for its own route, so none is \* queued toward it. Dropping them changes no behaviour; `Budget` still counts them. +\* @type: (<>, $msg) => Bool; Heeded(d, m) == d[2] # Origin \* The sum of f(x) over the finite set S. -SumOver(S, f(_)) == - LET F[T \in SUBSET S] == IF T = {} THEN 0 ELSE LET x == CHOOSE x \in T : TRUE IN f(x) + F[T \ {x}] - IN F[S] +SumOver(S, f(_)) == ApaFoldSet(LAMBDA a, x : a + f(x), 0, S) \* Commit the updates `rs` (a function from nodes to `Update` results), appending \* each node's messages to `q0`. Nodes in one step send on disjoint queues. +\* @type: (Int -> $update, <> -> Seq($msg)) => Bool; Commit(rs, q0) == LET ns == DOMAIN rs Sum(f(_)) == SumOver(ns, f) @@ -401,15 +490,18 @@ Quiet == \A d \in Dirs : q[d] = <<>> NoDoubt == \A n \in Nodes : st[n].wait = {} \* The messages the updates `rs` send, counted before `Heeded` drops any. -Sent(rs) == SumOver(DOMAIN rs, LAMBDA n : SumOver(Nodes, LAMBDA m : Len(rs[n].out[m]))) +\* @type: (Int -> $update) => Int; +Sent(rs) == LET Out(n) == SumOver(Nodes, LAMBDA m : Len(rs[n].out[m])) IN SumOver(DOMAIN rs, Out) \* A burst runs from one quiet point to the next. An external change (a claim \* change, a session opening or closing) made while quiet starts a fresh one; \* every message sent in it counts against the changes made in it. +\* @type: (Int) => Bool; External(sent) == /\ burst' = (IF Quiet THEN 0 ELSE burst) + sent /\ churn' = (IF Quiet THEN 0 ELSE churn) + 1 +\* @type: (Int) => Bool; Internal(sent) == /\ burst' = burst + sent /\ UNCHANGED churn @@ -418,6 +510,7 @@ Internal(sent) == (* Initial state: every session open, the publisher's route sent and no *) (* claims yet. *) +\* @type: $node; InitNode == [ rx |-> [m \in Nodes |-> [k \in Keys |-> NoHeard]], rt |-> [k \in Keys |-> NoRoute], @@ -430,8 +523,10 @@ InitNode == [ shown |-> [c \in Claims |-> NotShown] ] +\* @type: $ov; OV0 == [rev |-> 0, items |-> NoItems] Gen0 == [l \in Links |-> 0] +\* @type: $update; Start == Update(Origin, [InitNode EXCEPT !.rt = OwnRoutes], OV0, Links, Gen0, [c \in Claims |-> None], NoReport, FALSE) @@ -453,11 +548,13 @@ Init == /\ burst = 0 /\ churn = 1 +\* @type: $ov; OV == [rev |-> rev, items |-> own] ----------------------------------------------------------------------------- (* The publisher changes a claim. *) +\* @type: (Str, Int) => Bool; ChangeClaim(c, item) == LET own1 == [own EXCEPT ![c] = item] ov1 == [rev |-> rev + 1, items |-> own1] @@ -478,6 +575,7 @@ Unannounce(c) == rev < MaxRev /\ own[c] # None /\ ChangeClaim(c, None) \* `fail`: the session `hop` names closed. `from` reported it with what became \* of its own routes through it, or this node saw it close (`from` is None). \* It casts doubt on the node at the session's far end, `hop[2]`. +\* @type: (Int, $node, $hop, Int, Set(<>), Bool) => $node; Fail(n, s, hop, from, moved, gone) == LET Moved(k) == {mv \in moved : mv[1] = k} rx1 == [p \in Nodes |-> [k \in Keys |-> @@ -495,6 +593,7 @@ Fail(n, s, hop, from, moved, gone) == IN [s EXCEPT !.rx = rx1, !.dead = @ \cup {hop}, !.doubt = @ \cup ({hop[2]} \ {n}), !.wait = @ \cup ({hop[2]} \ {n})] +\* @type: (Int, $node, Int, $msg) => $node; Recv(n, s, from, msg) == LET k == msg.k h == s.rx[from][k] @@ -510,6 +609,7 @@ Recv(n, s, from, msg) == IF h.on THEN [s EXCEPT !.rx[from][k].rev = msg.rev, !.rx[from][k].items = msg.items] ELSE s [] OTHER -> Fail(n, s, msg.hop, from, msg.moved, msg.gone) +\* @type: (<>) => Bool; Deliver(d) == LET m == d[1] n == d[2] @@ -528,6 +628,7 @@ Deliver(d) == \* whose session ended at x may be forgotten. With `Patient`, only once no DEAD \* about such a hop is in flight: a timer long enough for the news to cross \* the mesh. +\* @type: (Int, Int) => Bool; Lift(n, x) == LET rs == [y \in {n} |-> Update(n, [st[n] EXCEPT !.doubt = @ \ {x}, !.wait = @ \ {x}], OV, up, gen, ended[n], NoReport, TRUE)] @@ -541,16 +642,18 @@ Lift(n, x) == (* Sessions open and close. *) \* A closed session: everything learned or sent on it goes. +\* @type: ($node, Int) => $node; Closed(s, y) == [s EXCEPT !.rx[y] = [k \in Keys |-> NoHeard], !.tx[y] = [k \in Keys |-> NoSent(k)], !.told[y] = {}] +\* @type: (Set(Int)) => Bool; Connect(l) == LET up1 == up \cup {l} gen1 == [gen EXCEPT ![l] = @ + 1] rs == [x \in l |-> - LET y == CHOOSE y \in l : y # x + LET y == CHOOSE z \in l : z # x IN Update(x, Closed(st[x], y), OV, up1, gen1, ended[x], NoReport, FALSE)] IN /\ l \notin up /\ flaps < MaxFlaps @@ -562,11 +665,13 @@ Connect(l) == /\ UNCHANGED <> \* `disconnect`: each end names the hop it learned routes on there. +\* @type: (Set(Int)) => Bool; Disconnect(l) == LET up1 == up \ {l} q0 == [d \in Dirs |-> IF {d[1], d[2]} = l THEN <<>> ELSE q[d]] rs == [x \in l |-> - LET y == CHOOSE y \in l : y # x + LET y == CHOOSE z \in l : z # x + \* @type: $hop; hop == <> s == Closed(st[x], y) IN IF x = Origin @@ -635,23 +740,18 @@ Seen == (j = KeyOf(c) \/ j = "root") /\ Believed(n, st[n], m, j) => st[n].rx[m][j].rev <= v.floor -\* The loop-free paths from the publisher over the configured links, as the -\* nodes each crosses in order, and what each costs its last node. -RECURSIVE Extend(_, _) -Last(p) == p[Len(p)] -Extend(P, k) == - IF k = 0 THEN P - ELSE Extend(P \cup UNION {{Append(p, n) : n \in {m \in Relays : {Last(p), m} \in Links}} : p \in P}, k - 1) -Paths == - {p \in Extend({<>}, Cardinality(Relays)) : \A i, j \in DOMAIN p : i # j => p[i] # p[j]} - -NodesOf(path) == [i \in DOMAIN path |-> path[i][1]] +\* A loop-free path from the publisher to `from` over the configured links, +\* each hop naming the session it was learned on from the one before. +\* @type: (Int, $path) => Bool; IsPath(from, path) == /\ Len(path) >= 1 /\ path[1] = OHop - /\ NodesOf(path) \in Paths - /\ Last(NodesOf(path)) = from - /\ \A i \in DOMAIN path : i > 1 => path[i][2] = path[i - 1][1] + /\ path[Len(path)][1] = from + /\ \A i \in DOMAIN path : i > 1 => + /\ path[i][1] \in Relays + /\ path[i][2] = path[i - 1][1] + /\ {path[i - 1][1], path[i][1]} \in Links + /\ \A i, j \in DOMAIN path : i # j => path[i][1] # path[j][1] \* Every route held or in flight names a loop-free path from the publisher to \* its sender. @@ -662,43 +762,41 @@ SimplePaths == /\ q[d][i].t = "dead" => \A mv \in q[d][i].moved : IsPath(d[1], mv[2]) \* A hop whose session has closed: the link is down or opened again since. +\* @type: ($hop) => Bool; Gone(h) == h # OHop /\ ({h[1], h[2]} \notin up \/ gen[{h[1], h[2]}] # h[3]) +\* @type: ($path) => Bool; Stale(path) == \E i \in DOMAIN path : Gone(path[i]) \* Where a request for a claim goes. A node starts it on the narrowest live \* route covering the claim; each node forwards it on the route it offered the \* node it came from under that key, and never along a route whose path names -\* that node. The result is "origin", "stuck", "refused", or "loop". -RECURSIVE Fwd(_, _, _, _) -Fwd(cur, k, prev, i) == - IF cur = Origin THEN "origin" - ELSE IF i = 0 THEN "loop" - ELSE LET src == IF prev = None THEN k ELSE SrcKey(st[cur], prev, k) - r == st[cur].rt[src] - IN IF ~Live(r) THEN "stuck" - ELSE IF prev # None /\ Names(r.path, prev) THEN "refused" - ELSE Fwd(r.next, src, cur, i - 1) - -Request(n, c) == - Fwd(n, IF c \in Narrow /\ Live(st[n].rt["a"]) THEN "a" ELSE "root", None, Cardinality(Nodes)) - -\* The nodes a request from n for c crosses before it reaches the publisher, -\* stops, or has crossed every node. -RECURSIVE Walk(_, _, _, _) -Walk(cur, k, prev, i) == - IF cur = Origin \/ i = 0 THEN <<>> - ELSE LET src == IF prev = None THEN k ELSE SrcKey(st[cur], prev, k) - r == st[cur].rt[src] - IN IF ~Live(r) \/ (prev # None /\ Names(r.path, prev)) THEN <<>> - ELSE <<[node |-> cur, path |-> r.path]>> \o Walk(r.next, src, cur, i - 1) +\* that node. The result is "origin", "stuck", "refused", or "loop", once it +\* has crossed every node; `stale` says whether a node it crossed forwarded it +\* on a stale route. +\* @type: {cur: Int, k: Str, prev: Int, res: Str, stale: Bool} => {cur: Int, k: Str, prev: Int, res: Str, stale: Bool}; +Fwd(w) == + IF w.res # "" THEN w + ELSE IF w.cur = Origin THEN [w EXCEPT !.res = "origin"] + ELSE LET src == IF w.prev = None THEN w.k ELSE SrcKey(st[w.cur], w.prev, w.k) + r == st[w.cur].rt[src] + IN IF ~Live(r) THEN [w EXCEPT !.res = "stuck"] + ELSE IF w.prev # None /\ Names(r.path, w.prev) THEN [w EXCEPT !.res = "refused"] + ELSE [cur |-> r.next, k |-> src, prev |-> w.cur, res |-> "", stale |-> w.stale \/ Stale(r.path)] + +Walk(n, c) == + LET k == IF c \in Narrow /\ Live(st[n].rt["a"]) THEN "a" ELSE "root" + w == ApaFoldSet(LAMBDA x, i : Fwd(x), + [cur |-> n, k |-> k, prev |-> None, res |-> "", stale |-> FALSE], Nodes) + IN IF w.res # "" THEN w + ELSE [w EXCEPT !.res = IF w.cur = Origin THEN "origin" ELSE "loop"] + +Request(n, c) == Walk(n, c).res \* A request that loops crosses a node whose route is stale: it names a \* session that has closed, whose news has yet to reach that node. LoopsAreStale == \A n \in Relays, c \in Claims : - (Live(st[n].rt["root"]) \/ Live(st[n].rt["a"])) /\ Request(n, c) = "loop" => - LET w == Walk(n, IF c \in Narrow /\ Live(st[n].rt["a"]) THEN "a" ELSE "root", None, Cardinality(Nodes)) - IN \E i \in DOMAIN w : Stale(w[i].path) + (Live(st[n].rt["root"]) \/ Live(st[n].rt["a"])) /\ Request(n, c) = "loop" => Walk(n, c).stale \* A request never loops. It does while news is in flight: `Loop.cfg` pins it. RequestsLoopFree == \A n \in Relays, c \in Claims : Request(n, c) # "loop" @@ -712,30 +810,32 @@ NoStaleReturn == \* Whether the news that ends a stale route node n heard from m under key k is \* on its way: queued from m to n, or m's own route is stale and its news is -\* on its way to m. -RECURSIVE Chased(_, _, _, _) -Chased(n, m, k, i) == - \/ q[<>] # <<>> - \/ /\ i > 0 - /\ m # Origin - /\ LET src == SrcKey(st[m], n, k) - r == st[m].rt[src] - IN /\ Live(r) - /\ Stale(r.path) - /\ Chased(m, r.next, src, i - 1) +\* on its way to m, and so on back, over at most every node. +\* @type: {n: Int, m: Int, k: Str, res: Str} => {n: Int, m: Int, k: Str, res: Str}; +Chase(w) == + IF w.res # "" THEN w + ELSE IF q[<>] # <<>> THEN [w EXCEPT !.res = "yes"] + ELSE IF w.m = Origin THEN [w EXCEPT !.res = "no"] + ELSE LET src == SrcKey(st[w.m], w.n, w.k) + r == st[w.m].rt[src] + IN IF Live(r) /\ Stale(r.path) THEN [n |-> w.m, m |-> r.next, k |-> src, res |-> ""] + ELSE [w EXCEPT !.res = "no"] + +Chased(n, m, k) == + LET w == ApaFoldSet(LAMBDA x, i : Chase(x), [n |-> n, m |-> m, k |-> k, res |-> ""], Nodes) + IN w.res = "yes" \/ (w.res = "" /\ q[<>] # <<>>) \* A stale route a node may use always has the news that ends it on its way, \* so it lasts no longer than that news takes to arrive. StaleIsChased == \A n \in Relays, m \in Nodes, k \in Keys : - Usable(n, st[n], m, k) /\ Stale(st[n].rx[m][k].path) => Chased(n, m, k, Cardinality(Nodes)) + Usable(n, st[n], m, k) /\ Stale(st[n].rx[m][k].path) => Chased(n, m, k) \* The nodes a path over open sessions from the publisher reaches, through \* nodes whose interest covers claim c. -RECURSIVE Grow(_, _, _) -Grow(R, c, i) == IF i = 0 THEN R - ELSE Grow(R \cup {n \in Relays : Covers(Ask(n), c) /\ \E m \in R : {m, n} \in up}, c, i - 1) -Carried(c) == Grow({Origin}, c, Cardinality(Nodes)) +Carried(c) == + ApaFoldSet(LAMBDA R, i : R \cup {n \in Relays : Covers(Ask(n), c) /\ \E m \in R : {m, n} \in up}, + {Origin}, Nodes) \* Once nothing is in flight and no doubt is left: each relay shows exactly the \* publisher's claims that a path carries to it, available; a request for each From a4306e659b55438c689d6f61f7feace9fb171cc2 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 14:06:41 -0800 Subject: [PATCH 3/6] wip(net): a claims model with no paths, refined by the route model --- rs/moq-net/verify/route/RouteClaims.tla | 303 +++++++++++++++++++++++ rs/moq-net/verify/route/RouteHandoff.tla | 291 +++++++++------------- 2 files changed, 419 insertions(+), 175 deletions(-) create mode 100644 rs/moq-net/verify/route/RouteClaims.tla diff --git a/rs/moq-net/verify/route/RouteClaims.tla b/rs/moq-net/verify/route/RouteClaims.tla new file mode 100644 index 00000000000..de26f09423d --- /dev/null +++ b/rs/moq-net/verify/route/RouteClaims.tla @@ -0,0 +1,303 @@ +---------------------------- MODULE RouteClaims ---------------------------- +(***************************************************************************) +(* What RouteHandoff.tla's relays show their readers, with no paths: on *) +(* every step, any relay's routes may come and go as they like. A relay *) +(* hears a route per neighbour and key, believed or not, and holds a route *) +(* of its own per key, live, held, or none. The claims a node sends may *) +(* reach any relay, in any order, any number of times, or never. *) +(* *) +(* RouteHandoff refines this model (its `RefinesClaims`), so the claim *) +(* rules here hold there too. Apalache checks that `IndInv` holds at *) +(* `Init` and that every step keeps it, so they hold for runs of any *) +(* length: revisions, sessions, and route changes are unbounded. *) +(***************************************************************************) +EXTENDS Integers, FiniteSets, Apalache + +CONSTANTS + \* @type: Set(Int); + Nodes, \* relays and the publisher + \* @type: Int; + Origin, \* the publisher + \* @type: Set(Str); + Claims, \* claim paths + \* @type: Set(Str); + Narrow, \* the claims inside prefix "a" + \* @type: Int; + MaxFlight \* `IndInit` only: the claims messages in flight + +\* Apalache's names for the records below. +\* @typeAlias: floor = { rev: Int, items: Str -> Int }; +\* @typeAlias: view = { floor: Int, items: Str -> Int }; +\* @typeAlias: msg = { k: Str, rev: Int, items: Str -> Int }; +\* @typeAlias: shown = { item: Int, avail: Bool }; +\* Every relay's state is one function keyed by relay first, since Apalache +\* cannot pick a function of functions. +\* @typeAlias: heard = <> -> Str; +\* @typeAlias: offered = <> -> $floor; +\* @typeAlias: route = <> -> Str; +\* @typeAlias: views = <> -> $view; +RouteClaims_aliases == TRUE + +Relays == Nodes \ {Origin} + +\* A claim's item, the revision that last set it, or None when absent. +None == -1 +\* A view's floor: a revision, None for no floor yet, or Absent for no view. +Absent == -2 + +Keys == {"root", "a"} +\* @type: (Str, Str) => Bool; +Covers(k, c) == k = "root" \/ c \in Narrow +\* @type: Str => Str; +KeyOf(c) == IF c \in Narrow THEN "a" ELSE "root" + +NoItems == [c \in Claims |-> None] +\* @type: (Str -> Int, Str) => Str -> Int; +Restrict(items, k) == [c \in Claims |-> IF Covers(k, c) THEN items[c] ELSE None] +NoFloor == [rev |-> None, items |-> NoItems] +EmptyView == [floor |-> None, items |-> NoItems] +NoView == [floor |-> Absent, items |-> NoItems] +NotShown == [item |-> None, avail |-> FALSE] + +\* What a relay heard from a neighbour for a key: nothing, a route it +\* believes, or one it does not (held, dead, or through itself). +Hearings == {"off", "live", "doubt"} +\* The route a relay uses for a key. +Routings == {"none", "held", "live"} + +\* @type: Set(<>); +HeardIdx == Relays \X Nodes \X Keys +\* @type: Set(<>); +KeyIdx == Relays \X Keys +\* @type: Set(<>); +ClaimIdx == Relays \X Claims + +VARIABLES + \* @type: Int; + rev, \* the publisher's claim revision + \* @type: Str -> Int; + own, \* the publisher's claims + \* @type: Int -> (Str -> Int); + hist, \* hist[r]: the publisher's claims at revision r, for each r the state names + \* @type: $heard; + heard, \* heard[<>]: the route n heard from m for key k + \* @type: $offered; + offered, \* offered[<>]: the floor that route last gave n + \* @type: $route; + route, \* route[<>]: the route n uses for key k + \* @type: $views; + view, \* view[<>]: the newest floor a route covering k gave n + \* @type: <> -> $shown; + shown, \* shown[<>]: what n's reader sees of claim c + \* @type: <> -> Int; + ended, \* ended[<>]: the item n's reader last saw END for, until n forgets c + \* @type: Set($msg); + flight, \* the claims messages in flight + \* @type: Int; + revivals, \* reader STARTs of an item the reader saw END for + \* @type: Int; + falseEnds, \* reader ENDs while the publisher still has that item + \* @type: Int; + regressions \* reader UPDATEs to an older item + +vars == <> + +----------------------------------------------------------------------------- +(* What a relay shows, as RouteHandoff's `Know`, `ShownNow`, and `Events`. *) + +\* @type: ($route, Int, Str) => Bool; +Presence(rt, n, k) == rt[<>] # "none" \/ (k = "a" /\ rt[<>] # "none") + +\* Relay n's view for key k: the newest floor a believed route covering k +\* gave, kept while n holds a route covering k. +\* @type: ($heard, $offered, $route, $views, Int, Str) => $view; +NewView(hd, of, rt, vw, n, k) == + IF ~Presence(rt, n, k) THEN NoView + ELSE LET \* @type: ($view, <>) => $view; + Newer(v, x) == + IF hd[x] = "live" /\ of[x].rev > v.floor + THEN [floor |-> of[x].rev, items |-> Restrict(of[x].items, k)] + ELSE v + IN ApaFoldSet(Newer, IF vw[<>].floor = Absent THEN EmptyView ELSE vw[<>], + {n} \X Nodes \X {k, "root"}) + +\* What relay n's reader sees of claim c. +\* @type: ($route, $views, Int, Str) => $shown; +ShownNow(rt, vw, n, c) == + LET v == vw[<>] IN + IF v.floor = Absent \/ v.items[c] = None THEN NotShown + ELSE [item |-> v.items[c], + avail |-> rt[<>] = "live" \/ (c \in Narrow /\ rt[<>] = "live")] + +\* What node n sends: its view per key, or the publisher's claims. +\* @type: (Int, Int, Str -> Int, $views) => Set($msg); +Sends(n, rv, ow, vw) == + IF n = Origin THEN {[k |-> k, rev |-> rv, items |-> Restrict(ow, k)] : k \in Keys} + ELSE {[k |-> k, rev |-> IF vw[<>].floor = Absent THEN None ELSE vw[<>].floor, + items |-> vw[<>].items] : k \in Keys} + +\* The revisions the state names: the publisher's, and every floor's. +\* @type: (Int, $offered, $views, Set($msg)) => Set(Int); +Refs(rv, of, vw, fl) == + {r \in {rv} + \cup {vw[x].floor : x \in KeyIdx} + \cup {of[x].rev : x \in HeardIdx} + \cup {y.rev : y \in fl} : r >= 0} + +----------------------------------------------------------------------------- +(* The publisher's claims and every relay's routes start empty; the *) +(* publisher's first claims may be in flight. *) + +Init == + /\ rev = 0 + /\ own = NoItems + /\ hist = [r \in {0} |-> NoItems] + /\ heard = [x \in HeardIdx |-> "off"] + /\ offered = [x \in HeardIdx |-> NoFloor] + /\ route = [x \in KeyIdx |-> "none"] + /\ view = [x \in KeyIdx |-> NoView] + /\ shown = [x \in ClaimIdx |-> NotShown] + /\ ended = [x \in ClaimIdx |-> None] + /\ flight \in SUBSET Sends(Origin, 0, NoItems, view) + /\ revivals = 0 + /\ falseEnds = 0 + /\ regressions = 0 + +\* The publisher keeps its claims or changes one. +Publish == + \/ rev' = rev /\ own' = own + \/ \E c \in Claims, item \in {rev + 1, None} : + /\ item = None => own[c] # None + /\ rev' = rev + 1 + /\ own' = [own EXCEPT ![c] = item] + +\* One step: the publisher may change a claim, and every relay's routes may +\* change. A route that stays on may take any claims in flight to it under +\* its key; one that turns on or off has no floor. Every relay then updates +\* its views and shows its reader the difference, and every node may send +\* its views, while any message in flight may be lost. +Next == + /\ Publish + /\ heard' \in [HeardIdx -> Hearings] + /\ route' \in [KeyIdx -> Routings] + /\ LET arrived == {[rev |-> y.rev, items |-> y.items] : y \in flight} + pool == {NoFloor} \cup arrived \cup {offered[x] : x \in HeardIdx} + IN /\ offered' \in [HeardIdx -> pool] + /\ \A x \in HeardIdx : + IF heard[x] = "off" \/ heard'[x] = "off" + THEN offered'[x] = NoFloor + ELSE \/ offered'[x] = offered[x] + \/ \E y \in flight : + y.k = x[3] /\ offered'[x] = [rev |-> y.rev, items |-> y.items] + /\ view' = [x \in KeyIdx |-> NewView(heard', offered', route', view, x[1], x[2])] + /\ shown' = [x \in ClaimIdx |-> ShownNow(route', view', x[1], x[2])] + /\ LET \* @type: (<>) => Bool; + present(x) == Presence(route', x[1], KeyOf(x[2])) + \* @type: (<>) => Bool; + isEnd(x) == shown[x].item # None /\ shown'[x].item = None /\ present(x) + \* @type: (<>) => Bool; + isStart(x) == shown[x].item = None /\ shown'[x].item # None + \* @type: (<>) => Bool; + isUpdate(x) == shown[x].item # None /\ shown'[x].item # None /\ shown[x].item # shown'[x].item + IN /\ ended' = [x \in ClaimIdx |-> + IF isEnd(x) THEN shown[x].item + ELSE IF present(x) THEN ended[x] ELSE None] + /\ revivals' = revivals + Cardinality({x \in ClaimIdx : isStart(x) /\ ended[x] = shown'[x].item}) + /\ falseEnds' = falseEnds + Cardinality({x \in ClaimIdx : isEnd(x) /\ own'[x[2]] = shown[x].item}) + /\ regressions' = regressions + Cardinality({x \in ClaimIdx : isUpdate(x) /\ shown'[x].item < shown[x].item}) + /\ flight' \in SUBSET (flight \cup UNION {Sends(n, rev', own', view') : n \in Nodes}) + /\ hist' = [r \in Refs(rev', offered', view', flight') |-> IF r = rev' THEN own' ELSE hist[r]] + +Spec == Init /\ [][Next]_vars + +----------------------------------------------------------------------------- +(* Rules, as RouteHandoff states them. *) + +\* Every floor a relay keeps or was offered is the publisher's claims at that +\* revision, within its key. +Truthful == + /\ \A x \in KeyIdx : view[x].floor >= 0 => + view[x].items = Restrict(hist[view[x].floor], x[2]) + /\ \A x \in HeardIdx : heard[x] # "off" /\ offered[x].rev >= 0 => + offered[x].items = Restrict(hist[offered[x].rev], x[3]) + +\* A reader never sees a broadcast start again after it saw it end. +NoRevival == revivals = 0 + +\* A reader never sees a broadcast end while the publisher still has it. +NoFalseEnd == falseEnds = 0 + +\* A reader never sees an older version replace a newer one. +NoRegression == regressions = 0 + +----------------------------------------------------------------------------- +(* The inductive invariant. A floor only grows while a route covers it, *) +(* each floor is the publisher's claims at its revision, and an item is *) +(* the revision that set it, so a newer floor never names an older item. *) + +\* A floor: None with no items, or a revision the publisher has passed with +\* its claims then, within key k. +\* @type: (Str, Int, Str -> Int) => Bool; +Sound(k, r, items) == + \/ r = None /\ items = NoItems + \/ /\ 0 <= r /\ r <= rev + /\ r \in DOMAIN hist + /\ items = Restrict(hist[r], k) + +IndInv == + /\ Truthful + /\ NoRevival + /\ NoFalseEnd + /\ NoRegression + \* The history: an item is the revision that set it, and it stays set + \* until a later revision changes it. + /\ rev >= 0 + /\ DOMAIN hist = Refs(rev, offered, view, flight) + /\ hist[rev] = own + /\ \A r \in DOMAIN hist, c \in Claims : + hist[r][c] = None \/ (1 <= hist[r][c] /\ hist[r][c] <= r) + /\ \A r1, r2 \in DOMAIN hist, c \in Claims : + r1 <= r2 /\ hist[r2][c] # None /\ hist[r2][c] <= r1 => hist[r1][c] = hist[r2][c] + \* Every floor is sound, and a route that is off gave none. + /\ \A y \in flight : y.k \in Keys /\ Sound(y.k, y.rev, y.items) + /\ \A x \in HeardIdx : + /\ Sound(x[3], offered[x].rev, offered[x].items) + /\ heard[x] = "off" => offered[x] = NoFloor + \* A relay keeps a view exactly while it holds a route covering it. + /\ \A x \in KeyIdx : + IF Presence(route, x[1], x[2]) THEN Sound(x[2], view[x].floor, view[x].items) + ELSE view[x] = NoView + /\ \A x \in ClaimIdx : shown[x] = ShownNow(route, view, x[1], x[2]) + \* What the reader saw end is older than the view, which no longer has it. + /\ \A x \in ClaimIdx : + ended[x] # None => + LET v == view[<>] IN + /\ Presence(route, x[1], KeyOf(x[2])) + /\ 1 <= ended[x] /\ ended[x] <= v.floor + /\ v.items[x[2]] # ended[x] + +\* Any state of the right shape where `IndInv` holds, with up to `MaxFlight` +\* claims messages in flight. +IndInit == + /\ rev \in Int + /\ own \in [Claims -> Int] + /\ heard \in [HeardIdx -> Hearings] + /\ route \in [KeyIdx -> Routings] + /\ \E r \in [HeardIdx -> Int], i \in [HeardIdx \X Claims -> Int] : + offered = [x \in HeardIdx |-> [rev |-> r[x], items |-> [c \in Claims |-> i[<>]]]] + /\ \E f \in [KeyIdx -> Int], i \in [KeyIdx \X Claims -> Int] : + view = [x \in KeyIdx |-> [floor |-> f[x], items |-> [c \in Claims |-> i[<>]]]] + /\ \E i \in [ClaimIdx -> Int], a \in [ClaimIdx -> BOOLEAN] : + shown = [x \in ClaimIdx |-> [item |-> i[x], avail |-> a[x]]] + /\ ended \in [ClaimIdx -> Int] + /\ flight = Gen(MaxFlight) + /\ \A y \in flight : DOMAIN y.items = Claims + /\ \E i \in [Refs(rev, offered, view, flight) \X Claims -> Int] : + hist = [r \in Refs(rev, offered, view, flight) |-> [c \in Claims |-> i[<>]]] + /\ revivals \in Int + /\ falseEnds \in Int + /\ regressions \in Int + /\ IndInv + +============================================================================= diff --git a/rs/moq-net/verify/route/RouteHandoff.tla b/rs/moq-net/verify/route/RouteHandoff.tla index 59bc54e7276..dbaa981e73c 100644 --- a/rs/moq-net/verify/route/RouteHandoff.tla +++ b/rs/moq-net/verify/route/RouteHandoff.tla @@ -27,49 +27,18 @@ (* each opening is a new session with a new hop. A claim's attributes are *) (* the revision that last set them. *) (***************************************************************************) -EXTENDS Integers, Sequences, FiniteSets, Apalache - -(* Types, for Apalache: TLC ignores the annotations. *) -\* @typeAlias: hop = <>; -\* @typeAlias: path = Seq($hop); -\* @typeAlias: items = Str -> Int; -\* @typeAlias: heard = {on: Bool, path: $path, state: Str, rev: Int, items: $items}; -\* @typeAlias: route = {on: Bool, held: Bool, next: Int, path: $path}; -\* @typeAlias: sent = {on: Bool, held: Bool, path: $path, rev: Int, items: $items, src: Str}; -\* @typeAlias: view = {floor: Int, items: $items}; -\* @typeAlias: shown = {item: Int, avail: Bool}; -\* @typeAlias: node = {rx: Int -> Str -> $heard, rt: Str -> $route, view: Str -> $view, -\* dead: Set($hop), doubt: Set(Int), wait: Set(Int), tx: Int -> Str -> $sent, -\* told: Int -> Set($hop), shown: Str -> $shown}; -\* @typeAlias: msg = {t: Str, k: Str, path: $path, rev: Int, items: $items, hop: $hop, -\* moved: Set(<>), gone: Bool}; -\* @typeAlias: events = {ended: Str -> Int, revivals: Int, falseEnds: Int, regressions: Int, -\* unstable: Int}; -\* @typeAlias: update = {s: $node, out: Int -> Seq($msg), ev: $events, dead: Set($hop)}; -\* @typeAlias: ov = {rev: Int, items: $items}; -\* @typeAlias: rep = {on: Bool, hop: $hop}; -TypeAliases == TRUE +EXTENDS Integers, Sequences, FiniteSets CONSTANTS - \* @type: Set(Int); Nodes, \* relays and the publisher; ordered as `select` breaks ties - \* @type: Int; Origin, \* the publisher - \* @type: Set(Set(Int)); Links, \* sessions, as 2-element sets of nodes - \* @type: Set(Set(Int)); Dear, \* the links that cost 2; the rest cost 1 - \* @type: Set(Int); Scoped, \* relays that ask every neighbour for prefix "a" alone - \* @type: Set(Str); Claims, \* claim paths - \* @type: Set(Str); Narrow, \* the claims inside prefix "a" - \* @type: Int; MaxRev, \* the publisher's claim changes - \* @type: Int; MaxFlaps, \* session opens and closes - \* @type: Bool; Patient \* TRUE: a doubt lifts only once no DEAD about its node is in flight Relays == Nodes \ {Origin} @@ -83,7 +52,6 @@ Absent == -2 Keys == {"root", "a"} \* The keys in the order a node sends them in. -\* @type: Seq(Str); KeySeq == <<"root", "a">> \* Whether a route keyed `k` covers claim `c`. @@ -95,130 +63,90 @@ Ask(n) == IF n \in Scoped THEN "a" ELSE "root" \* The keys a stream to `p` carries. Streams(p) == IF p \in Scoped THEN {"a"} ELSE Keys -\* @type: $items; NoItems == [c \in Claims |-> None] -\* @type: ($items, Str) => $items; Restrict(items, k) == [c \in Claims |-> IF Covers(k, c) THEN items[c] ELSE None] -\* @type: $view; EmptyView == [floor |-> None, items |-> NoItems] -\* @type: $view; NoView == [floor |-> Absent, items |-> NoItems] \* A hop is <>: the node, and the session to `peer` of \* that generation it learned the route on. The publisher names itself. -\* @type: $hop; OHop == <> \* A route a neighbour offered (`Heard`). `state` is "live", "dead" (its path \* holds a hop this node knows is dead, and the neighbour has not said what \* became of it), or "held". -\* @type: $heard; NoHeard == [on |-> FALSE, path |-> <<>>, state |-> "live", rev |-> None, items |-> NoItems] \* The route a node uses for a key (`Route`). Held: no path, and `next` is the \* neighbour it holds under, or None on its own account. -\* @type: $route; NoRoute == [on |-> FALSE, held |-> FALSE, next |-> None, path |-> <<>>] \* What a node last sent a neighbour for a key (`Sent`). `src` is the key of \* the node's own route the offer reflects, kept after an end. -\* @type: (Str) => $sent; NoSent(k) == [on |-> FALSE, held |-> FALSE, path |-> <<>>, rev |-> None, items |-> NoItems, src |-> k] -\* @type: $shown; NotShown == [item |-> None, avail |-> FALSE] \* Messages: one record shape so TLC can compare them. -\* @type: $msg; Blank == [t |-> "", k |-> "root", path |-> <<>>, rev |-> None, items |-> NoItems, hop |-> OHop, moved |-> {}, gone |-> FALSE] -\* @type: (Str, $path) => $msg; OfferMsg(k, path) == [Blank EXCEPT !.t = "offer", !.k = k, !.path = path] -\* @type: (Str) => $msg; HoldMsg(k) == [Blank EXCEPT !.t = "hold", !.k = k] -\* @type: (Str) => $msg; EndMsg(k) == [Blank EXCEPT !.t = "end", !.k = k] -\* @type: (Str, $view) => $msg; ClaimsMsg(k, v) == [Blank EXCEPT !.t = "claims", !.k = k, !.rev = v.floor, !.items = v.items] -\* @type: ($hop, Set(<>), Bool) => $msg; DeadMsg(hop, moved, gone) == [Blank EXCEPT !.t = "dead", !.hop = hop, !.moved = moved, !.gone = gone] VARIABLES - \* @type: Set(Set(Int)); up, \* open sessions - \* @type: Set(Int) -> Int; gen, \* gen[l]: the generation of the session on link l - \* @type: <> -> Seq($msg); q, \* q[<>]: messages from m to n, in order - \* @type: Int; rev, \* the publisher's claim revision - \* @type: $items; own, \* the publisher's claims - \* @type: Seq($items); hist, \* hist[r + 1]: the publisher's claims at revision r - \* @type: Int -> $node; st, \* st[n]: node n's state for the publisher - \* @type: Int -> Str -> Int; ended, \* ended[n][c]: the item n's reader last saw END for, until n forgets c - \* @type: Int; revivals, \* reader STARTs of an item the reader saw END for - \* @type: Int; falseEnds, \* reader ENDs while the publisher still has that item - \* @type: Int; regressions, \* reader UPDATEs to an older item - \* @type: Int; unstable, \* claim changes a path change or a lifted doubt alone made - \* @type: Int -> Set($hop); learnt, \* learnt[n]: every hop n was ever told is dead - \* @type: Int; flaps, - \* @type: Int; burst, \* messages sent since the last quiet point - \* @type: Int; churn \* external changes since the last quiet point vars == <> Dirs == {<> \in Nodes \X Nodes : {m, n} \in Links} -\* @type: (Int, Set(Set(Int))) => Set(Int); Peers(n, ups) == {m \in Nodes : {n, m} \in ups} ----------------------------------------------------------------------------- (* Paths. *) -\* @type: ($path, Int) => Bool; Names(path, n) == \E i \in DOMAIN path : path[i][1] = n -\* @type: ($path, $hop) => Bool; HasHop(path, h) == \E i \in DOMAIN path : path[i] = h -\* @type: ($path, Set($hop)) => Bool; DeadIn(path, D) == \E i \in DOMAIN path : path[i] \in D \* The relay that offered `path` learned it from `n`. -\* @type: ($path, Int) => Bool; Child(path, n) == Len(path) >= 2 /\ path[Len(path) - 1][1] = n \* What the route costs the last node on its path. -\* @type: ($path) => Int; PathCost(path) == - ApaFoldSet(LAMBDA c, i : IF i = 1 THEN c ELSE c + Cost[{path[i - 1][1], path[i][1]}], - 0, DOMAIN path) + LET F[i \in 0..Len(path)] == + IF i <= 1 THEN 0 ELSE F[i - 1] + Cost[{path[i - 1][1], path[i][1]}] + IN F[Len(path)] -\* @type: ($route) => Bool; Live(r) == r.on /\ ~r.held ----------------------------------------------------------------------------- (* Selection on node n's state s (paths.rs: `select`, `pending`, `hopes`). *) -\* @type: ($node, $path) => Bool; Doubted(s, path) == \E i \in DOMAIN path : path[i][1] \in s.doubt \* A route a neighbour offered that this node may use: live, and its path does \* not name this node. -\* @type: (Int, $node, Int, Str) => Bool; Usable(n, s, m, k) == s.rx[m][k].on /\ s.rx[m][k].state = "live" /\ ~Names(s.rx[m][k].path, n) \* The key of this node's own route an offer of key k to p reflects. A stream \* to a scoped relay carries one route, "a": the node's route for "a" where it \* has a live one, else its root route, which covers "a". -\* @type: ($node, Int, Str) => Str; SrcKey(s, p, k) == IF p \notin Scoped THEN k ELSE IF Live(s.rt["a"]) THEN "a" @@ -226,7 +154,6 @@ SrcKey(s, p, k) == ELSE IF s.rt["a"].on THEN "a" ELSE "root" \* A neighbour that learned this node's route for k has yet to answer its loss. -\* @type: (Int, $node, Str) => Bool; Pending(n, s, k) == \E p \in Nodes : \E j \in Keys : /\ s.rx[p][j].on @@ -235,13 +162,11 @@ Pending(n, s, k) == /\ s.tx[p][j].src = k \* A neighbour offers a route that only doubt keeps this node off. -\* @type: (Int, $node, Str) => Bool; Hopes(n, s, k) == \E m \in Nodes : Usable(n, s, m, k) /\ Doubted(s, s.rx[m][k].path) \* `select` for one key: the cheapest usable route, staying on the next hop \* among equals, then the lowest key. Doubt keeps a node from moving to a route, \* not on the one it uses. With none left, hold or let go. -\* @type: (Int, $node, Str, Set(Int) -> Int) => $route; SelectKey(n, s, k, gens) == LET was == s.rt[k] current == IF was.on THEN was.next ELSE None @@ -263,12 +188,10 @@ SelectKey(n, s, k, gens) == ELSE [on |-> TRUE, held |-> TRUE, next |-> IF under THEN current ELSE None, path |-> <<>>] \* The publisher's own route covers everything. -\* @type: Str -> $route; OwnRoutes == [k \in Keys |-> IF k = "root" THEN [on |-> TRUE, held |-> FALSE, next |-> None, path |-> <>] ELSE NoRoute] -\* @type: (Int, $node, Set(Int) -> Int) => $node; Select(n, s, gens) == IF n = Origin THEN s ELSE [s EXCEPT !.rt = [k \in Keys |-> SelectKey(n, s, k, gens)]] @@ -277,15 +200,12 @@ Select(n, s, gens) == (* What a node knows of the claims: one view per key, the newest floor any *) (* route covering that key gave it, kept while it holds a covering route. *) -\* @type: ($node, Str) => Bool; Presence(s, k) == s.rt[k].on \/ (k = "a" /\ s.rt["root"].on) \* A route this node believes: live, and it did not cross this node. -\* @type: (Int, $node, Int, Str) => Bool; Believed(n, s, m, j) == s.rx[m][j].on /\ s.rx[m][j].state = "live" /\ ~Names(s.rx[m][j].path, n) -\* @type: (Int, $node, Str) => $view; NewView(n, s, k) == IF ~Presence(s, k) THEN NoView ELSE LET base == IF s.view[k].floor = Absent THEN EmptyView ELSE s.view[k] @@ -299,14 +219,12 @@ NewView(n, s, k) == ELSE [floor |-> s.rx[best[1]][best[2]].rev, items |-> Restrict(s.rx[best[1]][best[2]].items, k)] -\* @type: (Int, $node, $ov) => $node; Know(n, s, ov) == IF n = Origin THEN [s EXCEPT !.view = [k \in Keys |-> [floor |-> ov.rev, items |-> Restrict(ov.items, k)]]] ELSE [s EXCEPT !.view = [k \in Keys |-> NewView(n, s, k)]] \* How the reader sees each claim: from the narrowest key's view, available \* while a live route covers it. -\* @type: ($node) => Str -> $shown; ShownNow(s) == [c \in Claims |-> LET v == s.view[KeyOf(c)] IN @@ -320,7 +238,6 @@ ShownNow(s) == \* What this node wants a neighbour p to hold for key k: a path, a hold, an \* end, or to keep what it was sent while the next hop this node holds under \* waits for those behind it. -\* @type: (Int, $node, Str, Int) => {kind: Str, path: $path, src: Str}; Want(n, s, k, p) == LET src == SrcKey(s, p, k) r == s.rt[src] @@ -332,7 +249,6 @@ Want(n, s, k, p) == ELSE [kind |-> "hold", path |-> <<>>, src |-> src] \* `advertise` for one key on the stream to p. -\* @type: (Int, $node, Int, Str) => {tx: $sent, out: Seq($msg)}; Advertise1(n, s, p, k) == LET t == s.tx[p][k] w == Want(n, s, k, p) @@ -352,7 +268,6 @@ Advertise1(n, s, p, k) == out |-> (IF offer THEN <> ELSE <<>>) \o (IF claims THEN <> ELSE <<>>)] -\* @type: (Int, $node, Set(Set(Int))) => {s: $node, out: Int -> Seq($msg)}; Advertise(n, s, ups) == LET a == [p \in Peers(n, ups) |-> [k \in Keys |-> Advertise1(n, s, p, k)]] IN [s |-> [s EXCEPT !.tx = [p \in Nodes |-> @@ -360,14 +275,15 @@ Advertise(n, s, ups) == out |-> [p \in Nodes |-> IF p \in Peers(n, ups) THEN a[p]["root"].out \o a[p]["a"].out ELSE <<>>]] -\* The message f(k) for each key k in `ks`, in key order. -\* @type: (Set(Str), Str => $msg) => Seq($msg); +\* Messages for the keys in `ks`, in key order. Each(ks, f(_)) == - ApaFoldSeqLeft(LAMBDA out, k : IF k \in ks THEN Append(out, f(k)) ELSE out, <<>>, KeySeq) + LET F[i \in 0..Len(KeySeq)] == + IF i = 0 THEN <<>> + ELSE F[i - 1] \o (IF KeySeq[i] \in ks THEN f(KeySeq[i]) ELSE <<>>) + IN F[Len(KeySeq)] \* `report` to one neighbour p: what became of the routes this node sent it \* through `hop`, in one DEAD where it is the first word on that hop. -\* @type: (Int, $node, Int, $hop) => {tx: Str -> $sent, told: Set($hop), out: Seq($msg)}; Report1(n, s, p, hop) == LET t == s.tx[p] through == {k \in Keys : t[k].on /\ HasHop(t[k].path, hop)} @@ -389,14 +305,13 @@ Report1(n, s, p, hop) == out == IF first \/ (gone /\ ends # {}) THEN <> \o (IF gone THEN <<>> - ELSE Each(parents, HoldMsg) \o Each(ends, EndMsg)) - ELSE Each({k \in through : w[k].kind = "path"}, LAMBDA k : OfferMsg(k, w[k].path)) - \o Each(holds, HoldMsg) - \o Each(ends, EndMsg) + ELSE Each(parents, LAMBDA k : <>) \o Each(ends, LAMBDA k : <>)) + ELSE Each({k \in through : w[k].kind = "path"}, LAMBDA k : <>) + \o Each(holds, LAMBDA k : <>) + \o Each(ends, LAMBDA k : <>) IN IF through = {} THEN [tx |-> t, told |-> s.told[p], out |-> <<>>] ELSE [tx |-> tx1, told |-> s.told[p] \cup {hop}, out |-> out] -\* @type: (Int, $node, Set(Set(Int)), $hop) => {s: $node, out: Int -> Seq($msg)}; Report(n, s, ups, hop) == LET r == [p \in Peers(n, ups) |-> Report1(n, s, p, hop)] IN [s |-> [s EXCEPT !.tx = [p \in Nodes |-> IF p \in Peers(n, ups) THEN r[p].tx ELSE s.tx[p]], @@ -406,7 +321,6 @@ Report(n, s, ups, hop) == \* `collect`: forget each doubt no route names any more, each dead hop no route \* names once the timer it started has fired, and each told hop no route sent \* names. -\* @type: ($node) => $node; Collect(s) == LET heard == {s.rx[x[1]][x[2]].path : x \in {y \in Nodes \X Keys : s.rx[y[1]][y[2]].on}} IN [s EXCEPT @@ -420,7 +334,6 @@ Collect(s) == (* show. Returns the node's new state, its messages per neighbour, and its *) (* reader's events. *) -\* @type: $rep; NoReport == [on |-> FALSE, hop |-> OHop] \* The reader's events: changes to `ended` and the counters. A claim leaving @@ -428,7 +341,6 @@ NoReport == [on |-> FALSE, hop |-> OHop] \* `quiet` marks a step that only changed a path or lifted a doubt: in one, a \* claim the reader sees changes only to what a newer floor says, or goes \* offline after it was held unavailable. -\* @type: ($node, $node, Str -> $shown, Str -> $shown, $ov, Str -> Int, Bool) => $events; Events(s0, s, old, now, ov, eb, quiet) == LET present(c) == Presence(s, KeyOf(c)) isEnd(c) == old[c].item # None /\ now[c].item = None /\ present(c) @@ -447,7 +359,6 @@ Events(s0, s, old, now, ov, eb, quiet) == unstable |-> IF ~quiet THEN 0 ELSE Cardinality({c \in Claims : old[c].item # now[c].item /\ before(c) /\ ~newer(c) /\ ~release(c)})] -\* @type: (Int, $node, $ov, Set(Set(Int)), Set(Int) -> Int, Str -> Int, $rep, Bool) => $update; Update(n, s0, ov, ups, gens, eb, rep, quiet) == LET s1 == Select(n, s0, gens) s2 == Know(n, s1, ov) @@ -464,15 +375,15 @@ Update(n, s0, ov, ups, gens, eb, rep, quiet) == \* The publisher ignores every message it hears for its own route, so none is \* queued toward it. Dropping them changes no behaviour; `Budget` still counts them. -\* @type: (<>, $msg) => Bool; Heeded(d, m) == d[2] # Origin \* The sum of f(x) over the finite set S. -SumOver(S, f(_)) == ApaFoldSet(LAMBDA a, x : a + f(x), 0, S) +SumOver(S, f(_)) == + LET F[T \in SUBSET S] == IF T = {} THEN 0 ELSE LET x == CHOOSE x \in T : TRUE IN f(x) + F[T \ {x}] + IN F[S] \* Commit the updates `rs` (a function from nodes to `Update` results), appending \* each node's messages to `q0`. Nodes in one step send on disjoint queues. -\* @type: (Int -> $update, <> -> Seq($msg)) => Bool; Commit(rs, q0) == LET ns == DOMAIN rs Sum(f(_)) == SumOver(ns, f) @@ -490,18 +401,15 @@ Quiet == \A d \in Dirs : q[d] = <<>> NoDoubt == \A n \in Nodes : st[n].wait = {} \* The messages the updates `rs` send, counted before `Heeded` drops any. -\* @type: (Int -> $update) => Int; -Sent(rs) == LET Out(n) == SumOver(Nodes, LAMBDA m : Len(rs[n].out[m])) IN SumOver(DOMAIN rs, Out) +Sent(rs) == SumOver(DOMAIN rs, LAMBDA n : SumOver(Nodes, LAMBDA m : Len(rs[n].out[m]))) \* A burst runs from one quiet point to the next. An external change (a claim \* change, a session opening or closing) made while quiet starts a fresh one; \* every message sent in it counts against the changes made in it. -\* @type: (Int) => Bool; External(sent) == /\ burst' = (IF Quiet THEN 0 ELSE burst) + sent /\ churn' = (IF Quiet THEN 0 ELSE churn) + 1 -\* @type: (Int) => Bool; Internal(sent) == /\ burst' = burst + sent /\ UNCHANGED churn @@ -510,7 +418,6 @@ Internal(sent) == (* Initial state: every session open, the publisher's route sent and no *) (* claims yet. *) -\* @type: $node; InitNode == [ rx |-> [m \in Nodes |-> [k \in Keys |-> NoHeard]], rt |-> [k \in Keys |-> NoRoute], @@ -523,10 +430,8 @@ InitNode == [ shown |-> [c \in Claims |-> NotShown] ] -\* @type: $ov; OV0 == [rev |-> 0, items |-> NoItems] Gen0 == [l \in Links |-> 0] -\* @type: $update; Start == Update(Origin, [InitNode EXCEPT !.rt = OwnRoutes], OV0, Links, Gen0, [c \in Claims |-> None], NoReport, FALSE) @@ -548,13 +453,11 @@ Init == /\ burst = 0 /\ churn = 1 -\* @type: $ov; OV == [rev |-> rev, items |-> own] ----------------------------------------------------------------------------- (* The publisher changes a claim. *) -\* @type: (Str, Int) => Bool; ChangeClaim(c, item) == LET own1 == [own EXCEPT ![c] = item] ov1 == [rev |-> rev + 1, items |-> own1] @@ -575,7 +478,6 @@ Unannounce(c) == rev < MaxRev /\ own[c] # None /\ ChangeClaim(c, None) \* `fail`: the session `hop` names closed. `from` reported it with what became \* of its own routes through it, or this node saw it close (`from` is None). \* It casts doubt on the node at the session's far end, `hop[2]`. -\* @type: (Int, $node, $hop, Int, Set(<>), Bool) => $node; Fail(n, s, hop, from, moved, gone) == LET Moved(k) == {mv \in moved : mv[1] = k} rx1 == [p \in Nodes |-> [k \in Keys |-> @@ -593,7 +495,6 @@ Fail(n, s, hop, from, moved, gone) == IN [s EXCEPT !.rx = rx1, !.dead = @ \cup {hop}, !.doubt = @ \cup ({hop[2]} \ {n}), !.wait = @ \cup ({hop[2]} \ {n})] -\* @type: (Int, $node, Int, $msg) => $node; Recv(n, s, from, msg) == LET k == msg.k h == s.rx[from][k] @@ -609,7 +510,6 @@ Recv(n, s, from, msg) == IF h.on THEN [s EXCEPT !.rx[from][k].rev = msg.rev, !.rx[from][k].items = msg.items] ELSE s [] OTHER -> Fail(n, s, msg.hop, from, msg.moved, msg.gone) -\* @type: (<>) => Bool; Deliver(d) == LET m == d[1] n == d[2] @@ -628,7 +528,6 @@ Deliver(d) == \* whose session ended at x may be forgotten. With `Patient`, only once no DEAD \* about such a hop is in flight: a timer long enough for the news to cross \* the mesh. -\* @type: (Int, Int) => Bool; Lift(n, x) == LET rs == [y \in {n} |-> Update(n, [st[n] EXCEPT !.doubt = @ \ {x}, !.wait = @ \ {x}], OV, up, gen, ended[n], NoReport, TRUE)] @@ -642,18 +541,16 @@ Lift(n, x) == (* Sessions open and close. *) \* A closed session: everything learned or sent on it goes. -\* @type: ($node, Int) => $node; Closed(s, y) == [s EXCEPT !.rx[y] = [k \in Keys |-> NoHeard], !.tx[y] = [k \in Keys |-> NoSent(k)], !.told[y] = {}] -\* @type: (Set(Int)) => Bool; Connect(l) == LET up1 == up \cup {l} gen1 == [gen EXCEPT ![l] = @ + 1] rs == [x \in l |-> - LET y == CHOOSE z \in l : z # x + LET y == CHOOSE y \in l : y # x IN Update(x, Closed(st[x], y), OV, up1, gen1, ended[x], NoReport, FALSE)] IN /\ l \notin up /\ flaps < MaxFlaps @@ -665,13 +562,11 @@ Connect(l) == /\ UNCHANGED <> \* `disconnect`: each end names the hop it learned routes on there. -\* @type: (Set(Int)) => Bool; Disconnect(l) == LET up1 == up \ {l} q0 == [d \in Dirs |-> IF {d[1], d[2]} = l THEN <<>> ELSE q[d]] rs == [x \in l |-> - LET y == CHOOSE z \in l : z # x - \* @type: $hop; + LET y == CHOOSE y \in l : y # x hop == <> s == Closed(st[x], y) IN IF x = Origin @@ -740,18 +635,23 @@ Seen == (j = KeyOf(c) \/ j = "root") /\ Believed(n, st[n], m, j) => st[n].rx[m][j].rev <= v.floor -\* A loop-free path from the publisher to `from` over the configured links, -\* each hop naming the session it was learned on from the one before. -\* @type: (Int, $path) => Bool; +\* The loop-free paths from the publisher over the configured links, as the +\* nodes each crosses in order, and what each costs its last node. +RECURSIVE Extend(_, _) +Last(p) == p[Len(p)] +Extend(P, k) == + IF k = 0 THEN P + ELSE Extend(P \cup UNION {{Append(p, n) : n \in {m \in Relays : {Last(p), m} \in Links}} : p \in P}, k - 1) +Paths == + {p \in Extend({<>}, Cardinality(Relays)) : \A i, j \in DOMAIN p : i # j => p[i] # p[j]} + +NodesOf(path) == [i \in DOMAIN path |-> path[i][1]] IsPath(from, path) == /\ Len(path) >= 1 /\ path[1] = OHop - /\ path[Len(path)][1] = from - /\ \A i \in DOMAIN path : i > 1 => - /\ path[i][1] \in Relays - /\ path[i][2] = path[i - 1][1] - /\ {path[i - 1][1], path[i][1]} \in Links - /\ \A i, j \in DOMAIN path : i # j => path[i][1] # path[j][1] + /\ NodesOf(path) \in Paths + /\ Last(NodesOf(path)) = from + /\ \A i \in DOMAIN path : i > 1 => path[i][2] = path[i - 1][1] \* Every route held or in flight names a loop-free path from the publisher to \* its sender. @@ -762,41 +662,43 @@ SimplePaths == /\ q[d][i].t = "dead" => \A mv \in q[d][i].moved : IsPath(d[1], mv[2]) \* A hop whose session has closed: the link is down or opened again since. -\* @type: ($hop) => Bool; Gone(h) == h # OHop /\ ({h[1], h[2]} \notin up \/ gen[{h[1], h[2]}] # h[3]) -\* @type: ($path) => Bool; Stale(path) == \E i \in DOMAIN path : Gone(path[i]) \* Where a request for a claim goes. A node starts it on the narrowest live \* route covering the claim; each node forwards it on the route it offered the \* node it came from under that key, and never along a route whose path names -\* that node. The result is "origin", "stuck", "refused", or "loop", once it -\* has crossed every node; `stale` says whether a node it crossed forwarded it -\* on a stale route. -\* @type: {cur: Int, k: Str, prev: Int, res: Str, stale: Bool} => {cur: Int, k: Str, prev: Int, res: Str, stale: Bool}; -Fwd(w) == - IF w.res # "" THEN w - ELSE IF w.cur = Origin THEN [w EXCEPT !.res = "origin"] - ELSE LET src == IF w.prev = None THEN w.k ELSE SrcKey(st[w.cur], w.prev, w.k) - r == st[w.cur].rt[src] - IN IF ~Live(r) THEN [w EXCEPT !.res = "stuck"] - ELSE IF w.prev # None /\ Names(r.path, w.prev) THEN [w EXCEPT !.res = "refused"] - ELSE [cur |-> r.next, k |-> src, prev |-> w.cur, res |-> "", stale |-> w.stale \/ Stale(r.path)] - -Walk(n, c) == - LET k == IF c \in Narrow /\ Live(st[n].rt["a"]) THEN "a" ELSE "root" - w == ApaFoldSet(LAMBDA x, i : Fwd(x), - [cur |-> n, k |-> k, prev |-> None, res |-> "", stale |-> FALSE], Nodes) - IN IF w.res # "" THEN w - ELSE [w EXCEPT !.res = IF w.cur = Origin THEN "origin" ELSE "loop"] - -Request(n, c) == Walk(n, c).res +\* that node. The result is "origin", "stuck", "refused", or "loop". +RECURSIVE Fwd(_, _, _, _) +Fwd(cur, k, prev, i) == + IF cur = Origin THEN "origin" + ELSE IF i = 0 THEN "loop" + ELSE LET src == IF prev = None THEN k ELSE SrcKey(st[cur], prev, k) + r == st[cur].rt[src] + IN IF ~Live(r) THEN "stuck" + ELSE IF prev # None /\ Names(r.path, prev) THEN "refused" + ELSE Fwd(r.next, src, cur, i - 1) + +Request(n, c) == + Fwd(n, IF c \in Narrow /\ Live(st[n].rt["a"]) THEN "a" ELSE "root", None, Cardinality(Nodes)) + +\* The nodes a request from n for c crosses before it reaches the publisher, +\* stops, or has crossed every node. +RECURSIVE Walk(_, _, _, _) +Walk(cur, k, prev, i) == + IF cur = Origin \/ i = 0 THEN <<>> + ELSE LET src == IF prev = None THEN k ELSE SrcKey(st[cur], prev, k) + r == st[cur].rt[src] + IN IF ~Live(r) \/ (prev # None /\ Names(r.path, prev)) THEN <<>> + ELSE <<[node |-> cur, path |-> r.path]>> \o Walk(r.next, src, cur, i - 1) \* A request that loops crosses a node whose route is stale: it names a \* session that has closed, whose news has yet to reach that node. LoopsAreStale == \A n \in Relays, c \in Claims : - (Live(st[n].rt["root"]) \/ Live(st[n].rt["a"])) /\ Request(n, c) = "loop" => Walk(n, c).stale + (Live(st[n].rt["root"]) \/ Live(st[n].rt["a"])) /\ Request(n, c) = "loop" => + LET w == Walk(n, IF c \in Narrow /\ Live(st[n].rt["a"]) THEN "a" ELSE "root", None, Cardinality(Nodes)) + IN \E i \in DOMAIN w : Stale(w[i].path) \* A request never loops. It does while news is in flight: `Loop.cfg` pins it. RequestsLoopFree == \A n \in Relays, c \in Claims : Request(n, c) # "loop" @@ -810,32 +712,30 @@ NoStaleReturn == \* Whether the news that ends a stale route node n heard from m under key k is \* on its way: queued from m to n, or m's own route is stale and its news is -\* on its way to m, and so on back, over at most every node. -\* @type: {n: Int, m: Int, k: Str, res: Str} => {n: Int, m: Int, k: Str, res: Str}; -Chase(w) == - IF w.res # "" THEN w - ELSE IF q[<>] # <<>> THEN [w EXCEPT !.res = "yes"] - ELSE IF w.m = Origin THEN [w EXCEPT !.res = "no"] - ELSE LET src == SrcKey(st[w.m], w.n, w.k) - r == st[w.m].rt[src] - IN IF Live(r) /\ Stale(r.path) THEN [n |-> w.m, m |-> r.next, k |-> src, res |-> ""] - ELSE [w EXCEPT !.res = "no"] - -Chased(n, m, k) == - LET w == ApaFoldSet(LAMBDA x, i : Chase(x), [n |-> n, m |-> m, k |-> k, res |-> ""], Nodes) - IN w.res = "yes" \/ (w.res = "" /\ q[<>] # <<>>) +\* on its way to m. +RECURSIVE Chased(_, _, _, _) +Chased(n, m, k, i) == + \/ q[<>] # <<>> + \/ /\ i > 0 + /\ m # Origin + /\ LET src == SrcKey(st[m], n, k) + r == st[m].rt[src] + IN /\ Live(r) + /\ Stale(r.path) + /\ Chased(m, r.next, src, i - 1) \* A stale route a node may use always has the news that ends it on its way, \* so it lasts no longer than that news takes to arrive. StaleIsChased == \A n \in Relays, m \in Nodes, k \in Keys : - Usable(n, st[n], m, k) /\ Stale(st[n].rx[m][k].path) => Chased(n, m, k) + Usable(n, st[n], m, k) /\ Stale(st[n].rx[m][k].path) => Chased(n, m, k, Cardinality(Nodes)) \* The nodes a path over open sessions from the publisher reaches, through \* nodes whose interest covers claim c. -Carried(c) == - ApaFoldSet(LAMBDA R, i : R \cup {n \in Relays : Covers(Ask(n), c) /\ \E m \in R : {m, n} \in up}, - {Origin}, Nodes) +RECURSIVE Grow(_, _, _) +Grow(R, c, i) == IF i = 0 THEN R + ELSE Grow(R \cup {n \in Relays : Covers(Ask(n), c) /\ \E m \in R : {m, n} \in up}, c, i - 1) +Carried(c) == Grow({Origin}, c, Cardinality(Nodes)) \* Once nothing is in flight and no doubt is left: each relay shows exactly the \* publisher's claims that a path carries to it, available; a request for each @@ -863,4 +763,45 @@ PerChange == 4 * Cardinality(Dirs) * (Cardinality(Keys) + Cardinality(Claims)) \* deliveries that never goes quiet would grow it past any budget. Budget == burst <= PerChange * churn +----------------------------------------------------------------------------- +(* The claims with no paths (RouteClaims.tla): every step here is a step *) +(* there, which `RefinesClaims` checks. Its `Truthful`, `NoRevival`, *) +(* `NoFalseEnd`, and `NoRegression` are these rules read through the *) +(* mapping, and Apalache shows they hold there for runs of any length. *) + +\* The route n heard from m for key k: none, believed, or not. +Hearing(n, m, k) == + IF ~st[n].rx[m][k].on THEN "off" ELSE IF Believed(n, st[n], m, k) THEN "live" ELSE "doubt" +Routing(r) == IF ~r.on THEN "none" ELSE IF r.held THEN "held" ELSE "live" + +\* The claims messages queued on d, without their order. +ClaimsOn(d) == + {[k |-> q[d][i].k, rev |-> q[d][i].rev, items |-> q[d][i].items] : + i \in {j \in DOMAIN q[d] : q[d][j].t = "claims"}} + +COffered == [x \in Relays \X Nodes \X Keys |-> + [rev |-> st[x[1]].rx[x[2]][x[3]].rev, items |-> st[x[1]].rx[x[2]][x[3]].items]] +CView == [x \in Relays \X Keys |-> st[x[1]].view[x[2]]] +CFlight == UNION {ClaimsOn(d) : d \in Dirs} +\* The publisher's claims at each revision the state names, as `Refs` there. +CHist == + LET refs == {r \in {rev} + \cup {CView[x].floor : x \in DOMAIN CView} + \cup {COffered[x].rev : x \in DOMAIN COffered} + \cup {y.rev : y \in CFlight} : r >= 0} + IN [r \in refs |-> hist[r + 1]] + +Claimed == INSTANCE RouteClaims WITH + hist <- CHist, + heard <- [x \in Relays \X Nodes \X Keys |-> Hearing(x[1], x[2], x[3])], + offered <- COffered, + route <- [x \in Relays \X Keys |-> Routing(st[x[1]].rt[x[2]])], + view <- CView, + shown <- [x \in Relays \X Claims |-> st[x[1]].shown[x[2]]], + ended <- [x \in Relays \X Claims |-> ended[x[1]][x[2]]], + flight <- CFlight, + MaxFlight <- 0 + +RefinesClaims == Claimed!Spec + ============================================================================= From fd339d26bb7ad8c53cbfff254e978fac07e40d0a Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 15:53:24 -0800 Subject: [PATCH 4/6] wip(net): floors carry the publisher's claims at their revision --- rs/moq-net/verify/route/RouteClaims.tla | 107 +++++++++++------------ rs/moq-net/verify/route/RouteHandoff.tla | 26 ++---- 2 files changed, 60 insertions(+), 73 deletions(-) diff --git a/rs/moq-net/verify/route/RouteClaims.tla b/rs/moq-net/verify/route/RouteClaims.tla index de26f09423d..9bb474c988f 100644 --- a/rs/moq-net/verify/route/RouteClaims.tla +++ b/rs/moq-net/verify/route/RouteClaims.tla @@ -6,6 +6,10 @@ (* of its own per key, live, held, or none. The claims a node sends may *) (* reach any relay, in any order, any number of times, or never. *) (* *) +(* Every floor carries `full`, the publisher's claims at its revision, so *) +(* a floor is truthful when its items are `full` within its key. Nothing *) +(* reads `full` but the rules: it stands for RouteHandoff's history. *) +(* *) (* RouteHandoff refines this model (its `RefinesClaims`), so the claim *) (* rules here hold there too. Apalache checks that `IndInv` holds at *) (* `Init` and that every step keeps it, so they hold for runs of any *) @@ -26,9 +30,9 @@ CONSTANTS MaxFlight \* `IndInit` only: the claims messages in flight \* Apalache's names for the records below. -\* @typeAlias: floor = { rev: Int, items: Str -> Int }; -\* @typeAlias: view = { floor: Int, items: Str -> Int }; -\* @typeAlias: msg = { k: Str, rev: Int, items: Str -> Int }; +\* @typeAlias: floor = { rev: Int, items: Str -> Int, full: Str -> Int }; +\* @typeAlias: view = { floor: Int, items: Str -> Int, full: Str -> Int }; +\* @typeAlias: msg = { k: Str, rev: Int, items: Str -> Int, full: Str -> Int }; \* @typeAlias: shown = { item: Int, avail: Bool }; \* Every relay's state is one function keyed by relay first, since Apalache \* cannot pick a function of functions. @@ -54,9 +58,9 @@ KeyOf(c) == IF c \in Narrow THEN "a" ELSE "root" NoItems == [c \in Claims |-> None] \* @type: (Str -> Int, Str) => Str -> Int; Restrict(items, k) == [c \in Claims |-> IF Covers(k, c) THEN items[c] ELSE None] -NoFloor == [rev |-> None, items |-> NoItems] -EmptyView == [floor |-> None, items |-> NoItems] -NoView == [floor |-> Absent, items |-> NoItems] +NoFloor == [rev |-> None, items |-> NoItems, full |-> NoItems] +EmptyView == [floor |-> None, items |-> NoItems, full |-> NoItems] +NoView == [floor |-> Absent, items |-> NoItems, full |-> NoItems] NotShown == [item |-> None, avail |-> FALSE] \* What a relay heard from a neighbour for a key: nothing, a route it @@ -77,8 +81,6 @@ VARIABLES rev, \* the publisher's claim revision \* @type: Str -> Int; own, \* the publisher's claims - \* @type: Int -> (Str -> Int); - hist, \* hist[r]: the publisher's claims at revision r, for each r the state names \* @type: $heard; heard, \* heard[<>]: the route n heard from m for key k \* @type: $offered; @@ -100,7 +102,7 @@ VARIABLES \* @type: Int; regressions \* reader UPDATEs to an older item -vars == <> ----------------------------------------------------------------------------- @@ -117,7 +119,7 @@ NewView(hd, of, rt, vw, n, k) == ELSE LET \* @type: ($view, <>) => $view; Newer(v, x) == IF hd[x] = "live" /\ of[x].rev > v.floor - THEN [floor |-> of[x].rev, items |-> Restrict(of[x].items, k)] + THEN [floor |-> of[x].rev, items |-> Restrict(of[x].items, k), full |-> of[x].full] ELSE v IN ApaFoldSet(Newer, IF vw[<>].floor = Absent THEN EmptyView ELSE vw[<>], {n} \X Nodes \X {k, "root"}) @@ -133,17 +135,9 @@ ShownNow(rt, vw, n, c) == \* What node n sends: its view per key, or the publisher's claims. \* @type: (Int, Int, Str -> Int, $views) => Set($msg); Sends(n, rv, ow, vw) == - IF n = Origin THEN {[k |-> k, rev |-> rv, items |-> Restrict(ow, k)] : k \in Keys} + IF n = Origin THEN {[k |-> k, rev |-> rv, items |-> Restrict(ow, k), full |-> ow] : k \in Keys} ELSE {[k |-> k, rev |-> IF vw[<>].floor = Absent THEN None ELSE vw[<>].floor, - items |-> vw[<>].items] : k \in Keys} - -\* The revisions the state names: the publisher's, and every floor's. -\* @type: (Int, $offered, $views, Set($msg)) => Set(Int); -Refs(rv, of, vw, fl) == - {r \in {rv} - \cup {vw[x].floor : x \in KeyIdx} - \cup {of[x].rev : x \in HeardIdx} - \cup {y.rev : y \in fl} : r >= 0} + items |-> vw[<>].items, full |-> vw[<>].full] : k \in Keys} ----------------------------------------------------------------------------- (* The publisher's claims and every relay's routes start empty; the *) @@ -152,7 +146,6 @@ Refs(rv, of, vw, fl) == Init == /\ rev = 0 /\ own = NoItems - /\ hist = [r \in {0} |-> NoItems] /\ heard = [x \in HeardIdx |-> "off"] /\ offered = [x \in HeardIdx |-> NoFloor] /\ route = [x \in KeyIdx |-> "none"] @@ -173,15 +166,15 @@ Publish == /\ own' = [own EXCEPT ![c] = item] \* One step: the publisher may change a claim, and every relay's routes may -\* change. A route that stays on may take any claims in flight to it under -\* its key; one that turns on or off has no floor. Every relay then updates -\* its views and shows its reader the difference, and every node may send -\* its views, while any message in flight may be lost. +\* change. A route that stays on may take any claims in flight under its +\* key; one that turns on or off has no floor. Every relay then updates its +\* views and shows its reader the difference, and every node may send its +\* views, while any message in flight may be lost. Next == /\ Publish /\ heard' \in [HeardIdx -> Hearings] /\ route' \in [KeyIdx -> Routings] - /\ LET arrived == {[rev |-> y.rev, items |-> y.items] : y \in flight} + /\ LET arrived == {[rev |-> y.rev, items |-> y.items, full |-> y.full] : y \in flight} pool == {NoFloor} \cup arrived \cup {offered[x] : x \in HeardIdx} IN /\ offered' \in [HeardIdx -> pool] /\ \A x \in HeardIdx : @@ -189,7 +182,7 @@ Next == THEN offered'[x] = NoFloor ELSE \/ offered'[x] = offered[x] \/ \E y \in flight : - y.k = x[3] /\ offered'[x] = [rev |-> y.rev, items |-> y.items] + y.k = x[3] /\ offered'[x] = [rev |-> y.rev, items |-> y.items, full |-> y.full] /\ view' = [x \in KeyIdx |-> NewView(heard', offered', route', view, x[1], x[2])] /\ shown' = [x \in ClaimIdx |-> ShownNow(route', view', x[1], x[2])] /\ LET \* @type: (<>) => Bool; @@ -207,7 +200,6 @@ Next == /\ falseEnds' = falseEnds + Cardinality({x \in ClaimIdx : isEnd(x) /\ own'[x[2]] = shown[x].item}) /\ regressions' = regressions + Cardinality({x \in ClaimIdx : isUpdate(x) /\ shown'[x].item < shown[x].item}) /\ flight' \in SUBSET (flight \cup UNION {Sends(n, rev', own', view') : n \in Nodes}) - /\ hist' = [r \in Refs(rev', offered', view', flight') |-> IF r = rev' THEN own' ELSE hist[r]] Spec == Init /\ [][Next]_vars @@ -217,10 +209,9 @@ Spec == Init /\ [][Next]_vars \* Every floor a relay keeps or was offered is the publisher's claims at that \* revision, within its key. Truthful == - /\ \A x \in KeyIdx : view[x].floor >= 0 => - view[x].items = Restrict(hist[view[x].floor], x[2]) + /\ \A x \in KeyIdx : view[x].floor >= 0 => view[x].items = Restrict(view[x].full, x[2]) /\ \A x \in HeardIdx : heard[x] # "off" /\ offered[x].rev >= 0 => - offered[x].items = Restrict(hist[offered[x].rev], x[3]) + offered[x].items = Restrict(offered[x].full, x[3]) \* A reader never sees a broadcast start again after it saw it end. NoRevival == revivals = 0 @@ -236,37 +227,41 @@ NoRegression == regressions = 0 (* each floor is the publisher's claims at its revision, and an item is *) (* the revision that set it, so a newer floor never names an older item. *) -\* A floor: None with no items, or a revision the publisher has passed with +\* Every revision the state names, with the publisher's claims then. +Fulls == + {[rev |-> rev, full |-> own]} + \cup {[rev |-> view[x].floor, full |-> view[x].full] : x \in KeyIdx} + \cup {[rev |-> offered[x].rev, full |-> offered[x].full] : x \in HeardIdx} + \cup {[rev |-> y.rev, full |-> y.full] : y \in flight} + +\* A floor: None with no claims, or a revision the publisher has passed with \* its claims then, within key k. -\* @type: (Str, Int, Str -> Int) => Bool; -Sound(k, r, items) == - \/ r = None /\ items = NoItems - \/ /\ 0 <= r /\ r <= rev - /\ r \in DOMAIN hist - /\ items = Restrict(hist[r], k) +\* @type: (Str, Int, Str -> Int, Str -> Int) => Bool; +Sound(k, r, items, full) == + \/ r = None /\ items = NoItems /\ full = NoItems + \/ 0 <= r /\ r <= rev /\ items = Restrict(full, k) IndInv == /\ Truthful /\ NoRevival /\ NoFalseEnd /\ NoRegression - \* The history: an item is the revision that set it, and it stays set - \* until a later revision changes it. + \* The history the floors name: an item is the revision that set it, and + \* it stays set until a later revision changes it. /\ rev >= 0 - /\ DOMAIN hist = Refs(rev, offered, view, flight) - /\ hist[rev] = own - /\ \A r \in DOMAIN hist, c \in Claims : - hist[r][c] = None \/ (1 <= hist[r][c] /\ hist[r][c] <= r) - /\ \A r1, r2 \in DOMAIN hist, c \in Claims : - r1 <= r2 /\ hist[r2][c] # None /\ hist[r2][c] <= r1 => hist[r1][c] = hist[r2][c] + /\ \A f \in Fulls, c \in Claims : f.rev >= 0 => + f.full[c] = None \/ (1 <= f.full[c] /\ f.full[c] <= f.rev) + /\ \A f, g \in Fulls, c \in Claims : + 0 <= f.rev /\ f.rev <= g.rev /\ g.full[c] # None /\ g.full[c] <= f.rev => + f.full[c] = g.full[c] \* Every floor is sound, and a route that is off gave none. - /\ \A y \in flight : y.k \in Keys /\ Sound(y.k, y.rev, y.items) + /\ \A y \in flight : y.k \in Keys /\ Sound(y.k, y.rev, y.items, y.full) /\ \A x \in HeardIdx : - /\ Sound(x[3], offered[x].rev, offered[x].items) + /\ Sound(x[3], offered[x].rev, offered[x].items, offered[x].full) /\ heard[x] = "off" => offered[x] = NoFloor \* A relay keeps a view exactly while it holds a route covering it. /\ \A x \in KeyIdx : - IF Presence(route, x[1], x[2]) THEN Sound(x[2], view[x].floor, view[x].items) + IF Presence(route, x[1], x[2]) THEN Sound(x[2], view[x].floor, view[x].items, view[x].full) ELSE view[x] = NoView /\ \A x \in ClaimIdx : shown[x] = ShownNow(route, view, x[1], x[2]) \* What the reader saw end is older than the view, which no longer has it. @@ -284,17 +279,17 @@ IndInit == /\ own \in [Claims -> Int] /\ heard \in [HeardIdx -> Hearings] /\ route \in [KeyIdx -> Routings] - /\ \E r \in [HeardIdx -> Int], i \in [HeardIdx \X Claims -> Int] : - offered = [x \in HeardIdx |-> [rev |-> r[x], items |-> [c \in Claims |-> i[<>]]]] - /\ \E f \in [KeyIdx -> Int], i \in [KeyIdx \X Claims -> Int] : - view = [x \in KeyIdx |-> [floor |-> f[x], items |-> [c \in Claims |-> i[<>]]]] + /\ \E r \in [HeardIdx -> Int], i, f \in [HeardIdx \X Claims -> Int] : + offered = [x \in HeardIdx |-> [rev |-> r[x], items |-> [c \in Claims |-> i[<>]], + full |-> [c \in Claims |-> f[<>]]]] + /\ \E r \in [KeyIdx -> Int], i, f \in [KeyIdx \X Claims -> Int] : + view = [x \in KeyIdx |-> [floor |-> r[x], items |-> [c \in Claims |-> i[<>]], + full |-> [c \in Claims |-> f[<>]]]] /\ \E i \in [ClaimIdx -> Int], a \in [ClaimIdx -> BOOLEAN] : shown = [x \in ClaimIdx |-> [item |-> i[x], avail |-> a[x]]] /\ ended \in [ClaimIdx -> Int] /\ flight = Gen(MaxFlight) - /\ \A y \in flight : DOMAIN y.items = Claims - /\ \E i \in [Refs(rev, offered, view, flight) \X Claims -> Int] : - hist = [r \in Refs(rev, offered, view, flight) |-> [c \in Claims |-> i[<>]]] + /\ \A y \in flight : DOMAIN y.items = Claims /\ DOMAIN y.full = Claims /\ revivals \in Int /\ falseEnds \in Int /\ regressions \in Int diff --git a/rs/moq-net/verify/route/RouteHandoff.tla b/rs/moq-net/verify/route/RouteHandoff.tla index dbaa981e73c..b0bd35613df 100644 --- a/rs/moq-net/verify/route/RouteHandoff.tla +++ b/rs/moq-net/verify/route/RouteHandoff.tla @@ -774,32 +774,24 @@ Hearing(n, m, k) == IF ~st[n].rx[m][k].on THEN "off" ELSE IF Believed(n, st[n], m, k) THEN "live" ELSE "doubt" Routing(r) == IF ~r.on THEN "none" ELSE IF r.held THEN "held" ELSE "live" +\* The publisher's claims at revision r, for a floor's `full` there. +Full(r) == IF r >= 0 THEN hist[r + 1] ELSE NoItems + \* The claims messages queued on d, without their order. ClaimsOn(d) == - {[k |-> q[d][i].k, rev |-> q[d][i].rev, items |-> q[d][i].items] : + {[k |-> q[d][i].k, rev |-> q[d][i].rev, items |-> q[d][i].items, full |-> Full(q[d][i].rev)] : i \in {j \in DOMAIN q[d] : q[d][j].t = "claims"}} -COffered == [x \in Relays \X Nodes \X Keys |-> - [rev |-> st[x[1]].rx[x[2]][x[3]].rev, items |-> st[x[1]].rx[x[2]][x[3]].items]] -CView == [x \in Relays \X Keys |-> st[x[1]].view[x[2]]] -CFlight == UNION {ClaimsOn(d) : d \in Dirs} -\* The publisher's claims at each revision the state names, as `Refs` there. -CHist == - LET refs == {r \in {rev} - \cup {CView[x].floor : x \in DOMAIN CView} - \cup {COffered[x].rev : x \in DOMAIN COffered} - \cup {y.rev : y \in CFlight} : r >= 0} - IN [r \in refs |-> hist[r + 1]] - Claimed == INSTANCE RouteClaims WITH - hist <- CHist, heard <- [x \in Relays \X Nodes \X Keys |-> Hearing(x[1], x[2], x[3])], - offered <- COffered, + offered <- [x \in Relays \X Nodes \X Keys |-> + LET h == st[x[1]].rx[x[2]][x[3]] IN [rev |-> h.rev, items |-> h.items, full |-> Full(h.rev)]], route <- [x \in Relays \X Keys |-> Routing(st[x[1]].rt[x[2]])], - view <- CView, + view <- [x \in Relays \X Keys |-> + LET v == st[x[1]].view[x[2]] IN [floor |-> v.floor, items |-> v.items, full |-> Full(v.floor)]], shown <- [x \in Relays \X Claims |-> st[x[1]].shown[x[2]]], ended <- [x \in Relays \X Claims |-> ended[x[1]][x[2]]], - flight <- CFlight, + flight <- UNION {ClaimsOn(d) : d \in Dirs}, MaxFlight <- 0 RefinesClaims == Claimed!Spec From 92610f10d81e7d9a1707baa7b77e5456fecb120e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 18:25:02 -0800 Subject: [PATCH 5/6] quest: split the route proof into claims and loops Co-Authored-By: Claude Opus 5.5 --- quest/m1/route-inductive.md | 28 +++++++--------- quest/m1/route-loops.md | 66 +++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 quest/m1/route-loops.md diff --git a/quest/m1/route-inductive.md b/quest/m1/route-inductive.md index 225fc47f5da..ef1585f2373 100644 --- a/quest/m1/route-inductive.md +++ b/quest/m1/route-inductive.md @@ -92,24 +92,18 @@ Found 2026-11-12, trying it on the route model itself rules (`SimplePaths`, `LoopsAreStale`, `StaleIsChased`) need routes, DEAD, holds, and doubts, but no claims, views, or events. -Public API: none. Wire: none. +Decided 2026-11-12 (maintainer, /quest-unblock): ✅ split the model +(rejected: a TLAPS proof on the route model; deleting the quest and resting +on TLC's bounded runs and the sweeps; a host with far more memory). This +quest proves the claim rules (`Truthful`, `NoRevival`, `NoFalseEnd`, +`NoRegression`) on a small model with no paths, where routes come and go +freely. [A follow-up](/quest/m1/route-loops.md) proves the loop rules +(`SimplePaths`, `LoopsAreStale`, `StaleIsChased`) on a model without claims, +after first measuring that Apalache fits it. TLC refinement-checks each model +against `RouteHandoff.tla`. This PR keeps the Apalache package and the `tla` +recipe, and drops the annotations and folds from `RouteHandoff.tla`. -## Waiting - -- Maintainer: how to prove the rules for runs of any length, now that - Apalache cannot check the route model itself. Options: (A, recommended) - split it: this quest proves the claim rules on a small model whose routes - come and go freely, and a new quest proves the loop rules on a model - without claims after measuring that Apalache fits it, each tied to - `RouteHandoff.tla` by a refinement TLC checks on its configs; (B) a TLAPS - proof on the route model, rejected 2026-11-10 because its steps break on - each model change, which the router quest is still making; (C) delete the - quest and rest on TLC's bounded runs and the sweeps; (D) retry on a host - with far more memory, which the two-relay result above makes unlikely to - fit any useful mesh. A recommends itself because the claim rules are the - ones bounded runs cover least, and a model without paths should fit five - relays. An agent cannot pick: it changes the method the 2026-11-10 - decision chose. +Public API: none. Wire: none. ## Related diff --git a/quest/m1/route-loops.md b/quest/m1/route-loops.md new file mode 100644 index 00000000000..1b997866843 --- /dev/null +++ b/quest/m1/route-loops.md @@ -0,0 +1,66 @@ +# [L] The route model's loop rules hold for runs of any length + +## Goal + +`SimplePaths`, `LoopsAreStale`, and `StaleIsChased` from +`rs/moq-net/verify/route/RouteHandoff.tla` hold for runs of any length: +Apalache checks in Nightly that an inductive invariant of a model with +routes, DEAD, holds, and doubts, but no claims, holds initially and that +every step keeps it. TLC checks on the route model's configs that +`RouteHandoff.tla` refines it, as it does for the claims model +(`RouteClaims.tla`, `RefinesClaims`). The bounds are the relay count and the +messages in flight the configs state; revisions, sessions, and churn are +unbounded. The `verify-route` skill states both bounds. + +## Plan + +Decided 2026-11-12 (maintainer, /quest-unblock on +[moq-dev/moq#8564](https://github.com/moq-dev/moq/pull/8564)), after +Apalache 0.63 could not step the route model itself on one relay pair with +16 GB of heap: ✅ split the model (rejected: a TLAPS proof on the route +model, whose steps break on each model change; deleting the quest and resting +on TLC's bounded runs and the sweeps; a host with far more memory). That PR +proved the claim rules on `RouteClaims.tla`, a model with no paths. This +quest proves the loop rules on a model with no claims, views, or reader +events, after first measuring that Apalache fits it. + +- Measure first: one step of a claims-free model from any typed state, on + the smallest mesh with a loop (the publisher and two relays), then three + and five relays. If no mesh fits, stop and hand the decision back with the + measurements, as the claims split did. +- Lessons from `RouteClaims.tla`, which fits five neighbours in about twelve + minutes: + - Apalache cannot pick a function of functions: key every per-relay + variable by a tuple (`<>`), one level deep. + - Write each step so TLC can check refinement without enumerating: assign + a variable from a finite function set (`x' \in [S -> T]`) and constrain + it, rather than `\E choice : x' = f(choice)`. + - A ghost the invariant compares pairwise must only grow (`hist' = hist + \cup {new}`), so a step re-proves only the pairs with the new entry; a + pairwise rule over values a step copies around never finished. + - A history keyed by a computed set of revisions made even the first + state unsolvable; a set of records was fast. + - Fold one-of-several choices into one transition (`\E change \in + BOOLEAN`), and check invariants after the step only + (`search.invariantFilter=1->.*`). +- Unlike the claim rules, the loop rules span several relays (a loop crosses + them), so one relay's step does not stand for every relay's: the check needs + the whole mesh, and its size is the bound. +- Start from the path argument: no relay holds or selects a route whose path + names it, every route in flight extends the path its sender held when it + sent it, and every withdrawal in flight names a hop whose session closed. + `SimplePaths` is inductive once the invariant also says a route is held + only from a node the holder shares a link with + ([moq-dev/moq#8487](https://github.com/moq-dev/moq/pull/8487)). +- A counterexample to induction starts from a state that may be unreachable. + If TLC cannot reach it, the invariant is too weak: strengthen it. If it can, + replay it on `route::tests::Sim` as the skill says before calling it a bug. +- The doubt's timer is a step that may fire at any moment, as the model has + it. That every hold ends stays an argument in the skill (`Budget`, + `QuietIsSettled`), not a checked rule. +- Run it through `sh/tla.sh` with an `Apalache:` line in its configs, as + `RouteClaims.cfg` does. + +## Related + +- [Route sweeps are checked against the TLA+ model](/quest/m1/route-trace-validation.md) - ties the same spec to the code From b9920a6ac7891e454a7c811bab297a4722c70a35 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Nov 2026 18:25:24 -0800 Subject: [PATCH 6/6] test(net): prove the route claim rules for runs of any length RouteClaims.tla keeps only what the claim rules need, with no paths. RouteHandoff refines it (RefinesClaims on every passing config), and Apalache checks its inductive invariant: IndInv holds at Init and every step keeps it. sh/tla.sh runs a config with an Apalache: line through Apalache, and picks the directory's root spec for a config named after none. RouteHandoff.tla drops the annotations and folds. Co-Authored-By: Claude Opus 5.5 --- .claude/skills/verify-route/SKILL.md | 17 ++- quest/m1/route-inductive.md | 110 -------------------- quest/m1/route-trace-validation.md | 5 +- quest/m2/cluster-routing/routes/README.md | 2 +- rs/moq-net/verify/route/Blind.cfg | 3 + rs/moq-net/verify/route/Dead.cfg | 3 + rs/moq-net/verify/route/Early.cfg | 3 + rs/moq-net/verify/route/Lag.cfg | 3 + rs/moq-net/verify/route/LagWide.cfg | 3 + rs/moq-net/verify/route/Ring.cfg | 3 + rs/moq-net/verify/route/RouteClaims.cfg | 17 +++ rs/moq-net/verify/route/RouteClaims.tla | 76 ++++++++------ rs/moq-net/verify/route/RouteClaimsInit.cfg | 13 +++ rs/moq-net/verify/route/RouteHandoff.cfg | 3 + rs/moq-net/verify/route/RouteHandoff.tla | 1 + rs/moq-net/verify/route/Twice.cfg | 3 + sh/tla.sh | 24 ++++- 17 files changed, 139 insertions(+), 150 deletions(-) delete mode 100644 quest/m1/route-inductive.md create mode 100644 rs/moq-net/verify/route/RouteClaims.cfg create mode 100644 rs/moq-net/verify/route/RouteClaimsInit.cfg diff --git a/.claude/skills/verify-route/SKILL.md b/.claude/skills/verify-route/SKILL.md index 2f772191f50..347585bb5f9 100644 --- a/.claude/skills/verify-route/SKILL.md +++ b/.claude/skills/verify-route/SKILL.md @@ -1,6 +1,6 @@ --- name: verify-route -description: Model-check the lite-07 route rule (`rs/moq-net/verify/route/RouteHandoff.tla`, the rule the routes epic's Plan item 27 picked, as `rs/moq-net/src/route/tests/paths.rs` prototypes it) with TLA+. Use when a change touches route paths, the DEAD message for a closed session, holds, the doubt and its timer, forgetting dead hops, routes per prefix and scoped streams, the newest-floor views, what a reader is shown, or where a request goes, or when a routing bug needs every message ordering checked rather than a random sweep. +description: Model-check the lite-07 route rule (`rs/moq-net/verify/route/RouteHandoff.tla`, the rule the routes epic's Plan item 27 picked, as `rs/moq-net/src/route/tests/paths.rs` prototypes it) with TLA+. Use when a change touches route paths, the DEAD message for a closed session, holds, the doubt and its timer, forgetting dead hops, routes per prefix and scoped streams, the newest-floor views, what a reader is shown, or where a request goes, or when a routing bug needs every message ordering checked rather than a random sweep. Also covers `RouteClaims.tla`, the claims model with no paths that it refines, where Apalache proves the claim rules for runs of any length. --- # Verify the route rule @@ -27,6 +27,12 @@ Each rule is an INVARIANT; the harm says why it matters. | `Budget` | From one quiet point to the next, the messages sent stay within 4 each way over each configured session per prefix and per claim, for each external change. | One change sets off announce spam, or routing never goes quiet. | | `RequestsLoopFree` | A request never loops. | Only `Loop.cfg` checks it, as an open finding. | +## Runs of any length + +TLC checks bounded runs. `RouteClaims.tla` keeps only what the claim rules need, with no paths: every step, any relay's routes may come and go, and claims in flight may arrive in any order, again, or never. Each config's `RefinesClaims` checks that every step of `RouteHandoff.tla` is a step there, and its `Truthful`, `NoRevival`, `NoFalseEnd`, and `NoRegression` are this model's under that mapping. Apalache checks that `IndInv` holds at `Init` (`RouteClaimsInit.cfg`) and that every step from a state where it holds keeps it (`RouteClaims.cfg`), so those four rules hold for any number of revisions, sessions, and route changes. + +What stays bounded: the nodes and claims the configs name, and the two claims in flight the step check starts from. The step check keeps one relay's state with five neighbours; one relay's step stands for every relay's because relays share only the claims in flight, and what a relay sends is its own view. That argument, and that a longer history than the floors name changes nothing, are not checked. The loop rules (`SimplePaths`, `LoopsAreStale`, `StaleIsChased`) have no such proof yet: [the loop rules quest](/quest/m1/route-loops.md). + No config checks a liveness property: `Spec` has no fairness, so TLC does not show that a hold ends. That one does is an argument over what TLC does check. `Budget` bounds the messages a burst sends, each delivery takes one message off a queue, and a doubt starts only at a close or a delivery, so a burst is a finite number of steps. A delivery is enabled while a queue holds a message and a timer may fire once no news about its node is in flight, so a burst left alone reaches the state with nothing in flight and no doubt. `QuietIsSettled` says no relay holds there. What the timer costs, as the configs show it: fired late, it costs only the wait, and every rule holds (`RouteHandoff.cfg`). Fired early, a stale route can return, as with no doubt at all, and nothing else breaks (`Early.cfg`, which passes without `NoStaleReturn` and fails it within seconds with it). With two failures a stale route can return whatever the timer (`Twice.cfg` drops `NoStaleReturn`), and `StaleIsChased` is the bound. @@ -36,14 +42,15 @@ What the timer costs, as the configs show it: fired late, it costs only the wait ```sh just rs tla moq-net/verify/route/RouteHandoff.tla just rs tla moq-net/verify/route/RouteHandoff.tla -config rs/moq-net/verify/route/Ring.cfg +just test tla rs/moq-net/verify/route/RouteClaims.cfg just test tla rs/moq-net/verify/route ``` -`just test tla rs/moq-net/verify/route` runs every config, as Nightly does, simulating each one with a `Simulate:` line and expecting `Loop.cfg` to break. Times are with `-workers 4`. `Patient` is TRUE unless the table says otherwise. +`just test tla rs/moq-net/verify/route` runs every config, as Nightly does, simulating each one with a `Simulate:` line, checking each with an `Apalache:` line through Apalache, and expecting `Loop.cfg` to break. Every TLC config but `Loop.cfg` also checks `RefinesClaims`, which costs about two thirds more time. Times are with `-workers 4`. `Patient` is TRUE unless the table says otherwise. | Config | Mesh | Bounds | Distinct states | Run | | --- | --- | --- | --- | --- | -| `RouteHandoff.cfg` | The publisher behind relay 1, in a triangle with relays 2 and 3. | 1 claim change, 1 session change | 407,240 | a minute or two | +| `RouteHandoff.cfg` | The publisher behind relay 1, in a triangle with relays 2 and 3. | 1 claim change, 1 session change | 407,240 | five minutes | | `Early.cfg` | The same, with a timer that fires at any moment. | 1 claim change, 1 session change | 4,178,590 | ten minutes | | `Twice.cfg` | The same, where two sessions close, as when relay 1 dies. Simulated: `num` counts behaviours per worker. | 1 claim change, 2 session changes | 40,000 behaviours, 4.0M states | a few minutes | | `Ring.cfg` | The publisher and three relays in a ring, with a timer that fires at any moment. | 1 claim change, 1 session change | 426,409 | a minute or two | @@ -52,6 +59,8 @@ just test tla rs/moq-net/verify/route | `Dead.cfg` | Two relays behind a relay whose only uplink asks for `"a"` alone, one with a dear session of its own to the publisher. Simulated. | 3 claim changes, 1 session change | 40,000 behaviours, 4.8M states | ten minutes | | `Blind.cfg` | A relay whose nearest neighbour asks for `"a"` alone, and a farther one knows everything. Simulated. | 2 claim changes, 1 session change | 40,000 behaviours, 4.8M states | ten minutes | | `Loop.cfg` | The publisher with a session to each of three relays in a triangle, all closing. Open finding: `RequestsLoopFree` breaks. | 3 session changes | 979,474 when it breaks | a few minutes | +| `RouteClaims.cfg` | Apalache: one step of `RouteClaims.tla` from any state where `IndInv` holds, for one relay with five neighbours. | 2 claims in flight | none | twelve minutes | +| `RouteClaimsInit.cfg` | Apalache: `IndInv` holds at `Init`, with five relays. | none | none | seconds | Run them last, one at a time. First run what answers in seconds: the prototype's tests (`just rs test -p moq-net --lib -E 'test(/route::tests::(paths|compare|copies)/)'`), then TLC's simulation mode with raised bounds in a copy of a config, such as `-simulate num=3000 -depth 150`. @@ -61,7 +70,7 @@ Follow Reading a failure in `rs/moq-net/verify/README.md`. Replay the path on th ## Coverage -Sync commit: `d3b6c2573a30541402d396f8080488646f673594`. Run `git log d3b6c2573a.. -- rs/moq-net/src/route/tests/paths.rs` to see what changed since. The model describes the prototype, extended with a route per prefix and with dead hops kept until their timer fires; `route::Router` does not run this rule yet. `Relay::collect` forgets a dead hop as soon as no route names it, so `NoStaleReturn` covers the rule the router is to run, not the prototype's. Follow Coverage in `rs/moq-net/verify/README.md` after a change to a covered function. +Sync commit: `d3b6c2573a30541402d396f8080488646f673594`. Run `git log d3b6c2573a.. -- rs/moq-net/src/route/tests/paths.rs` to see what changed since. The model describes the prototype, extended with a route per prefix and with dead hops kept until their timer fires; `route::Router` does not run this rule yet. `Relay::collect` forgets a dead hop as soon as no route names it, so `NoStaleReturn` covers the rule the router is to run, not the prototype's. Follow Coverage in `rs/moq-net/verify/README.md` after a change to a covered function. `RouteClaims.tla` repeats `Know`, `ShownNow`, and the reader's events in `Events`: a change to them changes it too, and `RefinesClaims` fails until it does. | Code | Model | | --- | --- | diff --git a/quest/m1/route-inductive.md b/quest/m1/route-inductive.md deleted file mode 100644 index ef1585f2373..00000000000 --- a/quest/m1/route-inductive.md +++ /dev/null @@ -1,110 +0,0 @@ -# [L] The route rules hold from any state, not only the runs TLC reaches - -## Goal - -An inductive invariant of the route model implies `NoRevival`, `NoFalseEnd`, -`NoRegression`, `Truthful`, and the loop rule the model proves for the path -rule: no relay uses a route whose path names it, and selected next hops loop -only within the bound the model (`rs/moq-net/verify/route/RouteHandoff.tla`) -found: through a stale route whose news is on its way (`LoopsAreStale`, -`StaleIsChased`). Apalache -checks in Nightly that it holds initially and that every step preserves it -from any state satisfying it, on each mesh shape of up to five relays. The -rules then hold for runs of any length and any number of changes, where -TLC's pass covers one claim, two revisions, and two session opens or closes. - -## Plan - -Decided 2026-11-10 (maintainer, /quest-plan on what could be proved about -moq-net): - -- ✅ An inductive invariant checked by Apalache (rejected: a TLAPS proof for - every mesh size, whose hand-written steps break on each model change, until - this invariant has settled; verifying the Rust itself in Verus or Lean, - which needs the code rewritten around the prover). -- ✅ m1 (rejected: m4), because a flaw in the routing design is cheapest to - fix before lite-07 is cut. It does not gate the cut: a flaw it finds becomes - a fix quest that joins [Finalize moq-lite-07](/quest/m2/lite07-finalize.md) - then. - -Decided 2026-11-12 (maintainer, /quest-plan on the quests still written for -Babel), asked what happens to this quest now that the route rule is the path -([routes epic](/quest/m2/cluster-routing/routes/README.md) Plan item 27): -✅ keep it in m1, rewritten for the path rule (rejected: m4, since the path -argument is simpler than Babel's; deleting it and resting on the bounded -TLC runs and the sweeps). The claim rules are where the stale copies were, -and they are what a bounded run covers least. `LoopFree` leaves the Goal as -an invariant: under the path rule selected next hops can loop for a moment -when two unrelated things fail at once, which the maintainer accepted, so -the invariant implies the bound the model states instead. - -What it removes is the bound on the run, not on the mesh: revisions, -sessions, and churn are unbounded, while the relay count and queue lengths -stay constants the config states. Say both bounds in the `verify-route` skill. - -- Start from the path argument: no relay holds or selects a route whose path - names it, every route in flight extends the path its sender held when it - sent it, and every withdrawal in flight names a hop whose session closed. - The doubt's timer is a step that may fire at any moment, as the model has - it. Strengthen until Apalache finds no counterexample to induction. -- A counterexample to induction starts from a state that may be unreachable. - If TLC cannot reach it, the invariant is too weak: strengthen it. If it can, - replay it on `route::tests::Sim` as the skill says before calling it a bug. -- Apalache needs type annotations. Add them to the spec TLC already checks, - so both tools read one file and neither drifts. -- `NoCountToInfinity` follows from `SimplePaths`, which is inductive once - the invariant also says a route is held only from a node the holder shares - a link with: every route sent adds its sender to hops that did not name it - ([moq-dev/moq#8487](https://github.com/moq-dev/moq/pull/8487)). Start there. -- Apalache checks safety. That every hold ends is no checked rule: the - model has no fairness, and the `verify-route` skill argues it from - `Budget` and `QuietIsSettled`. Leave it there. -- Run it through the `tla` recipes with Apalache from the flake. If five - relays does not fit Nightly, record the largest mesh that does and its time. - -Found 2026-11-12, trying it on the route model itself -([moq-dev/moq#8564](https://github.com/moq-dev/moq/pull/8564)): - -- The spec there carries Apalache's type annotations and its folds in place - of `RECURSIVE` operators, and `just rs apalache typecheck - moq-net/verify/route/RouteHandoff.tla` passes. TLC reads the same file - through Apalache's library (`nix/apalache.nix`, the `tla` recipe) and finds - the same distinct states as before on every exhaustive config. -- No mesh fits. Apalache 0.63 could not finish one step with `SimplePaths` - as the only invariant, on a host with 16 GB of heap to give it: - - | Check | Mesh | Result | - | --- | --- | --- | - | One step from `Init`, all 7 transitions | publisher and 3 relays | out of heap after 26 minutes | - | One `Deliver` on one session, from any typed state | publisher and 3 relays | out of heap after 6 minutes | - | The same, `--smt-encoding=arrays` | publisher and 3 relays | still in its optimizer pass after 85 minutes | - | The same | publisher and 2 relays, the smallest mesh with a loop | past 19 GB in 8 minutes, killed | - -- Why: every step runs `Update`, which rebuilds a node's whole state, so the - solver encodes every neighbour's and key's route with its path, the views, - what the node sent, and its reader's events, for every step. That state, - not the invariant, is what does not fit. -- The rules split along the model. The claim rules (`Truthful`, - `NoRevival`, `NoFalseEnd`, `NoRegression`) need no paths: a view's floor - only grows while a route covers it, each floor is the publisher's claims at - its revision, and an item is the revision that set it. They should hold - however routes come and go, which is argued, not yet checked. The loop - rules (`SimplePaths`, `LoopsAreStale`, `StaleIsChased`) need routes, DEAD, - holds, and doubts, but no claims, views, or events. - -Decided 2026-11-12 (maintainer, /quest-unblock): ✅ split the model -(rejected: a TLAPS proof on the route model; deleting the quest and resting -on TLC's bounded runs and the sweeps; a host with far more memory). This -quest proves the claim rules (`Truthful`, `NoRevival`, `NoFalseEnd`, -`NoRegression`) on a small model with no paths, where routes come and go -freely. [A follow-up](/quest/m1/route-loops.md) proves the loop rules -(`SimplePaths`, `LoopsAreStale`, `StaleIsChased`) on a model without claims, -after first measuring that Apalache fits it. TLC refinement-checks each model -against `RouteHandoff.tla`. This PR keeps the Apalache package and the `tla` -recipe, and drops the annotations and folds from `RouteHandoff.tla`. - -Public API: none. Wire: none. - -## Related - -- [Route sweeps are checked against the TLA+ model](/quest/m1/route-trace-validation.md) - ties the same spec to the code diff --git a/quest/m1/route-trace-validation.md b/quest/m1/route-trace-validation.md index f39fb401771..25b5e57e04c 100644 --- a/quest/m1/route-trace-validation.md +++ b/quest/m1/route-trace-validation.md @@ -14,8 +14,9 @@ the route model drifting from the code ([moq-dev/moq#8447](https://github.com/mo Decided 2026-11-10 (maintainer, a later /quest-plan the same day): -- ✅ m1 (rejected: staying in m4). The mesh configs beside it, the - [inductive invariant](/quest/m1/route-inductive.md), and the +- ✅ m1 (rejected: staying in m4). The mesh configs beside it, the claims + model it refines (`RouteClaims.tla`), the + [loop rules proof](/quest/m1/route-loops.md), and the [cache-aware routing proof](/quest/m2/cache-routing-proof.md) all build on `RouteHandoff.tla`, so drift there costs the most. - ✅ The other three models get trace validation too, each its own m4 quest diff --git a/quest/m2/cluster-routing/routes/README.md b/quest/m2/cluster-routing/routes/README.md index 2012786db31..17ca801834f 100644 --- a/quest/m2/cluster-routing/routes/README.md +++ b/quest/m2/cluster-routing/routes/README.md @@ -53,7 +53,7 @@ The items below were decided 2026-11-10 (maintainer, /quest-plan on lite-07 rout Measured on 24 relays (the mesh sweep's sparse shape, 16 seeds), against today's router, with the doubt lasting 4 hops of delay: a detour settles in 12 hops of delay where the distance takes 15.7, and in 6.2 where it does not run through the far end of the closed link; the publisher's relay dying costs 124 route messages where the distance costs 276, with no loop and 6 claims sent again; and a link closing in a clique costs 44 messages with one publisher behind it and 198 with eight, where the distance costs 621 and 5,024. Accepted: a detour through the far end of a closed link waits the timer out; selected routes can loop for a moment when two unrelated things fail at once (32 of 120,000 churn steps), which the distance never does; and holds and doubt have passed sweeps and no model. The timer's length is the model's and the router's to settle, from the maintainer's 1 s. Rejected: Babel's distance; paths with nothing else, which hunt through stale paths (65,219 messages for one publisher leaving a clique of 12); no doubt, which loops when a relay with several neighbours dies; and a doubt lifted by an epoch the node floods, which resolves in a couple of hops but costs a message per session on each relay-to-relay close ("Epoches are a bit scary in terms of messages"). -28. ✅ Decided 2026-11-12 (maintainer, /quest-plan on the quests still written for Babel), asked how item 27's removal is split and ordered: **the router first with no wire change, then a switch of the sessions, and the switch lands before the route stream.** [The router](/quest/m2/cluster-routing/routes/scope.md) runs the path rule with a route per scope, sans-IO, beside today's router. [The switch](/quest/m2/cluster-routing/routes/switch.md) puts it on the lite-07-wip wire, the draft, the Rust sessions, and `js/net`, and deletes Babel's router. [The interest set](/quest/m2/cluster-routing/routes/interest-set.md) then edits the path router only, and [the route stream](/quest/m2/cluster-routing/routes/route-stream.md) follows the switch with no echo or route request to carry. The switch's recommended wire puts the answer that ends a hold on the publisher half, behind the routes its sender sent first, so the path rule needs no order between streams that today's sessions lack for one prefix. [Acceptance](/quest/m2/cluster-routing/routes/acceptance.md) is of the switched sessions, and [the inductive invariant](/quest/m1/route-inductive.md) stays in m1, rewritten for the path, without `LoopFree` as an invariant. Rejected: the router quest in m1; one quest for router, wire, draft, sessions, and `js/net`; the route stream first, which builds the echo and ROUTE_REQUEST on the new stream and then deletes them; one wire change for the path rule and the one stream together; moving the inductive invariant to m4; deleting it. +28. ✅ Decided 2026-11-12 (maintainer, /quest-plan on the quests still written for Babel), asked how item 27's removal is split and ordered: **the router first with no wire change, then a switch of the sessions, and the switch lands before the route stream.** [The router](/quest/m2/cluster-routing/routes/scope.md) runs the path rule with a route per scope, sans-IO, beside today's router. [The switch](/quest/m2/cluster-routing/routes/switch.md) puts it on the lite-07-wip wire, the draft, the Rust sessions, and `js/net`, and deletes Babel's router. [The interest set](/quest/m2/cluster-routing/routes/interest-set.md) then edits the path router only, and [the route stream](/quest/m2/cluster-routing/routes/route-stream.md) follows the switch with no echo or route request to carry. The switch's recommended wire puts the answer that ends a hold on the publisher half, behind the routes its sender sent first, so the path rule needs no order between streams that today's sessions lack for one prefix. [Acceptance](/quest/m2/cluster-routing/routes/acceptance.md) is of the switched sessions, and the inductive invariant stays in m1, rewritten for the path, without `LoopFree` as an invariant: [moq-dev/moq#8564](https://github.com/moq-dev/moq/pull/8564) later proved its claim rules, and [the loop rules](/quest/m1/route-loops.md) remain. Rejected: the router quest in m1; one quest for router, wire, draft, sessions, and `js/net`; the route stream first, which builds the echo and ROUTE_REQUEST on the new stream and then deletes them; one wire change for the path rule and the one stream together; moving the inductive invariant to m4; deleting it. The route layer's core landed in [moq-dev/moq#7676](https://github.com/moq-dev/moq/pull/7676): a diff --git a/rs/moq-net/verify/route/Blind.cfg b/rs/moq-net/verify/route/Blind.cfg index 750ac81f68d..b24db276c03 100644 --- a/rs/moq-net/verify/route/Blind.cfg +++ b/rs/moq-net/verify/route/Blind.cfg @@ -31,3 +31,6 @@ INVARIANTS NoStaleReturn QuietIsSettled Budget + +PROPERTY + RefinesClaims diff --git a/rs/moq-net/verify/route/Dead.cfg b/rs/moq-net/verify/route/Dead.cfg index a6c0d9ac55c..19f0ec07de1 100644 --- a/rs/moq-net/verify/route/Dead.cfg +++ b/rs/moq-net/verify/route/Dead.cfg @@ -32,3 +32,6 @@ INVARIANTS NoStaleReturn QuietIsSettled Budget + +PROPERTY + RefinesClaims diff --git a/rs/moq-net/verify/route/Early.cfg b/rs/moq-net/verify/route/Early.cfg index c5f1c3f9f4a..1821b9f5695 100644 --- a/rs/moq-net/verify/route/Early.cfg +++ b/rs/moq-net/verify/route/Early.cfg @@ -27,3 +27,6 @@ INVARIANTS StaleIsChased QuietIsSettled Budget + +PROPERTY + RefinesClaims diff --git a/rs/moq-net/verify/route/Lag.cfg b/rs/moq-net/verify/route/Lag.cfg index f11ccb79398..65a7ea12292 100644 --- a/rs/moq-net/verify/route/Lag.cfg +++ b/rs/moq-net/verify/route/Lag.cfg @@ -29,3 +29,6 @@ INVARIANTS NoStaleReturn QuietIsSettled Budget + +PROPERTY + RefinesClaims diff --git a/rs/moq-net/verify/route/LagWide.cfg b/rs/moq-net/verify/route/LagWide.cfg index 38cbc263585..53aa4f5fe52 100644 --- a/rs/moq-net/verify/route/LagWide.cfg +++ b/rs/moq-net/verify/route/LagWide.cfg @@ -27,3 +27,6 @@ INVARIANTS NoStaleReturn QuietIsSettled Budget + +PROPERTY + RefinesClaims diff --git a/rs/moq-net/verify/route/Ring.cfg b/rs/moq-net/verify/route/Ring.cfg index 6eb3e4b0ba5..139e2db9272 100644 --- a/rs/moq-net/verify/route/Ring.cfg +++ b/rs/moq-net/verify/route/Ring.cfg @@ -28,3 +28,6 @@ INVARIANTS StaleIsChased QuietIsSettled Budget + +PROPERTY + RefinesClaims diff --git a/rs/moq-net/verify/route/RouteClaims.cfg b/rs/moq-net/verify/route/RouteClaims.cfg new file mode 100644 index 00000000000..329b67add01 --- /dev/null +++ b/rs/moq-net/verify/route/RouteClaims.cfg @@ -0,0 +1,17 @@ +\* The induction step: from any state where `IndInv` holds, with two claims +\* in flight, every step keeps it. One relay with five neighbours stands for +\* every relay: relays share only the claims in flight, and each relay's own +\* step keeps what it sends truthful. Invariants are checked after the step +\* only, since `IndInit` assumes them before it. +\* Apalache: --length=1 --tuning-options=search.invariantFilter=1->.* +CONSTANTS + Nodes = {0, 1, 2, 3, 4, 5} + Origin = 0 + Relays = {1} + Claims = {"ax", "bx"} + Narrow = {"ax"} + MaxFlight = 2 + +INIT IndInit +NEXT Next +INVARIANT IndInv diff --git a/rs/moq-net/verify/route/RouteClaims.tla b/rs/moq-net/verify/route/RouteClaims.tla index 9bb474c988f..50ef84087c2 100644 --- a/rs/moq-net/verify/route/RouteClaims.tla +++ b/rs/moq-net/verify/route/RouteClaims.tla @@ -7,13 +7,19 @@ (* reach any relay, in any order, any number of times, or never. *) (* *) (* Every floor carries `full`, the publisher's claims at its revision, so *) -(* a floor is truthful when its items are `full` within its key. Nothing *) -(* reads `full` but the rules: it stands for RouteHandoff's history. *) +(* a floor is truthful when its items are `full` within its key, and *) +(* `hist` keeps every revision with its claims. Nothing reads either but *) +(* the rules: they stand for RouteHandoff's history. *) (* *) (* RouteHandoff refines this model (its `RefinesClaims`), so the claim *) (* rules here hold there too. Apalache checks that `IndInv` holds at *) (* `Init` and that every step keeps it, so they hold for runs of any *) -(* length: revisions, sessions, and route changes are unbounded. *) +(* length: revisions, sessions, and route changes are unbounded. The *) +(* bounds are the nodes and claims the configs name and the claims in *) +(* flight `IndInit` starts from. The step check keeps one relay's state, *) +(* with five neighbours: relays share only the claims in flight, and what *) +(* each sends is its own view, which its own step keeps truthful, so one *) +(* relay's step stands for every relay's. *) (***************************************************************************) EXTENDS Integers, FiniteSets, Apalache @@ -22,6 +28,8 @@ CONSTANTS Nodes, \* relays and the publisher \* @type: Int; Origin, \* the publisher + \* @type: Set(Int); + Relays, \* the relays whose state the model keeps; any other node only sends \* @type: Set(Str); Claims, \* claim paths \* @type: Set(Str); @@ -34,6 +42,7 @@ CONSTANTS \* @typeAlias: view = { floor: Int, items: Str -> Int, full: Str -> Int }; \* @typeAlias: msg = { k: Str, rev: Int, items: Str -> Int, full: Str -> Int }; \* @typeAlias: shown = { item: Int, avail: Bool }; +\* @typeAlias: past = { rev: Int, full: Str -> Int }; \* Every relay's state is one function keyed by relay first, since Apalache \* cannot pick a function of functions. \* @typeAlias: heard = <> -> Str; @@ -42,8 +51,6 @@ CONSTANTS \* @typeAlias: views = <> -> $view; RouteClaims_aliases == TRUE -Relays == Nodes \ {Origin} - \* A claim's item, the revision that last set it, or None when absent. None == -1 \* A view's floor: a revision, None for no floor yet, or Absent for no view. @@ -81,6 +88,8 @@ VARIABLES rev, \* the publisher's claim revision \* @type: Str -> Int; own, \* the publisher's claims + \* @type: Set($past); + hist, \* every revision the publisher passed, with its claims then \* @type: $heard; heard, \* heard[<>]: the route n heard from m for key k \* @type: $offered; @@ -102,7 +111,7 @@ VARIABLES \* @type: Int; regressions \* reader UPDATEs to an older item -vars == <> ----------------------------------------------------------------------------- @@ -146,6 +155,7 @@ Sends(n, rv, ow, vw) == Init == /\ rev = 0 /\ own = NoItems + /\ hist = {[rev |-> 0, full |-> NoItems]} /\ heard = [x \in HeardIdx |-> "off"] /\ offered = [x \in HeardIdx |-> NoFloor] /\ route = [x \in KeyIdx |-> "none"] @@ -157,13 +167,13 @@ Init == /\ falseEnds = 0 /\ regressions = 0 -\* The publisher keeps its claims or changes one. +\* The publisher keeps its claims or changes one, in one transition so that +\* Apalache checks one step. Publish == - \/ rev' = rev /\ own' = own - \/ \E c \in Claims, item \in {rev + 1, None} : - /\ item = None => own[c] # None - /\ rev' = rev + 1 - /\ own' = [own EXCEPT ![c] = item] + \E change \in BOOLEAN, c \in Claims, item \in {rev + 1, None} : + /\ change /\ item = None => own[c] # None + /\ rev' = IF change THEN rev + 1 ELSE rev + /\ own' = IF change THEN [own EXCEPT ![c] = item] ELSE own \* One step: the publisher may change a claim, and every relay's routes may \* change. A route that stays on may take any claims in flight under its @@ -172,6 +182,7 @@ Publish == \* views, while any message in flight may be lost. Next == /\ Publish + /\ hist' = hist \cup {[rev |-> rev', full |-> own']} /\ heard' \in [HeardIdx -> Hearings] /\ route' \in [KeyIdx -> Routings] /\ LET arrived == {[rev |-> y.rev, items |-> y.items, full |-> y.full] : y \in flight} @@ -199,7 +210,7 @@ Next == /\ revivals' = revivals + Cardinality({x \in ClaimIdx : isStart(x) /\ ended[x] = shown'[x].item}) /\ falseEnds' = falseEnds + Cardinality({x \in ClaimIdx : isEnd(x) /\ own'[x[2]] = shown[x].item}) /\ regressions' = regressions + Cardinality({x \in ClaimIdx : isUpdate(x) /\ shown'[x].item < shown[x].item}) - /\ flight' \in SUBSET (flight \cup UNION {Sends(n, rev', own', view') : n \in Nodes}) + /\ flight' \in SUBSET (flight \cup UNION {Sends(n, rev', own', view') : n \in {Origin} \cup Relays}) Spec == Init /\ [][Next]_vars @@ -227,33 +238,33 @@ NoRegression == regressions = 0 (* each floor is the publisher's claims at its revision, and an item is *) (* the revision that set it, so a newer floor never names an older item. *) -\* Every revision the state names, with the publisher's claims then. -Fulls == - {[rev |-> rev, full |-> own]} - \cup {[rev |-> view[x].floor, full |-> view[x].full] : x \in KeyIdx} - \cup {[rev |-> offered[x].rev, full |-> offered[x].full] : x \in HeardIdx} - \cup {[rev |-> y.rev, full |-> y.full] : y \in flight} +\* Revisions r1 <= r2 of one history: an item r2 has that was set by r1 +\* is r1's item too. +\* @type: ($past, $past) => Bool; +Agree(f, g) == + \A c \in Claims : + f.rev <= g.rev /\ g.full[c] # None /\ g.full[c] <= f.rev => f.full[c] = g.full[c] -\* A floor: None with no claims, or a revision the publisher has passed with -\* its claims then, within key k. +\* A floor: None with no claims, or a revision the publisher passed, with +\* its claims then within key k. \* @type: (Str, Int, Str -> Int, Str -> Int) => Bool; Sound(k, r, items, full) == \/ r = None /\ items = NoItems /\ full = NoItems - \/ 0 <= r /\ r <= rev /\ items = Restrict(full, k) + \/ [rev |-> r, full |-> full] \in hist /\ items = Restrict(full, k) IndInv == /\ Truthful /\ NoRevival /\ NoFalseEnd /\ NoRegression - \* The history the floors name: an item is the revision that set it, and - \* it stays set until a later revision changes it. + \* The history: an item is the revision that set it, and it stays set + \* until a later revision changes it. /\ rev >= 0 - /\ \A f \in Fulls, c \in Claims : f.rev >= 0 => - f.full[c] = None \/ (1 <= f.full[c] /\ f.full[c] <= f.rev) - /\ \A f, g \in Fulls, c \in Claims : - 0 <= f.rev /\ f.rev <= g.rev /\ g.full[c] # None /\ g.full[c] <= f.rev => - f.full[c] = g.full[c] + /\ [rev |-> rev, full |-> own] \in hist + /\ \A h \in hist : + /\ 0 <= h.rev /\ h.rev <= rev + /\ \A c \in Claims : h.full[c] = None \/ (1 <= h.full[c] /\ h.full[c] <= h.rev) + /\ \A h, g \in hist : Agree(h, g) \* Every floor is sound, and a route that is off gave none. /\ \A y \in flight : y.k \in Keys /\ Sound(y.k, y.rev, y.items, y.full) /\ \A x \in HeardIdx : @@ -290,6 +301,13 @@ IndInit == /\ ended \in [ClaimIdx -> Int] /\ flight = Gen(MaxFlight) /\ \A y \in flight : DOMAIN y.items = Claims /\ DOMAIN y.full = Claims + \* Just the revisions the state names. A longer history adds entries no + \* floor names, which a step only checks against its new revision, as + \* it does these. + /\ hist = {[rev |-> rev, full |-> own]} + \cup {[rev |-> view[x].floor, full |-> view[x].full] : x \in {z \in KeyIdx : view[z].floor >= 0}} + \cup {[rev |-> offered[x].rev, full |-> offered[x].full] : x \in {z \in HeardIdx : offered[z].rev >= 0}} + \cup {[rev |-> y.rev, full |-> y.full] : y \in {z \in flight : z.rev >= 0}} /\ revivals \in Int /\ falseEnds \in Int /\ regressions \in Int diff --git a/rs/moq-net/verify/route/RouteClaimsInit.cfg b/rs/moq-net/verify/route/RouteClaimsInit.cfg new file mode 100644 index 00000000000..8e385ec2633 --- /dev/null +++ b/rs/moq-net/verify/route/RouteClaimsInit.cfg @@ -0,0 +1,13 @@ +\* The base case: `IndInv` holds initially, here with five relays. +\* Apalache: --length=0 +CONSTANTS + Nodes = {0, 1, 2, 3, 4, 5} + Origin = 0 + Relays = {1, 2, 3, 4, 5} + Claims = {"ax", "bx"} + Narrow = {"ax"} + MaxFlight = 0 + +INIT Init +NEXT Next +INVARIANT IndInv diff --git a/rs/moq-net/verify/route/RouteHandoff.cfg b/rs/moq-net/verify/route/RouteHandoff.cfg index 9f59549e023..529a121f072 100644 --- a/rs/moq-net/verify/route/RouteHandoff.cfg +++ b/rs/moq-net/verify/route/RouteHandoff.cfg @@ -29,3 +29,6 @@ INVARIANTS NoStaleReturn QuietIsSettled Budget + +PROPERTY + RefinesClaims diff --git a/rs/moq-net/verify/route/RouteHandoff.tla b/rs/moq-net/verify/route/RouteHandoff.tla index b0bd35613df..eae71c2f152 100644 --- a/rs/moq-net/verify/route/RouteHandoff.tla +++ b/rs/moq-net/verify/route/RouteHandoff.tla @@ -783,6 +783,7 @@ ClaimsOn(d) == i \in {j \in DOMAIN q[d] : q[d][j].t = "claims"}} Claimed == INSTANCE RouteClaims WITH + hist <- {[rev |-> r, full |-> hist[r + 1]] : r \in 0..rev}, heard <- [x \in Relays \X Nodes \X Keys |-> Hearing(x[1], x[2], x[3])], offered <- [x \in Relays \X Nodes \X Keys |-> LET h == st[x[1]].rx[x[2]][x[3]] IN [rev |-> h.rev, items |-> h.items, full |-> Full(h.rev)]], diff --git a/rs/moq-net/verify/route/Twice.cfg b/rs/moq-net/verify/route/Twice.cfg index e4f3a2ef766..86162001a63 100644 --- a/rs/moq-net/verify/route/Twice.cfg +++ b/rs/moq-net/verify/route/Twice.cfg @@ -29,3 +29,6 @@ INVARIANTS StaleIsChased QuietIsSettled Budget + +PROPERTY + RefinesClaims diff --git a/sh/tla.sh b/sh/tla.sh index 742441e63e8..a7302e98c7f 100755 --- a/sh/tla.sh +++ b/sh/tla.sh @@ -4,7 +4,8 @@ # a rule (a deadlock, invariant, property, or assertion), so a fix that should # promote its rule is noticed; every other config must pass. A config with a # `\* Simulate:` line is too large to exhaust: TLC samples it at random with the -# arguments that line gives. +# arguments that line gives. A config with an `\* Apalache:` line is checked +# by Apalache instead, with the arguments that line gives. set -euo pipefail shopt -s nullglob cd "$(git rev-parse --show-toplevel)" @@ -21,7 +22,8 @@ for cfg in "${configs[@]}"; do # The index still lists a config deleted but not yet staged. [ -f "$cfg" ] || continue # The directory's spec, or where it holds several, the one the config's name - # starts with. TLC's trace-exploration output (`*_TTrace_*.tla`) is no spec. + # starts with, else the one no other spec there extends or instantiates. + # TLC's trace-exploration output (`*_TTrace_*.tla`) is no spec. dir=$(dirname "$cfg") name=$(basename "$cfg") specs=() @@ -34,6 +36,12 @@ for cfg in "${configs[@]}"; do for spec in "${all[@]}"; do [[ "$name" != "$(basename "$spec" .tla)"* ]] || specs+=("$spec") done + if [ ${#specs[@]} -eq 0 ]; then + for spec in "${all[@]}"; do + module=$(basename "$spec" .tla) + grep -qE "^[^\\]*\b(EXTENDS|INSTANCE)\b.*\b$module\b" "${all[@]}" || specs+=("$spec") + done + fi fi if [ ${#specs[@]} -ne 1 ]; then failed+=("$cfg: no single spec in $dir") @@ -43,16 +51,24 @@ for cfg in "${configs[@]}"; do finding=false ! grep -q '^\\\* Open finding:' "$cfg" || finding=true read -ra simulate < <(sed -n 's/^\\\* Simulate: //p' "$cfg") || true + apalache=false + ! grep -q '^\\\* Apalache:' "$cfg" || apalache=true + read -ra checks < <(sed -n 's/^\\\* Apalache: //p' "$cfg") || true echo "::group::$cfg" start=$SECONDS status=0 - just "$lang" tla "${specs[0]#"$lang"/}" -config "$cfg" "${simulate[@]}" || status=$? + if $apalache; then + just "$lang" apalache check "${specs[0]#"$lang"/}" --config="$cfg" "${checks[@]}" || status=$? + else + just "$lang" tla "${specs[0]#"$lang"/}" -config "$cfg" "${simulate[@]}" || status=$? + fi echo "::endgroup::" echo "$cfg: exit $status in $((SECONDS - start))s" # TLC exits 11 to 14 for a deadlock, a violated invariant, a violated - # property, and a failed assertion; anything else nonzero is an error. + # property, and a failed assertion, and Apalache 12 for a violated + # invariant; anything else nonzero is an error. if $finding; then case $status in 11 | 12 | 13 | 14) ;;