Skip to content

Commit 10c0571

Browse files
committed
Add wrapper for adding entries to a chainstate's block index candidates
1 parent 471da5f commit 10c0571

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/validation.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3416,6 +3416,15 @@ void Chainstate::ResetBlockFailureFlags(CBlockIndex *pindex) {
34163416
}
34173417
}
34183418

3419+
void Chainstate::TryAddBlockIndexCandidate(CBlockIndex* pindex)
3420+
{
3421+
AssertLockHeld(cs_main);
3422+
// If the block has more work than our tip, then it should be a candidate for most-work-chain.
3423+
if (m_chain.Tip() == nullptr || !setBlockIndexCandidates.value_comp()(pindex, m_chain.Tip())) {
3424+
setBlockIndexCandidates.insert(pindex);
3425+
}
3426+
}
3427+
34193428
/** Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS). */
34203429
void Chainstate::ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const FlatFilePos& pos)
34213430
{
@@ -3443,9 +3452,7 @@ void Chainstate::ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pin
34433452
queue.pop_front();
34443453
pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx;
34453454
pindex->nSequenceId = m_chainman.nBlockSequenceId++;
3446-
if (m_chain.Tip() == nullptr || !setBlockIndexCandidates.value_comp()(pindex, m_chain.Tip())) {
3447-
setBlockIndexCandidates.insert(pindex);
3448-
}
3455+
TryAddBlockIndexCandidate(pindex);
34493456
std::pair<std::multimap<CBlockIndex*, CBlockIndex*>::iterator, std::multimap<CBlockIndex*, CBlockIndex*>::iterator> range = m_blockman.m_blocks_unlinked.equal_range(pindex);
34503457
while (range.first != range.second) {
34513458
std::multimap<CBlockIndex*, CBlockIndex*>::iterator it = range.first;

src/validation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,8 @@ class Chainstate
727727
/** Ensures we have a genesis block in the block tree, possibly writing one to disk. */
728728
bool LoadGenesisBlock();
729729

730+
void TryAddBlockIndexCandidate(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
731+
730732
void PruneBlockIndexCandidates();
731733

732734
void ClearBlockIndexCandidates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);

0 commit comments

Comments
 (0)