Skip to content

fix(consensus-observer): verify commit epoch before clearing blocks - #378

Open
apenzk wants to merge 2 commits into
m1from
fix/consensus-observer-commit-callback-epoch-guard
Open

fix(consensus-observer): verify commit epoch before clearing blocks#378
apenzk wants to merge 2 commits into
m1from
fix/consensus-observer-commit-callback-epoch-guard

Conversation

@apenzk

@apenzk apenzk commented Jun 8, 2026

Copy link
Copy Markdown

Description

The observer has a guard meant to reject commit notifications from the wrong epoch — but it ran after the cache eviction it was supposed to protect. So the guard rejected the notification while the damage was already done.

handle_committed_blocks did this:

1. evict cached payloads + ordered blocks   ← happens unconditionally
2. if wrong epoch { return }                 ← too late, caches already cleared

A commit notification for a different epoch than the root can legitimately arrive — a stale/orphaned callback racing with an epoch transition. When it did, step 1 wiped payloads and ordered blocks the observer still needed, and the observer stalled until it recovered via state sync. The wrong-epoch return blocked the root from advancing but never stopped the eviction.

The fix is a one-line reorder: check the epoch first, so a wrong-epoch notification returns before touching anything. Same-epoch notifications behave exactly as before. Impact is limited to observer/follower nodes — no committed ledger state is affected.

How Has This Been Tested?

New test test_handle_committed_blocks_wrong_epoch_preserves_caches. The test is added in its own commit ahead of the fix, so it can be run against both states.

Failure (old behavior). Check out the test commit (test present, fix absent) — the test fails because the caches are emptied:

git checkout fix/consensus-observer-commit-callback-epoch-guard~1
cargo test -p aptos-consensus --lib test_handle_committed_blocks_wrong_epoch_preserves_caches   # FAILS: left: 0, right: 3

Success (with the fix). Return to the branch tip — the same test passes:

git checkout fix/consensus-observer-commit-callback-epoch-guard
cargo test -p aptos-consensus --lib test_handle_committed_blocks_wrong_epoch_preserves_caches

Type of Change

  • Bug fix
  • Tests

apenzk added 2 commits June 8, 2026 15:50
- seed payload and ordered-block caches at the root epoch, then deliver a commit notification for a different epoch
- assert nothing is evicted from either cache and the root does not advance
- fails against current ordering (caches cleared before the epoch check); committed in failing state ahead of the fix
- move the epoch-match check ahead of the payload and ordered-block cache eviction, so a commit callback for a different epoch no longer clears caches it should leave untouched
- a wrong-epoch callback now returns early without evicting anything or advancing the root
@apenzk
apenzk requested a review from areshand as a code owner June 8, 2026 13:51
@apenzk
apenzk requested review from 0xIcarus, areshand, fEst1ck, musitdev, rubujubi and seanyoung and removed request for 0xIcarus, areshand, fEst1ck, musitdev and rubujubi June 8, 2026 13:52
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