Skip to content

Check applied entries and snapshots against the consensus trace - #8925

Draft
cjen1-msft wants to merge 2 commits into
mainfrom
cjen1-msft-fictional-broccoli
Draft

cjen1-msft wants to merge 2 commits into
mainfrom
cjen1-msft-fictional-broccoli

Conversation

@cjen1-msft

@cjen1-msft cjen1-msft commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Two ccf.cft trace events record more of what a node did, and the consensus trace replayer uses them to constrain what a node receives and how it starts.

  • execute_append_entries_sync gains the view (vw), seqno (sn) and signature flag (gc) of its entry. Replay requires the delivered AppendEntries to carry the entries its receiver traced applying, with the configuration and retirements of their ledger hooks, and the model to apply exactly those.
  • init_as_backup gains the snapshot's term history (th, the first seqno of each view). Replay requires the committed prefix a joiner starts from to agree with it, and with the snapshot's hooks.

Before, a packet's entries were delivered unchecked, as a packet header omits them, and a joiner copied any committed prefix with a signature at the snapshot's seqno and view.

The model driver (tests/cft_model/ModelDriver.lean) emits the same fields, as its trace must be that of the implementation. This is the bottom of a stack: per-node validation (#8916) builds on it.

For reviewers

  • Trace compatibility: the replayer now requires the new fields, so it rejects a trace from an older build (missing key 'th').
  • Moved event: execute_append_entries_sync moves below apply, because the signature flag is only known once the entry has applied. It is still traced before state->last_idx = i and the hooks. An entry which fails to apply no longer traces it.
  • Request IDs: a transaction is named by its seqno minus one, replacing the trace-wide counter, so that a receiver's entries equal the sender's.
  • What a snapshot shows: a real snapshot traces one add_configuration at its seqno with the nodes in force, and the retirements still in the nodes table. So the check is on the latest configuration of the prefix, and that the traced retirements are among those of the prefix, not on each entry's metadata. Terms are compared entry by entry.
  • Ambiguous delivery: envelopes with equal headers and different entries are now told apart by the applied entries; delivery is still ambiguous if the receiver applied none of the differing ones.
  • Reducer order: a follower's hooks must now directly follow the execute_append_entries_sync of their entry, as a leader's follow replicate_entry.

Testing

  • All 69 scenario captures and all 69 model-driver traces replay strictly with watermark 1, and the two sets are identical.
  • 29 e2e captures (e2e_logging, governance_test, code_update_test, reconfiguration_test_suite) are accepted by tests/cft_trace_validation.py, each with watermark 1. They include 21 joins from real snapshots, in views 2 and 3.
  • Five new invalid fixtures differ from valid/replication.ndjson only in fields the replayer did not read before: a follower applying another signature flag or configuration than was sent, and a joiner whose term history or hook configuration disagrees with its donor, or whose term history starts a view after the snapshot.
  • ReplayDelivery.lean covers selection by applied entry, an entry which was not sent, and an entry the model applies which the node did not trace.
  • Not covered by a real capture: no e2e snapshot had a retired_committed_tx hook, so the retirement check ran only with none traced.
Commands
cmake -S . -B build -GNinja -DVERBOSE_LOGGING=ON -DCFT_MODEL_DRIVER=ON && ninja -C build
ctest --test-dir build -R '^(cft_scenario_test|cft_model_test)$' --no-tests=error
(cd lean/consensus && lake build --wfail Consensus consensus-replay && lake exe check-imports && lake lint)
for t in build/consensus/raw/*.msgpack; do consensus-replay "$t"; done            # 69 ok
for t in build/consensus/model/*.ndjson; do scripts/pack-trace.py < "$t" > t.msgpack && consensus-replay t.msgpack; done   # 69 ok
(cd build && ./tests.sh -R '^(reconfiguration_test_suite|governance_test|code_update_test|e2e_logging)$')
tests/cft_trace_validation.py lean/consensus/.lake/build/bin/consensus-replay build/workspace   # 29 accepted, 0 rejected

Fixtures: 5 valid accepted, 20 invalid rejected with exit 1, each for its documented reason.

…s trace

execute_append_entries_sync records the view, seqno and signature flag of
its entry, and so is traced once the entry has applied. init_as_backup
records the snapshot's term history. The model driver emits the same.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replay requires a delivered AppendEntries to carry the entries its
receiver traced applying, and the model to apply exactly those. A joiner
initializes from a committed prefix which agrees with its snapshot's
term history and hooks. Transactions are named by seqno, so that every
node names an entry alike.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@cjen1-msft cjen1-msft changed the title Trace the applied entry and the snapshot term history in the consensus trace Check applied entries and snapshots against the consensus trace Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant