diff --git a/.claude/skills/verify-route/SKILL.md b/.claude/skills/verify-route/SKILL.md index d36ed2ca136..a6b45fb4fb9 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 quest gate just rs tla moq-net/verify/route/RouteHandoff.tla quest gate just rs tla moq-net/verify/route/RouteHandoff.tla -config rs/moq-net/verify/route/Ring.cfg +quest gate just test tla rs/moq-net/verify/route/RouteClaims.cfg quest gate 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 @@ quest gate 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/flake.nix b/flake.nix index acef76ddb20..2602bf79d22 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/m0/ci/tlc-cost.md b/quest/m0/ci/tlc-cost.md index 0728361d3b7..7eb84dd949e 100644 --- a/quest/m0/ci/tlc-cost.md +++ b/quest/m0/ci/tlc-cost.md @@ -44,9 +44,6 @@ Decided 2026-11-12 (maintainer, /quest-plan): Java override in `CommunityModules-deps.jar`, which nixpkgs does not package: take it from a pinned release, put it on TLC's classpath in both recipes, and confirm TLC's startup log reports the override loaded. - [moq-dev/moq#8564](https://github.com/moq-dev/moq/pull/8564) rewrites - `SumOver` as an Apalache fold; whichever lands second keeps one fold for the - model. - ✅ Add `SYMMETRY` where sound. No config checks a `PROPERTY`, so every one checks safety only, which symmetry preserves. A permutation is sound only if it fixes every constant the config gives, such as `Links`, `Origin`, or @@ -68,13 +65,15 @@ Decided 2026-11-12 (maintainer, /quest-plan): the `js/*/verify/` READMEs name single configs, and only Nightly runs `just test tla` over a directory. - Rejected: Apalache, which is no cheaper here and ran out of memory on the - route model ([moq-dev/moq#8564](https://github.com/moq-dev/moq/pull/8564)); + route model ([moq-dev/moq#8564](https://github.com/moq-dev/moq/pull/8564), + which now runs it only on the small claims model, `RouteClaims.tla`); waiting for the Rust checker, which the m1 quest spikes and this complements. -Not decided: the route-inductive work in progress adds a refinement check, -`RefinesClaims`, to the simulated `Blind.cfg`, where every sampled trace -re-checks it. Recommended: check a refinement on the smallest exhaustive config +Not decided: [moq-dev/moq#8564](https://github.com/moq-dev/moq/pull/8564) +checks a refinement, `RefinesClaims`, on every route config but `Loop.cfg`, +simulated ones included, which costs each about two thirds more time. +Recommended: check a refinement on the smallest exhaustive config that exercises it, where each distinct state is checked once, unless measuring shows the simulated config is cheaper. @@ -90,4 +89,4 @@ Public API: none. Wire: none. ## Related - [A Rust TLA+ checker runs the models locally if it agrees with TLC](/quest/m1/tla-native-checker.md) - a faster engine for the same specs; its TLC baseline moves with this -- [The route rules hold from any state, not only the runs TLC reaches](/quest/m1/route-inductive.md) - rewrites `SumOver` and adds the refinement check named above +- [The route model's loop rules hold for runs of any length](/quest/m1/route-loops.md) - adds a second refinement check like the one named above diff --git a/quest/m1/route-inductive.md b/quest/m1/route-inductive.md deleted file mode 100644 index 51b89f9880e..00000000000 --- a/quest/m1/route-inductive.md +++ /dev/null @@ -1,69 +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-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. - -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-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 diff --git a/quest/m1/route-trace-validation.md b/quest/m1/route-trace-validation.md index f8e2e6bf906..b4a1ea0db4a 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-routes/README.md b/quest/m2/cluster-routes/README.md index a11619e7c91..50dd9624889 100644 --- a/quest/m2/cluster-routes/README.md +++ b/quest/m2/cluster-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. The model covers both, but its no-stale-route property holds only for one failure and a patient timer; `StaleIsChased` bounds the rest. 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-routes/scope.md) runs the path rule with a route per scope, sans-IO, beside today's router. [The switch](/quest/m2/cluster-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-routes/interest-set.md) then edits the path router only, and [the route stream](/quest/m2/cluster-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-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-routes/scope.md) runs the path rule with a route per scope, sans-IO, beside today's router. [The switch](/quest/m2/cluster-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-routes/interest-set.md) then edits the path router only, and [the route stream](/quest/m2/cluster-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-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/quest/m2/cluster-routes/route-exhaustive-sim.md b/quest/m2/cluster-routes/route-exhaustive-sim.md index c57e9700a79..9d1f67da117 100644 --- a/quest/m2/cluster-routes/route-exhaustive-sim.md +++ b/quest/m2/cluster-routes/route-exhaustive-sim.md @@ -44,7 +44,7 @@ out. Nightly. This sits beside [trace validation](/quest/m1/route-trace-validation.md), which -keeps the TLA+ model honest for [the inductive invariant](/quest/m1/route-inductive.md) +keeps the TLA+ model honest for its proofs ([the loop rules](/quest/m1/route-loops.md)) and the design work done on the spec before code exists. It replaces neither that nor the seeded sweeps on larger meshes (`tests/integration/mesh_sweep.rs`). If the spike shows the diff --git a/rs/justfile b/rs/justfile index 94e93fd6b6c..58652549668 100644 --- a/rs/justfile +++ b/rs/justfile @@ -23,8 +23,38 @@ default: # `../.tla` for a spec outside `rs/`, such as a generated one in `.tmp/`. # TLC runs at the lowest priority with a 4 GB heap, which no model here outgrows: # the JVM otherwise takes a quarter of RAM per run. +[positional-arguments] tla spec *args: - JAVA_TOOL_OPTIONS=-Xmx4g nice -n 19 nix shell --inputs-from . nixpkgs#tlaplus18 --command tlc -workers auto -cleanup -noGenerateSpecTE -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="-Xmx4g -DTLA-Library=$lib" + exec nice -n 19 nix shell --inputs-from "$root" nixpkgs#tlaplus18 --command tlc -workers auto -cleanup -noGenerateSpecTE -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. Apalache's heap is 4 GB unless +# `JVM_ARGS` sets `-Xmx`. +[positional-arguments] +apalache command spec *args: + #!/usr/bin/env bash + set -euo pipefail + command=$1 + spec=rs/$2 + shift 2 + exec nice -n 19 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/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 new file mode 100644 index 00000000000..50ef84087c2 --- /dev/null +++ b/rs/moq-net/verify/route/RouteClaims.tla @@ -0,0 +1,316 @@ +---------------------------- 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. *) +(* *) +(* Every floor carries `full`, the publisher's claims at its revision, so *) +(* 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. 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 + +CONSTANTS + \* @type: Set(Int); + 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); + 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, 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 }; +\* @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; +\* @typeAlias: offered = <> -> $floor; +\* @typeAlias: route = <> -> Str; +\* @typeAlias: views = <> -> $view; +RouteClaims_aliases == TRUE + +\* 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, 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 +\* 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: 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; + 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), full |-> of[x].full] + 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), full |-> ow] : k \in Keys} + ELSE {[k |-> k, rev |-> IF vw[<>].floor = Absent THEN None ELSE vw[<>].floor, + items |-> vw[<>].items, full |-> vw[<>].full] : k \in Keys} + +----------------------------------------------------------------------------- +(* 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 = {[rev |-> 0, full |-> 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, in one transition so that +\* Apalache checks one step. +Publish == + \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 +\* 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 + /\ 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} + 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, 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; + 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 {Origin} \cup Relays}) + +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(view[x].full, x[2]) + /\ \A x \in HeardIdx : heard[x] # "off" /\ offered[x].rev >= 0 => + 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 + +\* 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. *) + +\* 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 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 + \/ [rev |-> r, full |-> full] \in hist /\ 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. + /\ rev >= 0 + /\ [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 : + /\ 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, 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. + /\ \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, 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 /\ 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 + /\ IndInv + +============================================================================= 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 9ec5db5494a..eae71c2f152 100644 --- a/rs/moq-net/verify/route/RouteHandoff.tla +++ b/rs/moq-net/verify/route/RouteHandoff.tla @@ -763,4 +763,38 @@ 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 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, full |-> Full(q[d][i].rev)] : + 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)]], + route <- [x \in Relays \X Keys |-> Routing(st[x[1]].rt[x[2]])], + 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 <- UNION {ClaimsOn(d) : d \in Dirs}, + MaxFlight <- 0 + +RefinesClaims == Claimed!Spec + ============================================================================= 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) ;;