Repository navigation
fix: deflake //rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_provision_write_access_test_colocate - #9248
Conversation
…rovision_write_access_test_colocate Skip state hash comparison in verify_latest_cup() when CUP height is above the latest state height. This fixes a deadlock where replay_consensus_pool() calls verify_latest_cup() before deliver_batches(), but the state at the CUP height cannot be committed until batches are delivered. When the downloaded checkpoint is from an earlier DKG interval than the CUP in the consensus pool (e.g. checkpoint at 147, CUP at 168), get_state_hash() loops forever waiting for the state to be committed, causing the 600s test timeout. The CUP signature is still verified; the state hash will be checked later via redeliver_certifications() after batches are delivered.
There was a problem hiding this comment.
Pull request overview
Prevents rs/replay’s Player::verify_latest_cup() from deadlocking during subnet recovery replays when the consensus pool’s latest CUP height is ahead of the locally produced state height, which intermittently causes the referenced deflake test to time out.
Changes:
- Add an early-return guard in
verify_latest_cup()whenCUP.height() > latest_state_height()to skip the state-hash comparison in that case. - Emit an informational log explaining the skip and why it occurs.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if last_cup.height() > self.state_manager.latest_state_height() { | ||
| // The CUP references a height that hasn't been reached yet (e.g. the downloaded | ||
| // checkpoint is from an earlier DKG interval than the CUP in the consensus pool). | ||
| // We cannot verify the state hash until batches up to the CUP height have been | ||
| // delivered. The state hash will be verified later via `redeliver_certifications`. | ||
| info!( | ||
| self.log, | ||
| "The CUP height {} is strictly above the latest state height {}. \ | ||
| Skipping state hash comparison as the state has not been produced yet.", | ||
| last_cup.height(), | ||
| self.state_manager.latest_state_height() | ||
| ); | ||
| return Ok(()); | ||
| } |
There was a problem hiding this comment.
This early-return skips not only the state-hash comparison but also the replica-version/upgrade check that occurs later in verify_latest_cup(). In the scenario where the CUP is ahead of the local state, it would still be useful (and in some call paths, important) to run the replica version check based solely on the CUP content before returning.
| if last_cup.height() > self.state_manager.latest_state_height() { | ||
| // The CUP references a height that hasn't been reached yet (e.g. the downloaded | ||
| // checkpoint is from an earlier DKG interval than the CUP in the consensus pool). | ||
| // We cannot verify the state hash until batches up to the CUP height have been | ||
| // delivered. The state hash will be verified later via `redeliver_certifications`. | ||
| info!( | ||
| self.log, | ||
| "The CUP height {} is strictly above the latest state height {}. \ | ||
| Skipping state hash comparison as the state has not been produced yet.", | ||
| last_cup.height(), | ||
| self.state_manager.latest_state_height() | ||
| ); |
There was a problem hiding this comment.
The log/branch compares against self.state_manager.latest_state_height() multiple times. If the latest height can change between calls, the condition and the logged value can disagree; even if not, this repeats work. Consider reading latest_state_height once into a local variable and using it for both the comparison and the log message.
| // The CUP references a height that hasn't been reached yet (e.g. the downloaded | ||
| // checkpoint is from an earlier DKG interval than the CUP in the consensus pool). | ||
| // We cannot verify the state hash until batches up to the CUP height have been | ||
| // delivered. The state hash will be verified later via `redeliver_certifications`. |
There was a problem hiding this comment.
The inline comment says the state hash will be verified later via redeliver_certifications, but verify_latest_cup() is also used in flows (e.g., backup restore) where redeliver_certifications is not part of the path. Consider rewording to avoid referencing a specific caller, and instead say the state-hash check will occur later once replay has produced the state at the CUP height.
| // delivered. The state hash will be verified later via `redeliver_certifications`. | |
| // delivered. The state hash will be verified later once replay has produced the | |
| // state at the CUP height. |
|
Like Copilot commented, I don't think all callers of the function would be happy with that change. Also, claiming that the state hash would be verified later in Even then, if we skipped checking the hash, we would not have the required artifacts to go from the latest state to the latest CUP, since replicas delete artifacts below the CUP height once they reach it. So it just shifts the problem. |
The test
sr_app_no_upgrade_provision_write_access_test_colocateoften times out:It consitently times out during subnet recovery, during the ic-replay step, while waiting for the state hash to be committed:
Claude Opus 4.6 concluded:
Root Cause
The bug is in
verify_latest_cup()inrs/replay/src/player.rs. During subnet recovery,replay_consensus_pool()callsverify_latest_cup()beforedeliver_batches(). When the downloaded checkpoint is from an earlier DKG interval than the CUP in the consensus pool (e.g. checkpoint at height 147, CUP at height 168),verify_latest_cupcallsget_state_hash(168)but the state at that height hasn't been produced yet. The state manager returns a transient error ("state at height 168 is not committed yet") andget_state_hashloops until the test's 600s timeout fires.This happens intermittently because it depends on timing — whether the subnet has progressed past the downloaded checkpoint's DKG interval by the time the consensus pool artifacts are also downloaded.
Fix
Added a condition in
verify_latest_cup()to skip the state hash comparison when the CUP height is above the latest state height (mirroring the existing skip for the reverse case). The CUP's cryptographic signature is still verified. The state hash will be verified later duringredeliver_certifications()which runs afterdeliver_batches()andwait_for_state().This is not a timeout tuning issue — no amount of waiting would help because the state at the CUP height can never be committed without first replaying blocks, and blocks can't be replayed until
verify_latest_cupreturns. It's a deadlock in the execution flow.This PR was created following the steps in
.claude/skills/fix-flaky-tests/SKILL.md.