tests: remove ResetIbd and JumpOutOfIbd helpers, update test logic to use IsInitialBlockDownload#91
Draft
tests: remove ResetIbd and JumpOutOfIbd helpers, update test logic to use IsInitialBlockDownload#91
ResetIbd and JumpOutOfIbd helpers, update test logic to use IsInitialBlockDownload#91Conversation
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.
…c to use `IsInitialBlockDownload`
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.
WIP