Repository navigation
fix: Revert async hashing - #10001
Merged
Merged
Conversation
This reverts commit d28780e.
pierugo-dfinity
approved these changes
Apr 23, 2026
cgundy
approved these changes
Apr 23, 2026
basvandijk
enabled auto-merge
April 23, 2026 15:32
AleDema
pushed a commit
to AleDema/ic
that referenced
this pull request
Oct 18, 2026
…nable_chain_keys_test_farm_colocate (dfinity#11818) ## Problem `//rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_enable_chain_keys_test_farm_colocate` flaked once in the week up to 2026-10-11 ([2026-10-05 16:19 UTC](https://dash.dm1-idx1.dfinity.network/invocation/b6dca5c2-ade4-4df4-94c4-d5d47bda5ff1?target=//rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_enable_chain_keys_test_farm_colocate), on PR dfinity#11744's branch). The recovery tool failed in `ValidateReplayOutput`: ``` Execution of step ValidateReplayOutput failed: Output error: Invalid output: Replay height smaller than certification height. ``` `ic-replay` had replayed 45 batches up to height 245 (the certification height), delivered the extra checkpointing batch 246 and logged `Created unverified checkpoint @246`, `Computed root hash ... of state @246` and `Validated checkpoint @246`. Yet its `ReplayOutput` reported the latest CUP's state, `StateParams { height: 200, hash: f3f4ff1b... }`, so the validation compared 200 - 1 against 245. In the passing attempts `Height after replay` is the certification height + 1, as intended since dfinity#11203. ## Root cause `Player::get_latest_state_params` read the hash of the latest state once and treated *any* `Err` from `get_state_hash_at` as "the latest state exists in memory only", falling back to the latest CUP. That read can fail transiently for a checkpoint that already exists on disk: - For a checkpoint round, `commit_and_certify` enqueues `ComputeManifest` and `ValidateReplicatedStateAndFinalize` on the tip channel, then has the hash thread insert `states_metadata[height]` (without a manifest yet) and publish the new `latest_state_height`, waits for it, and only then enqueues the follow-up `WaitForManifest` request that publishes the manifest (and `ResetTipAndMerge`). - `ic-replay`'s `wait_for_state` polls `latest_state_height` every 500 ms and then calls `flush_tip_channel`. If it observes the new height before `WaitForManifest` is enqueued, its `Wait` request lands between `ValidateReplicatedStateAndFinalize` and `WaitForManifest`: the flush returns as soon as the checkpoint is validated, while the root hash is still unpublished, and `get_state_hash_at` returns `Transient(HashNotComputedYet)`. The failing log shows this interleaving. Checkpoint 246 was created and its certification hash computed at 16:19:36.635; `ic-replay` saw height 246 at .664 (one poll later) and its flush returned at .797, right after `Validated checkpoint @246`; two further `wait_for_state` calls at .797 and .798 returned immediately, so `WaitForManifest` was still not enqueued; `ReplayOutput { height: 200 }` was printed at .975, and `ResetTipAndMerge` (enqueued together with `WaitForManifest`) ran at .969, during the state manager's drop. Why `commit_and_certify` needed more than 160 ms between publishing the height and enqueueing the follow-ups is inferred, not shown: the hash thread persists the states metadata with an fsync before it answers, and this run's checkpoint creation took 470 ms against 10 ms in the passing attempt. The window exists since async hashing moved the height publication onto the hash thread (dfinity#8464, reverted in dfinity#10001, re-landed as dfinity#10071 on 2026-05-08); the single read in `ic-replay` dates from 2022. This is not only a flake: the recovery tool went on to delete every checkpoint but the highest (246) while the state params it would put into the recovery CUP were those of height 200. `ValidateReplayOutput` caught it here, but the corrupted-CUP recoveries skip that step. ## Fix Read the hash with the existing `get_state_hash` helper, which retries transient errors every second and returns `None` only for `StateNotFullyCertified`, i.e. a state that really exists in memory only; the fallback to the CUP (or, without a consensus pool, to the highest checkpoint, now read the same way) is unchanged for that case. The helper answers height 0, which is never a checkpoint, with `None` without polling (an empty state directory would otherwise make the state manager report it as not committed yet forever), so `update-registry-local-store` on an empty state fails as before instead of waiting. Unit tests pin both `None` cases down. Behaviour changes to be aware of: a `StateRemoved` error for the latest state, which cannot happen, now panics instead of silently reporting the CUP; and like `verify_latest_cup`, which already used the helper, the poll is unbounded, so a manifest that is never published would make `ic-replay` log "Waiting for state hash" every second rather than report a wrong height. Follow-up for the state manager (not in this PR): `flush_tip_channel` is documented to finish "all asynchronous checkpointing operations, including ... manifest computation", but a caller on another thread can flush before `commit_and_certify` has enqueued `WaitForManifest`. `ic-replay` was the only such caller; the other callers flush from the committing thread. Not related to dfinity#11795: that change only touches the Local backend's bridge, and this run was colocated on Farm. ## Testing - `cargo check --all-targets --all-features -p ic-replay`, `cargo fmt`, `./ci/scripts/rust-lint.sh`. - `bazel build //rs/replay:replay`; `bazel test //rs/recovery:recovery_test //rs/replay:player_integration_tests //rs/replay:replay_doc_test //rs/replay:replay_test` (rerun after each review follow-up). - `bazel test --runs_per_test=3 --jobs=3 //rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_enable_chain_keys_test_farm_colocate`: 3/3 passed on Farm (372 s, 390 s, 380 s), each with `Height after replay` = certification height + 1. Passing runs cannot exercise the window, which needs the checkpoint's I/O to be slow; the evidence for the fix is the log analysis above and the unit tests. This PR was created following the steps in `.claude/skills/fix-flaky-tests/SKILL.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
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.
This PR reverts #9850 and #8464 because the latter may have introduced a bug. The former depends on the latter, so reverting them together leads to the smallest conflict.