Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ So is recovery from the ledger and snapshots of 7.x, in the `long` runs of the s
The Virtual A, B, and C jobs target `gha-vmss-d16av7-ci`, `gha-vmss-d16av7-ci-b`, and `gha-vmss-d16av7-ci-c`, respectively, to distribute demand across the regional pools.

End to end tests record each network's trace events, of every tag, and upload the capture with their logs.
The Virtual B and C jobs also run with `CCF_CONSISTENCY_TRACE=1`, record consistency traces for each traced network, and upload them with their logs.
The SNP Genoa job also runs with `CCF_RECOVERY_TRACE=1`, records a recovery trace manifest for each recovery decision protocol scenario, and uploads the manifests with its node logs.
The `Replay e2e traces` job runs after the Virtual and SNP Genoa jobs complete (unless the workflow is cancelled), builds or restores the cached Lean replayers, and invokes `tests/trace_replay.py` to validate both sets of logs.
It replays the `ccf.cft` events of every capture from the Virtual logs against the consensus model with `tests/cft_trace_validation.py`.
A capture may be incomplete, for example if a test killed a node, so consensus replay runs with `--lenient` and fails if the model disagrees with a capture, if replay consumes less than 90% of the events of one of a capture's nodes, or if there is no capture.
It replays the consistency traces from the Virtual logs against the consistency model with `tests/consistency_trace_replay.py`, failing if replay rejects a trace or if no trace is found.
It replays the recovery decision protocol node logs referenced by each manifest in the SNP Genoa logs against the disaster recovery model with `tests/recovery_trace_validation.py`, failing if any manifest is invalid, if replay rejects a scenario, or if no manifest is found.

File: `ci.yml`
Expand Down
33 changes: 23 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ jobs:
rm -rf /github/home/.cache
mkdir -p /github/home/.cache

export CCF_CONSISTENCY_TRACE=1
./tests.sh --timeout 360 --output-on-failure -L bucket_b
shell: bash

Expand All @@ -182,6 +183,7 @@ jobs:
build/workspace/*/*.ledger.*/*
build/workspace/*/stack_trace
build/workspace/*_trace/*.msgpack
build/workspace/*_consistency_trace/*.ndjson
build/workspace/**/openapi_coverage.json
if-no-files-found: ignore
if: success() || failure()
Expand Down Expand Up @@ -215,13 +217,6 @@ jobs:
- name: "Install Lean"
uses: ./.github/actions/install-lean

- name: "Build Lean consistency trace replayer"
run: |
set -euo pipefail
cd lean/consistency
lake build consistency-replay
shell: bash

- name: "Build Debug"
run: |
set -ex
Expand All @@ -240,15 +235,15 @@ jobs:
rm -rf /github/home/.cache
mkdir -p /github/home/.cache

export CCF_LEAN_CONSISTENCY_REPLAYER="$GITHUB_WORKSPACE/lean/consistency/.lake/build/bin/consistency-replay"
export CCF_CONSISTENCY_TRACE=1
./tests.sh --timeout 360 --output-on-failure -L bucket_c
shell: bash

- name: "Run partitions tests"
run: |
set -ex
cd build
export CCF_LEAN_CONSISTENCY_REPLAYER="$GITHUB_WORKSPACE/lean/consistency/.lake/build/bin/consistency-replay"
export CCF_CONSISTENCY_TRACE=1
./tests.sh --timeout 360 --output-on-failure -L partitions -C partitions
shell: bash

Expand All @@ -264,8 +259,8 @@ jobs:
build/workspace/*/*.ledger.*/*
build/workspace/*/stack_trace
build/workspace/*_trace/*.msgpack
build/workspace/*_consistency_trace/*.ndjson
build/workspace/**/openapi_coverage.json
build/workspace/*_consistency_trace.ndjson
if-no-files-found: ignore
if: success() || failure()

Expand Down Expand Up @@ -378,6 +373,16 @@ jobs:
hashFiles('lean/lean-toolchain', 'lean/common/**', 'lean/consensus/**')
}}

- name: Cache consistency replay
id: consistency_replay_cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: lean/consistency/.lake/build/bin/consistency-replay
key: >-
consistency-replay-${{ runner.os }}-${{ runner.arch }}-${{
hashFiles('lean/lean-toolchain', 'lean/common/**', 'lean/consistency/**')
}}

- name: Cache disaster recovery replay
id: recovery_replay_cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
Expand All @@ -391,6 +396,7 @@ jobs:
- name: Install Lean
if: >-
steps.consensus_replay_cache.outputs.cache-hit != 'true' ||
steps.consistency_replay_cache.outputs.cache-hit != 'true' ||
steps.recovery_replay_cache.outputs.cache-hit != 'true'
uses: ./.github/actions/install-lean

Expand All @@ -401,6 +407,13 @@ jobs:
set -euo pipefail
lake build --wfail consensus-replay

- name: Build consistency replay
if: steps.consistency_replay_cache.outputs.cache-hit != 'true'
working-directory: lean/consistency
run: |
set -euo pipefail
lake build --wfail consistency-replay

- name: Build disaster recovery replay
if: steps.recovery_replay_cache.outputs.cache-hit != 'true'
working-directory: lean/disaster-recovery
Expand Down
48 changes: 28 additions & 20 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,27 +203,35 @@ jobs:
--no-summary \
--json "${out_dir}/consensus.json.gz"

# 2. consistency: consistency_trace_validation + e2e_logging +
# recorder-backed partitions groups (excluding untraced
# ledger/restart groups).
# 2. consistency: consistency_trace_validation + traced virtual e2e
Comment thread
achamayou marked this conversation as resolved.
Resolved
# tests + recorder-backed partitions groups (only nodes started inside
# consistency_trace.recording(), excluding untraced recovery,
# lifecycle, and ledger/restart processes).
shopt -s nullglob
consistency_profraws=(consistency_trace_validation-*.profraw)
logging_profraws=(e2e_logging-*.profraw)
partition_profraws=(partitions_consistency_tests-*.profraw)
if [[ ${#consistency_profraws[@]} -eq 0 ]]; then
echo "::error::No consistency_trace_validation-*.profraw files found"
exit 1
fi
if [[ ${#logging_profraws[@]} -eq 0 ]]; then
echo "::error::No e2e_logging-*.profraw files found"
exit 1
fi
if [[ ${#partition_profraws[@]} -eq 0 ]]; then
echo "::error::No partitions_consistency_tests-*.profraw files found"
exit 1
fi
echo "consistency: selected ${#consistency_profraws[@]} consistency_trace_validation, ${#logging_profraws[@]} e2e_logging and ${#partition_profraws[@]} partitions_consistency_tests .profraw file(s)"
printf '%s\n' "${consistency_profraws[@]}" "${logging_profraws[@]}" "${partition_profraws[@]}" |
consistency_test_prefixes=(
consistency_trace_validation
e2e_forwarding_smoke
e2e_limits
e2e_logging
governance_test
js_batched_stress_test
partitions_consistency_tests
schema_test
tls_stress_test
)
all_consistency_profraws=()
summary_parts=()
for prefix in "${consistency_test_prefixes[@]}"; do
matched=("consistency-${prefix}"-*.profraw)
if [[ ${#matched[@]} -eq 0 ]]; then
echo "::error::No consistency-${prefix}-*.profraw files found"
exit 1
fi
all_consistency_profraws+=("${matched[@]}")
summary_parts+=("${#matched[@]} ${prefix}")
done
echo "consistency: selected $(IFS=', '; echo "${summary_parts[*]}") .profraw file(s)"
printf '%s\n' "${all_consistency_profraws[@]}" |
../scripts/coverage.sh \
--profiles-file - \
-o "${tmp_dir}/consistency.profdata" \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ jobs:
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: consistency-traces
path: build/workspace/*_consistency_trace.ndjson
path: build/workspace/*_consistency_trace/*.ndjson
if-no-files-found: error
retention-days: 1
overwrite: true
Expand Down
4 changes: 2 additions & 2 deletions doc/architecture/verification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Each replayer consumes traces produced by existing C++ tests:
Tracing is disabled in normal builds.
* **Consistency**: nodes export consensus events as Fluentd records with the ``ccf.cft`` tag, which :ccf_repo:`tests/infra/consistency_trace.py` collects, joins with the transaction statuses given to clients, and replays through ``consistency-replay``.
The ``consistency_trace_validation`` e2e test (:ccf_repo:`tests/consistency_trace_validation.py`) starts a three-node network running the :ccf_repo:`basic_tv <samples/apps/basic_tv/>` JavaScript application, runs :ccf_repo:`tests/tvc.py` against it, and suspends the primary to cause an election.
The ``e2e_logging`` (:ccf_repo:`tests/e2e_logging.py`) and partitions (:ccf_repo:`tests/partitions_test.py`) e2e tests also record and replay a trace for each of their traced networks.
The ``e2e_forwarding_smoke`` (:ccf_repo:`tests/forwarding.py`), ``e2e_limits`` (:ccf_repo:`tests/limits.py`), ``e2e_logging`` (:ccf_repo:`tests/e2e_logging.py`), ``governance_test`` (:ccf_repo:`tests/governance.py`), ``js_batched_stress_test`` (:ccf_repo:`tests/e2e_batched.py`), ``schema_test`` (:ccf_repo:`tests/schema.py` and :ccf_repo:`tests/e2e_operations.py`), ``tls_stress_test`` (:ccf_repo:`tests/connections.py`), and partitions (:ccf_repo:`tests/partitions_test.py`) e2e tests also record and replay a trace for each of their traced networks.
Comment thread
achamayou marked this conversation as resolved.
Resolved
* **Disaster recovery**: nodes started with the ``CCF_RECOVERY_TRACE`` environment variable set log each step of the recovery decision protocol as an ``RDP_TRACE`` record.
These scenarios only run in the SNP Genoa CI job, where :ccf_repo:`tests/infra/recovery_trace.py` records a manifest for the quorum, failover and multiple-timeout scenarios in :ccf_repo:`tests/e2e_operations.py` and the follow-up ``Replay e2e traces`` job replays those node logs through ``disaster-recovery-replay`` via :ccf_repo:`tests/recovery_trace_validation.py`.

Expand All @@ -87,7 +87,7 @@ The :ccf_repo:`Lean workflow <.github/workflows/lean.yml>` runs on pull requests
* A final ``Lean models and proofs`` job succeeds only if all of the above succeed.

The disaster recovery traces are captured by the SNP Genoa job in the main CI workflow and replayed by its follow-up ``Replay e2e traces`` job, since that is where the recovery scenarios run.
The ``e2e_logging`` and partitions tests replay their consistency traces in the main CI workflow for the same reason.
The remaining consistency-traced e2e tests and partitions tests replay their consistency traces in the main CI workflow for the same reason.

A separate ``Lean Mathlib equivalence`` workflow proves that the replacements for Mathlib definitions in ``lean/common`` are equivalent to the Mathlib originals, and runs only when those definitions change; see :ccf_repo:`lean/mathlib-equivalence/README.md`.

Expand Down
14 changes: 7 additions & 7 deletions lean/consistency/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ Nothing is reconstructed: a trace missing an election or a ledger entry is rejec
Client reads are not traced, so this does not validate the model's read observations.
Empty traces, malformed records, and disabled transitions fail with a line-numbered diagnostic and nonzero exit code.

[`tests/infra/consistency_trace.py`](../../tests/infra/consistency_trace.py) records such a trace for the nodes of a test and replays it, when `CCF_LEAN_CONSISTENCY_REPLAYER` names the replayer.
The trace is written to the test workspace, named after the test, such as `basic_partitions_consistency_trace.ndjson`.
Three e2e tests use it (they require the [CCF build prerequisites](../../doc/contribute/build_setup.rst)):
[`tests/infra/consistency_trace.py`](../../tests/infra/consistency_trace.py) records such a trace for the nodes of a test when `CCF_CONSISTENCY_TRACE` is set or `CCF_LEAN_CONSISTENCY_REPLAYER` names the replayer, and replays it inline when `CCF_LEAN_CONSISTENCY_REPLAYER` is set.
Each trace is written to the test workspace under a directory named after the test, such as `basic_partitions_consistency_trace/0.ndjson`.
Nine e2e tests use it (they require the [CCF build prerequisites](../../doc/contribute/build_setup.rst)):

- [`tests/consistency_trace_validation.py`](../../tests/consistency_trace_validation.py) suspends the primary to cause an election while [`tests/tvc.py`](../../tests/tvc.py) writes, and reports the final status of each write.
- [`tests/e2e_logging.py`](../../tests/e2e_logging.py) traces each of its networks (including the common-endpoints groups in [`tests/e2e_common_endpoints.py`](../../tests/e2e_common_endpoints.py)), and records client-observed statuses from `wait_for_commit`.
- [`tests/forwarding.py`](../../tests/forwarding.py), [`tests/limits.py`](../../tests/limits.py), [`tests/e2e_batched.py`](../../tests/e2e_batched.py), [`tests/connections.py`](../../tests/connections.py) (including [`tests/fuzzing.py`](../../tests/fuzzing.py)), [`tests/governance.py`](../../tests/governance.py) (and its helper modules, excluding disaster-recovery networks), and [`tests/schema.py`](../../tests/schema.py) (including [`tests/e2e_tutorial.py`](../../tests/e2e_tutorial.py) and non-recovery networks in [`tests/e2e_operations.py`](../../tests/e2e_operations.py)) trace their networks and record client-observed statuses from `wait_for_commit`.
- [`tests/partitions_test.py`](../../tests/partitions_test.py) traces each of its networks, and reports the `Invalid` statuses that it checks.

From the repository root:
Expand All @@ -91,11 +92,10 @@ From the repository root:
(cd lean/consistency && lake build --wfail consistency-replay)
export CCF_LEAN_CONSISTENCY_REPLAYER="$PWD/lean/consistency/.lake/build/bin/consistency-replay"
cmake -S . -B build -GNinja -DCMAKE_BUILD_TYPE=Debug -DLONG_TESTS=ON
cmake --build build --target consistency_trace_validation e2e_logging partitions
(cd build && ./tests.sh -VV -R '^consistency_trace_validation$' --no-tests=error)
(cd build && ./tests.sh -VV -R '^e2e_logging$' --no-tests=error)
cmake --build build --target consistency_trace_validation e2e_forwarding_smoke e2e_limits e2e_logging governance_test js_batched_stress_test partitions schema_test tls_stress_test
(cd build && ./tests.sh -VV -R '^(consistency_trace_validation|e2e_forwarding_smoke|e2e_limits|e2e_logging|governance_test|js_batched_stress_test|schema_test|tls_stress_test)$' --no-tests=error)
(cd build && ./tests.sh -VV -C partitions -R '^partitions$' --no-tests=error)
```

The [Lean workflow](../../.github/workflows/lean.yml) runs `consistency_trace_validation` with the replayer, and the [CI workflow](../../.github/workflows/ci.yml) does the same for `e2e_logging` and the partitions tests.
The [Lean workflow](../../.github/workflows/lean.yml) runs `consistency_trace_validation` with the replayer, and the [CI workflow](../../.github/workflows/ci.yml) records traces for the remaining consistency-traced e2e tests and the partitions tests with `CCF_CONSISTENCY_TRACE=1` and replays them in `Replay e2e traces` via [`tests/consistency_trace_replay.py`](../../tests/consistency_trace_replay.py).
The [replay fixtures](replayer/fixtures/README.md) check that the replayer accepts valid traces and rejects invalid ones.
7 changes: 4 additions & 3 deletions scripts/coverage_cft_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

Outputs one profile path per line:
- All cft_scenario-*.profraw files (validated by lean/consensus in lean.yml).
- Every virtual e2e <test_name>-<pid>.profraw whose OS PID emitted ccf.cft
events in workspace/*_trace/*.msgpack with a trace directory label matching
<test_name> (matching tests/cft_trace_validation.py in ci.yml).
- Every virtual e2e [consistency-]<test_name>-<pid>.profraw whose OS PID
emitted ccf.cft events in workspace/*_trace/*.msgpack with a trace directory
label matching <test_name> (matching tests/cft_trace_validation.py in ci.yml).
"""

import argparse
Expand Down Expand Up @@ -62,6 +62,7 @@ def select_profiles(build_dir: pathlib.Path) -> tuple[list[pathlib.Path], int, i
if "-" not in stem_pid:
continue
test_name, pid = stem_pid.rsplit("-", 1)
test_name = test_name.removeprefix("consistency-")
if test_name == "cft_scenario" or not pid.isdigit():
continue
labels = pid_to_labels.get(pid)
Expand Down
1 change: 1 addition & 0 deletions tests/ci-buckets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ bucket_c:

trace_replay:
cft_trace_validation
consistency_trace_replay
recovery_trace_validation

no_bucket:
Expand Down
11 changes: 6 additions & 5 deletions tests/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import fuzzing
import httpx
import infra.checker
import infra.consistency_trace
import infra.e2e_args
import infra.interfaces
import infra.network
Expand Down Expand Up @@ -71,7 +72,7 @@ def run_unsecured_connection_cap_test(args):
accepted_endpoints=["/node/version"],
)

with infra.network.network(
with infra.consistency_trace.recording(args), infra.network.network(
Comment thread
achamayou marked this conversation as resolved.
Resolved
args.nodes, args.binary_dir, args.debug_nodes, pdb=args.pdb
) as network:
network.start_and_open(args)
Expand Down Expand Up @@ -132,7 +133,7 @@ def run_removed_quic_tests(args):
app_protocol="QUIC",
)

with infra.network.network(
with infra.consistency_trace.recording(args), infra.network.network(
args.nodes, args.binary_dir, args.debug_nodes, pdb=args.pdb
) as network:
network.start_and_open(args)
Expand Down Expand Up @@ -171,7 +172,7 @@ def run_connection_caps_tests(args):
)
args.ubsan_options = "suppressions=" + str(supp_file)

with infra.network.network(
with infra.consistency_trace.recording(args), infra.network.network(
args.nodes, args.binary_dir, args.debug_nodes, pdb=args.pdb
) as network:
check = infra.checker.Checker()
Expand Down Expand Up @@ -387,7 +388,7 @@ def verbose_sleep(sleep_time):
timeout = test_case.get("timeout")
args.idle_connection_timeout_s = timeout

with infra.network.network(
with infra.consistency_trace.recording(args), infra.network.network(
args.nodes, args.binary_dir, args.debug_nodes, pdb=args.pdb
) as network:
network.start_and_open(args)
Expand Down Expand Up @@ -444,7 +445,7 @@ def node_tcp_socket(node):

# NB: This does rudimentary smoke testing. See fuzzing.py for more thorough test
def run_node_socket_robustness_tests(args):
with infra.network.network(
with infra.consistency_trace.recording(args), infra.network.network(
args.nodes, args.binary_dir, args.debug_nodes, pdb=args.pdb
) as network:
network.start_and_open(args)
Expand Down
47 changes: 47 additions & 0 deletions tests/consistency_trace_replay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache 2.0 License.
"""Replay recorded consistency traces against the Lean model.

usage: consistency_trace_replay.py CONSISTENCY_REPLAY DIRECTORY...
"""

import concurrent.futures
import functools
import os
import pathlib
import subprocess
import sys


def replay(replayer, path):
result = subprocess.run(
[replayer, str(path)],
capture_output=True,
text=True,
check=False,
)
output = ((result.stdout or "") + (result.stderr or "")).strip()
return result.returncode == 0, output


def main(replayer, *directories):
paths = sorted(
path
for directory in directories
for path in pathlib.Path(directory).rglob("*_consistency_trace/*.ndjson")
)
with concurrent.futures.ThreadPoolExecutor(os.cpu_count()) as pool:
results = list(pool.map(functools.partial(replay, replayer), paths))
rejected = 0
for path, (accepted, output) in zip(paths, results, strict=True):
rejected += not accepted
print(f"{'OK ' if accepted else 'FAIL'} {path}: {output}")
print(f"{len(paths) - rejected} accepted, {rejected} rejected")
return 0 if paths and not rejected else 1


if __name__ == "__main__":
if len(sys.argv) < 3:
sys.exit(__doc__)
sys.exit(main(*sys.argv[1:]))
Loading