Skip to content

tests: remove ResetIbd and JumpOutOfIbd helpers, update test logic to use IsInitialBlockDownload#91

Draft
l0rinc wants to merge 6 commits intomasterfrom
detached475
Draft

tests: remove ResetIbd and JumpOutOfIbd helpers, update test logic to use IsInitialBlockDownload#91
l0rinc wants to merge 6 commits intomasterfrom
detached475

Conversation

@l0rinc
Copy link
Copy Markdown
Owner

@l0rinc l0rinc commented Jan 11, 2026

WIP

l0rinc and others added 6 commits January 11, 2026 15:46
Factor the chain tip "enough work and recent" checks out of `ChainstateManager::IsInitialBlockDownload()` into a reusable `CChain::IsTipRecent()` helper.
This keeps the work/recency definition in one place and makes follow-up caching changes easier to reason about.

Co-authored-by: Patrick Strateman <patrick.strateman@gmail.com>
Introduce `ChainstateManager::SetTip()` and route active chain tip updates through it from `ConnectTip()`, `DisconnectTip()`, and `LoadChainTip()`.
Centralizing tip updates makes it harder to miss related state updates in follow-up commits (e.g. caching IBD-related state on tip changes).

Also switch `m_cached_finished_ibd` to `std::atomic_bool` for consistency with other boolean atomics.
Add a `m_cached_tip_recent` latch that becomes true once the active chain tip exists, has at least `MinimumChainWork()`, and is not older than `-maxtipage`.
Update the latch when `SetTip()` advances the active chain so `IsInitialBlockDownload()` can rely on a cached value instead of re-checking the tip.

Update `TestChainstateManager` helpers to keep the new latch consistent in tests.

Co-authored-by: Patrick Strateman <patrick.strateman@gmail.com>
Now that `IsInitialBlockDownload()` depends only on atomic state (`m_cached_finished_ibd`, `m_cached_tip_recent`, and `BlockManager::LoadingBlocks()`), it no longer needs to take `cs_main`.
Remove the lock and the now-redundant pre-test.

Co-authored-by: Patrick Strateman <patrick.strateman@gmail.com>
With `IsInitialBlockDownload()` lock-free, multiple threads can concurrently reach the latching path and emit duplicate "Leaving InitialBlockDownload" logs.
Use `m_cached_finished_ibd.exchange(true, ...)` so the log is only emitted on the false->true transition.
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