Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@ Runs Lean verification for the repository, with each package checked in an isola
All five packages (consensus, common, consistency, disaster-recovery, and kv) run in one matrix.
Package checks use the `gha-vmss-d16av7-ci` pool and trace replays use `gha-vmss-d16av7-ci-b`, both in Ubuntu 26.04 containers.
Native trace captures remain on `gha-vmss-d16av7-ci-c` with Azure Linux containers, and the lightweight final gate uses GitHub-hosted Ubuntu.
Each matrix job caches its third-party dependency checkouts and build outputs, including Mathlib and (where used) leanfmt, using GitHub Actions caching.
Each matrix job caches its third-party dependency checkouts and build outputs, including (where used) leanfmt, using GitHub Actions caching.
Caches are isolated by package and runner architecture and invalidated by changes to the Ubuntu version, Lean toolchain, package and common dependency manifests/configuration, or reusable workflow.
CCF package and common build outputs are not cached, and all verification steps still run, including Mathlib's upstream cache retrieval.
CCF package and common build outputs are not cached, and all verification steps still run.
CCF consensus, KV, and consistency trace captures run in parallel with package checks.
Three independent trace-validation jobs each restore Mathlib caches, build their own replayer, download the corresponding capture artifacts, and replay the traces without depending on the package matrix.
Three independent trace-validation jobs each build their own replayer, download the corresponding capture artifacts, and replay the traces without depending on the package matrix.
Consistency capture reuses the existing `consistency_trace_validation` e2e test, and its replay job also checks the consistency replay fixtures, including election and rollback traces.
A final summary job requires every package and trace job to succeed.

The packages use only the Mathlib and Batteries declarations vendored in `lean/mathlib-subset`, rather than depending on Mathlib; the [Lean Mathlib Subset](#lean-mathlib-subset) workflow checks them against upstream.

The disaster recovery job builds the library and replayer with `lake build --wfail --fail-fast` and runs Lean's built-in linters with `lake lint` on Ubuntu 26.04 on relevant pull requests.
Canonical behavior checks run with `#eval` when their test module is built, and assertion failures fail the build.
The build includes both the human-reviewed model and system properties and the proof implementation files marked as generated for review purposes.
Expand All @@ -172,13 +174,22 @@ The `KV trace captures` job builds the `CCF_KV_TRACING` unit tests on Azure Linu
The KV package job checks `lean/kv/replayer/check-fixtures.sh` against the KV fixtures.
The dedicated replay job builds `kv-replay` separately to validate the captured traces; no replay executables are transferred between jobs.

After the build, `scripts/lean-format-checks.sh` checks every tracked `.lean` file with the pinned leanfmt dependency.
After the build, `scripts/lean-format-checks.sh` checks every tracked `.lean` file except the vendored Mathlib subset with the pinned leanfmt dependency.
The workflow runs on pull requests that change `lean/`, any `.lean` file, the formatter script, or the workflow.
It also runs on changes to the C++ sources and trace runners checked against the CCF consensus and KV models: `src/consensus/aft/`, the CCF consensus scenario tests, `src/kv/`, the public KV and transaction headers, and the KV trace runner.
See the [local formatting commands](../../lean/disaster-recovery/README.md#formatting) to apply fixes.

File: `lean.yml`
3rd party dependencies: Mathlib and leanfmt (pinned in the Lake package), and elan.
3rd party dependencies: leanfmt (pinned in the Lake packages), Mathlib (vendored subset), and elan.

# Lean Mathlib Subset

Checks the declarations vendored in [`lean/mathlib-subset`](../../lean/mathlib-subset/README.md) against upstream Mathlib, using `lake exe mathlib-subset-check`.
Fetching upstream Mathlib is slow, so it is triggered only on pull requests that change the subset, its checker, the Lean toolchain, or this workflow.
It can also be run manually.

File: `lean-mathlib-subset.yml`
3rd party dependencies: Mathlib (pinned in the subset checker) and elan.

# Vendored Dependency Verification

Expand Down
65 changes: 65 additions & 0 deletions .github/workflows/lean-mathlib-subset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: "Lean Mathlib Subset"

on:
pull_request:
paths:
- "lean/lean-toolchain"
- "lean/mathlib-subset/**"
- "lean/mathlib-subset-check/**"
- ".github/workflows/lean-mathlib-subset.yml"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: read-all

jobs:
check:
name: Check vendored Mathlib subset
runs-on: [gha-vmss-d16av7-ci-b]
container:
image: ubuntu:26.04
options: --user root
timeout-minutes: 60
permissions:
contents: read
defaults:
run:
shell: bash

steps:
- name: Install container prerequisites
run: |
set -euo pipefail
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates git curl tar zstd build-essential libgmp-dev elan
echo "ELAN_HOME=$RUNNER_TEMP/elan" >> "$GITHUB_ENV"

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install Lean
run: |
set -euo pipefail
git config --global --add safe.directory "$GITHUB_WORKSPACE"
elan run --install "$(cat lean/lean-toolchain)" lean --version

- name: Build Mathlib subset
working-directory: lean/mathlib-subset
run: |
set -euo pipefail
lake build --wfail

- name: Fetch upstream Mathlib
working-directory: lean/mathlib-subset-check
run: |
set -euo pipefail
lake exe cache get

- name: Check subset against upstream Mathlib
working-directory: lean/mathlib-subset-check
run: |
set -euo pipefail
lake exe mathlib-subset-check ../mathlib-subset
6 changes: 0 additions & 6 deletions .github/workflows/lean-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ jobs:
path: lean/${{ inputs.package }}/.lake/packages
key: lean-deps-v2-vmss-ubuntu-26.04-${{ runner.arch }}-${{ inputs.package }}-${{ hashFiles('lean/lean-toolchain', format('lean/{0}/lake-manifest.json', inputs.package), format('lean/{0}/lakefile.toml', inputs.package), 'lean/common/lake-manifest.json', 'lean/common/lakefile.toml', '.github/workflows/lean-package.yml') }}

- name: Restore Mathlib cache
working-directory: lean/${{ inputs.package }}
run: |
set -euo pipefail
lake exe cache get

- name: Build, kernel and axiom check
working-directory: lean/${{ inputs.package }}
run: |
Expand Down
28 changes: 9 additions & 19 deletions .github/workflows/lean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,6 @@ jobs:
git config --global --add safe.directory "$GITHUB_WORKSPACE"
elan run --install "$(cat lean/lean-toolchain)" lean --version

- name: Restore Mathlib cache
working-directory: lean/consensus
run: |
set -euo pipefail
lake exe cache get

- name: Build CCF consensus replay
working-directory: lean/consensus
run: |
Expand Down Expand Up @@ -322,7 +316,15 @@ jobs:
python3 - <<'PY'
import pathlib

expected = {"consensus", "common", "consistency", "disaster-recovery", "kv"}
expected = {
"consensus",
"common",
"consistency",
"disaster-recovery",
"kv",
"mathlib-subset",
"mathlib-subset-check",
}
actual = {config.parent.name for config in pathlib.Path("lean").glob("*/lakefile.toml")}
if actual != expected:
raise SystemExit(
Expand Down Expand Up @@ -362,12 +364,6 @@ jobs:
git config --global --add safe.directory "$GITHUB_WORKSPACE"
elan run --install "$(cat lean/lean-toolchain)" lean --version

- name: Restore Mathlib cache
working-directory: lean/kv
run: |
set -euo pipefail
lake exe cache get

- name: Build KV replay
working-directory: lean/kv
run: |
Expand Down Expand Up @@ -421,12 +417,6 @@ jobs:
git config --global --add safe.directory "$GITHUB_WORKSPACE"
elan run --install "$(cat lean/lean-toolchain)" lean --version

- name: Restore Mathlib cache
working-directory: lean/consistency
run: |
set -euo pipefail
lake exe cache get

- name: Build consistency replay
working-directory: lean/consistency
run: |
Expand Down
1 change: 0 additions & 1 deletion doc/build_apps/kv/semantics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ Lean is pinned by ``lean/kv/lean-toolchain`` and is independent of normal CCF bu
.. code-block:: bash

cd lean/kv
lake exe cache get
lake build --wfail
cd ../..
cmake -S . -B build-kv-trace -GNinja \
Expand Down
4 changes: 2 additions & 2 deletions lean/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ The `ccf_common` Lake package exposes protocol-independent definitions in the `C

## Dependency imports

Specification proofs import the Mathlib tactics they need rather than the `Mathlib.Tactic` umbrella.
Specification proofs import the individual Mathlib modules they need from the vendored [Mathlib subset](../mathlib-subset/README.md), which keeps only the Mathlib and Batteries declarations that CCF uses.
Their CCF declarations, theorem statements, exposed definitions, and required tactic support remain available, but importing a proof module or an assembled specification root does not promise to reexport unrelated Mathlib tactics or theory.
`CCF.Execution` publicly imports `Mathlib.Data.Seq.Defs` and keeps `Mathlib.Data.Seq.Basic` private for its internal proofs.
Consumers that need other Mathlib facilities should import their defining modules explicitly.
Consumers that need other Mathlib facilities should import their defining modules explicitly, after adding them to the subset if necessary.
The documented property entrypoints remain the public proof APIs; see the [CCF consensus protocol](../consensus/README.md#proofs), [consistency](../consistency/README.md#properties), and [disaster recovery](../disaster-recovery/README.md#properties) packages.

Selective imports do not reduce the checked CCF roots or omit tests.
Expand Down
106 changes: 4 additions & 102 deletions lean/common/lake-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,111 +3,13 @@
"packagesDir": ".lake/packages",
"packages": [
{
"url": "https://github.com/leanprover-community/mathlib4.git",
"type": "git",
"subDir": null,
"type": "path",
"scope": "",
"rev": "56a005855ea17e0b0958f73ec801ae140b0a1679",
"name": "mathlib",
"name": "mathlib_subset",
"manifestFile": "lake-manifest.json",
"inputRev": "v4.35.0",
"inherited": false,
"configFile": "lakefile.lean"
},
{
"url": "https://github.com/leanprover-community/plausible",
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "dfa4f38190d07c37e315953e08b90fe2d95b3c24",
"name": "plausible",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
"inherited": true,
"configFile": "lakefile.toml"
},
{
"url": "https://github.com/leanprover-community/LeanSearchClient",
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "d6b4c7be5be75ec4917c873ac50c756dc1436372",
"name": "LeanSearchClient",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
"inherited": true,
"configFile": "lakefile.toml"
},
{
"url": "https://github.com/leanprover-community/import-graph",
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "a41f0e9a4dea23188ea9cc1c41ac9f8bbafe0b93",
"name": "importGraph",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
"inherited": true,
"configFile": "lakefile.toml"
},
{
"url": "https://github.com/leanprover-community/ProofWidgets4",
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "df72b022e558978a1c50264cfc4d7fec86fa8e04",
"name": "proofwidgets",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
"inherited": true,
"configFile": "lakefile.lean"
},
{
"url": "https://github.com/leanprover-community/aesop",
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "4a174c490d8707121c4a9290800489f105d85e07",
"name": "aesop",
"manifestFile": "lake-manifest.json",
"inputRev": "master",
"inherited": true,
"configFile": "lakefile.toml"
},
{
"url": "https://github.com/leanprover-community/quote4",
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "dce0ad79c486cb1fb504af04f953c3466b0c6db8",
"name": "Qq",
"manifestFile": "lake-manifest.json",
"inputRev": "master",
"inherited": true,
"configFile": "lakefile.toml"
},
{
"url": "https://github.com/leanprover-community/batteries",
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "66e469188fe07963e5cf666c7d4433f45b8131c5",
"name": "batteries",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
"inherited": true,
"configFile": "lakefile.toml"
},
{
"url": "https://github.com/leanprover/lean4-cli",
"type": "git",
"subDir": null,
"scope": "leanprover",
"rev": "c24fe6078c630e89b489bffe59b3e20ac30d12c8",
"name": "Cli",
"manifestFile": "lake-manifest.json",
"inputRev": "v4.35.0",
"inherited": true,
"dir": "../mathlib-subset",
"copy": false,
"configFile": "lakefile.toml"
}
],
Expand Down
6 changes: 3 additions & 3 deletions lean/common/lakefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ supportInterpreter = true
weakLinkArgs = ["-lLake"]

[[require]]
name = "mathlib"
git = "https://github.com/leanprover-community/mathlib4.git"
rev = "v4.35.0"
name = "mathlib_subset"
path = "../mathlib-subset"
copy = false
9 changes: 6 additions & 3 deletions lean/consensus/Consensus/Model/Node.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ public import Consensus.Model.Messages
public import Consensus.Model.NodeState
public import CCF.Capabilities
public import Mathlib.Data.Finset.Sort
public import Mathlib.Order.Prod.Lex.Basic

@[expose] public section

Expand Down Expand Up @@ -59,18 +58,22 @@ Approximates `all_other_nodes`; unlike CCF, peers lost on rollback are not retai
def eligiblePeers (state : NodeState) (self : NodeID) : Finset NodeID :=
(state.activeMembers ∪ state.retirementCompletedNodes).erase self

/-- Lexicographic order on successor ranks. -/
def rankBelow (a b : Nat × Nat × Nat) : Bool :=
decide (a.1 < b.1 \/ (a.1 = b.1 /\ Prod.lexLt a.2 b.2))

/-- Maximize replication progress, latest active membership, then node ID. -/
def findSuccessor (state : NodeState) (self : NodeID) : Option NodeID :=
let configurations := state.activeConfigurations
let rank node :=
toLex (state.matchIndex node, toLex (latestMembershipIndex configurations node, node))
(state.matchIndex node, latestMembershipIndex configurations node, node)
let peers := (eligiblePeers state self).sort
peers.foldl
(fun best candidate =>
match best with
| none => some candidate
| some selected =>
if rank selected < rank candidate then
if rankBelow (rank selected) (rank candidate) then
some candidate
else
best)
Expand Down
Loading