mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-06 21:57:54 +02:00
index: add explicit early exit in NextSyncBlock() when the input is the chain tip
When pindex_prev is the chain tip, return earlier and explicitly rather than mixing it with the reorg case. For more detail, please see PR: https://github.com/bitcoin/bitcoin/pull/32875 Co-authored-by: l0rinc <pap.lorinc@gmail.com> Co-authored-by: optout <optout@nostrplebs.com> Co-authored-by: furszy <matiasfurszyfer@protonmail.com>
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user