diff --git a/src/index/base.cpp b/src/index/base.cpp index 6c547680a4b..9e75109d5c9 100644 --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -155,11 +155,15 @@ static const CBlockIndex* NextSyncBlock(const CBlockIndex* pindex_prev, CChain& return chain.Genesis(); } - const CBlockIndex* pindex = chain.Next(pindex_prev); - if (pindex) { + if (const auto* pindex{chain.Next(pindex_prev)}) { return pindex; } + // If there is no next block, we might be synced + if (pindex_prev == chain.Tip()) { + return nullptr; + } + // Since block is not in the chain, return the next block in the chain AFTER the last common ancestor. // Caller will be responsible for rewinding back to the common ancestor. return chain.Next(chain.FindFork(pindex_prev));