Skip to content

test: fix intermittent baseindex_tests failure from undrained reorg notifications - #8177

Open
PastaPastaPasta wants to merge 1 commit into
dashpay:developfrom
PastaPastaPasta:fix/baseindex-drain-lowered-flush
Open

PastaPastaPasta wants to merge 1 commit into
dashpay:developfrom
PastaPastaPasta:fix/baseindex-drain-lowered-flush

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

baseindex_tests/restart_after_rewind_reindexes_erased_blocks (added in #8042) fails intermittently on a loaded machine: the restarted index's committed tip isn't 100, and after the rewind it isn't 97. Running the test 40 at a time, niced, it failed 14 times in 8000 runs (one as a segfault).

The cause is the test helper LowerLastFlushedBlock(). It reorgs the chain (invalidate, flush, reconnect) and returns with up to ten of the reorg's validation notifications still queued, because InvalidateBlock() and ActivateBestChain() only drain the queue once it holds more than ten callbacks. Notifications go to whatever is registered when the scheduler gets to them, so a slow scheduler thread hands them to the next index the test starts. That index is already synced to the tip, so a stale BlockConnected for a block it has indexed looks like a reorg: it rewinds to that block's parent and moves its committed locator down (to 97 or 99 in the failures).

Upstream has no equivalent fix to backport: this test and helper are Dash-only. bitcoin#36447 drains pending events before indexes are stopped, which this test already does; the stale events here are created after the first index has stopped.

What was done?

LowerLastFlushedBlock() now calls SyncWithValidationInterfaceQueue() before returning, so the reorg's notifications are delivered while no index is registered. restart_rewinds_blocks_synced_above_flush uses the same helper and gets the same protection.

How Has This Been Tested?

  • Made the race deterministic with a throwaway test change: a validation listener that sleeps 100ms in BlockConnected, registered before LowerLastFlushedBlock(), plus a drain right after the second index's Start(). Without the fix the test failed 30/30 with the same two checks; with it, 0/30.
  • With the fix alone, the stress run above (40 parallel niced copies of the test case, 8000 runs) went from 14 failures to 0.
  • baseindex_tests, blockfilter_index_tests, txindex_tests and coinstatsindex_tests pass 10/10 each (Linux x86_64, CMake build against depends).

Breaking Changes

None; test-only.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (if you have permission to set one)

🤖 Generated with Claude Code

…ex starts

LowerLastFlushedBlock() reorgs the chain (invalidate, flush, reconnect)
and returned with up to ten of the reorg's validation notifications still
queued: InvalidateBlock() and ActivateBestChain() only drain the queue
once it holds more than ten callbacks. The notifications are delivered to
whatever is registered when the scheduler gets to them, so with a loaded
scheduler thread they could reach the index that the test starts next.

That index is already synced to the tip, so a stale BlockConnected for a
block it has indexed looks like a reorg: it rewinds to the block's parent
and moves its committed locator down. In
restart_after_rewind_reindexes_erased_blocks, that broke the check that
the restarted index's committed tip is still 100, and the one after the
rewind to 97.

Wait for the notifications in the helper, while no index is registered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PastaPastaPasta PastaPastaPasta added this to the 24.1 milestone Nov 16, 2026
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

After reconnecting blocks, LowerLastFlushedBlock now calls SyncWithValidationInterfaceQueue() before returning. This delivers queued reorg notifications before another index starts.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • dashpay/dash#8042: Adds index rewind and locator commits to the base index test code that this change modifies.
  • dashpay/dash#8047: Adds coverage for a test that calls LowerLastFlushedBlock().
Merge Risk: Minimal · up to d7a80

This is a test-only change that drains pending validation notifications so a later index does not receive stale reorg events. It has no production impact and is low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the test helper LowerLastFlushedBlock() now drains undelivered reorg notifications, which fixes an intermittent baseindex_tests failure. It is short, specific, and mat…
Description check Passed The description explains the intermittent failure of baseindex_tests/restart_after_rewind_reindexes_erased_blocks, its root cause in LowerLastFlushedBlock(), the fix that calls SyncWithValidationInter…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the test helper LowerLastFlushedBlock() now drains undelivered reorg notifications, which fixes an intermittent baseindex_tests failure. It is short, specific, and matches the changeset (SyncWithValidationInterfaceQueue() call in baseindex_tests.cpp).

Full details: Description check

Explanation

The description explains the intermittent failure of baseindex_tests/restart_after_rewind_reindexes_erased_blocks, its root cause in LowerLastFlushedBlock(), the fix that calls SyncWithValidationInterfaceQueue() before returning, and the testing performed. It matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 88f459a4-efb2-420d-9836-17a93e384bd0
Commits

Reviewing files that changed from the base of the PR and between 5bce2e7 and d7a8078.

Files selected for processing: 1

  • src/test/baseindex_tests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

@thepastaclaw

thepastaclaw commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit d7a8078) · triage: low

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final validation — Phase 1 + Phase 2

The test-only change correctly places a FIFO validation-interface queue barrier after LowerLastFlushedBlock() completes its reorg and before either caller starts another index. This prevents stale reorg notifications from being delivered to a newly registered, already-synced index; no in-scope correctness issues were found. Lint, ClangFormat, Cppcheck, and completed build checks pass; remaining build/test checks were still pending in the supplied CI snapshot, with no failed code check attributable to this change.

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: dash-core-commit-history); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — This is a small, self-contained test-helper change that drains queued validation notifications without altering production behavior or critical code paths.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 99% left, weekly 50% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — dash-core-commit-history (completed, effort medium); agent phase2-reviewer

@thepastaclaw thepastaclaw added the pastaclaw:approved thepastaclaw's latest review approved this PR label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pastaclaw:approved thepastaclaw's latest review approved this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants