Repository navigation
Use a low-level model for trace validation and prove refine Consensus/Model.lean - #8787
Closed
cjen1-msft wants to merge 25 commits into
Closed
cjen1-msft wants to merge 25 commits into
cjen1-msft wants to merge 25 commits into
Conversation
A batch from a leader alone in its configuration which held a signature followed by a configuration adding a node left the signature uncommitted until the new node acknowledged: replicate() decided whether to commit after the batch's hooks had added the node. Decide before them, as the Lean model commits the signature within the batch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move Aft's nested Votes struct to aft::Votes in cft_types.h so the trace
serialisation can name it, and add msgpack encoders for votes_for_me
(array ordered by configuration index of {idx, quorum, sorted votes}) and
for optional node IDs (nil when absent).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ccf.cft events now carry voted_for, votes_for_me, leader_id, is_new_follower and ticking as top-level fields next to state, each only on the trace points whose lock hold reads or writes it, with its value when the trace point executes. Plain tick records gain only ticking, which the election-timeout check reads. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Trace validation needs a protocol-independent statement of what an accepted trace means, and a framework that turns per-hold simulation into that statement. CCF.Observation states refinement of a specification at observed trace events; CCF.Sections models event-granular nodes whose lock holds are checked at release, and CCF.Proofs.Sections/SectionsObservation prove that accepted section runs refine the clean network at those events. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This is the part of trace validation a reviewer reads: the declared state (one field per cft.h member, with the ledger the node holds after its snapshot base), the decoded trace points, the actions they map to, what each trace point is compared with, and the state refinement mapping `abs` / `related` from a clean node state to a declared state. Everything later in the series is checked against these definitions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
To validate a trace, each trace point must be explained by the code between it and the previous one. M_tv mirrors the cft.h handlers statement by statement over a full-ledger internal state (the declared suffix plus a ghost prefix for snapshot joiners), runs them as event-granular lock-hold sections, and checks at every release the local invariant the proofs use, that a snapshot base is a committed signature, and that the hold does not depend on ledger entries below the base. Rejections of behaviour cft.h can exhibit but the clean model cannot express are labelled as known implementation and specification differences. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The old replayer checked driver observations against direct clean-model transitions and could not follow real nodes or cft.h's own control flow. The validator splits a trace into per-node streams, runs them through M_tv with lock-hold sections, and compares every trace point with the declared state; `--refine` additionally runs every release in lock step against the clean model. The old Replay modules, their test and fixtures are replaced by fixtures captured from the native driver, and CI validates them and the scenario captures with `--refine`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The proof that accepted traces refine the clean model reduces to one obligation per cft.h handler. This adds the reduction: Hoare-style rules for M_tv's handler monad, the obligation statement (`HoldSound` over the proof relation `Rel`), the section-level simulation that discharges the framework side from the obligations, independence of the ghost ledger prefix below a snapshot base, and the validator's scheduling facts. It also adds the lemma libraries several handler proofs share (AppendEntries frames, lifecycle notes, vote counting, and `update_commit`). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
`init_as_backup`, `force_become_primary`, the out-of-lock snapshot hook and dropping pending messages each refine zero or one clean step. For a snapshot joiner, the ghost prefix taken from a donor's committed log satisfies the clean network's guard on `initAsBackup`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A follower's `recv_append_entries` (term check, previous-index check, conflict scan and rollback, append, commit and response) refines the clean `receiveAppendEntries` step, keeping the invariant and the relation, with every sent message satisfying the message invariant. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
RequestVote, RequestPreVote, their responses and ProposeRequestVote refine the clean vote steps, including becoming leader when a quorum is reached in every active configuration. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A leader's handling of an AppendEntries response (match and sent index updates, commit, retirement and successor nomination) and the nomination trace point refine the clean steps. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
`periodic` refines the clean timeout steps: heartbeats, CheckQuorum step-down, and election and pre-vote timeouts, with the timers that no trace point records read from the node's next event. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A leader's `replicate` of a batch (entry admission, configuration and retirement hooks, peer creation, flushing AppendEntries and committing) refines the clean append and send steps. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
TraceValidation.lean states the one reviewed theorem, `accepted_refines`: an accepted trace is a behaviour of `Consensus.Model.transitionSystem` under the reviewed state mapping `related`, at every lock-taking event. Its proof assembles the fourteen handler obligations and the section framework, and uses only the standard axioms. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ation The consensus README, the replay README and the architecture docs now describe the M_tv validator and what acceptance means. The replay README lists the behaviours of cft.h that validation rejects because the clean model cannot express them, with a reachable scenario for each, and what validation tolerates, so a rejected real capture can be triaged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ines `streamsMatch` compared only trace line numbers, so `accepted_refines` did not say that the observed events are the input: observations with the right lines but other events, or for nodes without a stream, satisfied it. It now says that every observation is of a stream's node and that each node's observed events are its stream's events, in order. The validator takes each scheduled action's event from the streams (`restream`) before certifying, so this holds by construction; the proof does not need a lawful equality on JSON. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Only the label and the `aft::Aft` variables were required to be present, so an event could omit a field that is a projection of the declared state, such as `replicate_entry.seqno` or a peer's `match_idx`, or even `state`, and still be accepted. `Observe.traceFields` now lists the fields of each trace point as `cft_trace_msgpack.h` declares them, with `recv_request_vote` split by message type; an event must carry exactly those. The `aft::Aft` variable projections no longer need their own per-point table. Add invalid fixtures for a missing `seqno` and a missing `match_idx`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A node joining from a snapshot taken after an election receives a term history spanning several views. fillSnapshot rejected such snapshots, assuming every entry up to the base was in the snapshot's view, so real services were rejected. Take the joiner's view history up to the base from the donor, which equals the snapshot's because both assign each committed index its entry's term, and check only that the base is a signature in the snapshot's view. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The files directly in TraceValidation/ should be exactly the reviewed surface. Move the model of cft.h (handler monad, handlers, machine, invariant, full-ledger state) to TraceValidation/MTv/ and the executable validator and lock-step check to TraceValidation/Validator/. Only module paths change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…duler The decoder and the split into per-node streams are trusted, not proved, so they belong to the reviewed surface; the scheduler is covered by the theorem and does not. Move Env and environment from the validator and Abs into a reviewed Input module with one load function the CLI uses, and state the refinement over the streams' nodes instead of the verdict's keys (equal by validate_sound), so that the theorem reads only validate and its observations from unreviewed code. Each reviewed header now says what a reviewer checks it against. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The files directly in TraceValidation/ are the reviewed surface, so a reviewer must be able to read them without M_tv, the validator or the proofs. Add that as an architecture rule checked by check-imports: they may import model modules, lean/common definitions other than CCF.Proofs, the TraceValidation entrypoint and each other. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
State in the layout policy, the consensus README and the replay README that the reviewed surface is TraceValidation.lean and the files directly in TraceValidation/, and that MTv/, Validator/ and Proofs/ are not reviewed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
Changes needed to fully align the model and the implementation Behaviours validation rejects today
Trace and tolerance gaps
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Trace validation now checks each
ccf.cfttrace event against M_tv, a Lean model ofcft.hwith one step per trace point, and proves that every accepted trace is explained by one execution of the existing consensus model: at each lock-taking event, the node's traced state is related to its state in that execution.The previous replayer grouped events with a grammar and ran the consensus model once per lock hold, comparing one state snapshot per group (about 40% of the snapshots in a trace) and ignoring several event fields. It could not follow real multi-process nodes without extra ordering rules. The new validator reads one stream per node, never relies on cross-node order, and requires every field of every event to be either compared with the model or consumed as that step's input.
What to review
The reviewed surface is about 800 lines; the proofs and M_tv are machine-checked against it and not meant for line-by-line review. Decoding a trace file and splitting it into per-node streams is trusted.
TraceValidation.lean: the one theorem,accepted_refines. If the validator accepts, the observed events are exactly the input events, each is consistent with the declared state, and there is one execution ofConsensus.Model.transitionSystemin which, at every lock-taking event in order, the node's model state is related to its declared state. Events inside a lock hold are checked against M_tv only; the model has no states there.CCF/Observation.lean: the generic refinement statement.State.leanandAbs.lean: the declaredcft.hstate and its mapping to the model state.Event.lean,Action.lean,Observe.lean: decoding, and what each trace point is compared with.Consensus/Model*,Properties*andProofs/*are unchanged; properties are still stated of the model only.Things to draw attention to
related), not equality with a projection (abs). A node holds only the ledger after its snapshot base, so the model log is related to it after droppingbaseentries, with a signature at the base. Send and match indexes are related only for a leader's peers, and vote sets only in the role that collects them. A node with no ledger entry yet is related to any model state that has committed nothing.cft.hand the model (for examplecft.hkeeps a peer across a rollback). The ninth is a liveness gap in the implementation: a primary that joined from a snapshot sends entries below its snapshot to a lagging follower, the host cannot read them and drops the message, so that follower cannot catch up from that primary.replicate()decides whether the leader is alone before running the batch's hooks, so a signature batched before a configuration adding the first peer commits, as the model does. Trace events additionally carryvoted_for,votes_for_me,leader_id,is_new_followerandtickingon the trace points that use them (about +4.5% on a tick-dominated trace).consensus-replay;--refineadditionally runs the model in lock step at every lock release.lake checkruns in CI only and has not been run locally.Evidence
#print axioms Consensus.TraceValidation.accepted_refines:propext,Classical.choice,Quot.sound. Nosorry.lake build --wfail,check-imports,lake lint, Lean format, ASCII, copyright, prettier, C++ and Python format checks pass.cft_test56/56,tracing_test6/6, all 60 consensus scenarios pass.--refine: 60 driver traces, 8 captures from real multi-process nodes (joins, elections, snapshot joins including one spanning two terms, backup and primary retirement, nomination, restart from own ledger) and 3 valid fixtures accepted; 12 invalid fixtures rejected.Size
About 28,700 lines added and 1,400 removed. Proofs are about 22,000 lines, M_tv about 2,200, the validator about 700, the generic framework in
lean/commonabout 1,400.