aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuhas Daftuar <sdaftuar@chaincode.com>2023-06-06 09:10:10 -0400
committerSuhas Daftuar <sdaftuar@chaincode.com>2023-07-14 17:09:06 -0400
commit10c05710ce1602d932037f72dc6c4bbc3f6f34ba (patch)
treed12b055383b23c21c0805f218f24a606810a010e
parent471da5f6e74bac71aeffe2ebc5faff145a6cbcea (diff)
Add wrapper for adding entries to a chainstate's block index candidates
-rw-r--r--src/validation.cpp13
-rw-r--r--src/validation.h2
2 files changed, 12 insertions, 3 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index cdf19e72a1..84eca5da95 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -3416,6 +3416,15 @@ void Chainstate::ResetBlockFailureFlags(CBlockIndex *pindex) {
}
}
+void Chainstate::TryAddBlockIndexCandidate(CBlockIndex* pindex)
+{
+ AssertLockHeld(cs_main);
+ // If the block has more work than our tip, then it should be a candidate for most-work-chain.
+ if (m_chain.Tip() == nullptr || !setBlockIndexCandidates.value_comp()(pindex, m_chain.Tip())) {
+ setBlockIndexCandidates.insert(pindex);
+ }
+}
+
/** Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS). */
void Chainstate::ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const FlatFilePos& pos)
{
@@ -3443,9 +3452,7 @@ void Chainstate::ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pin
queue.pop_front();
pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx;
pindex->nSequenceId = m_chainman.nBlockSequenceId++;
- if (m_chain.Tip() == nullptr || !setBlockIndexCandidates.value_comp()(pindex, m_chain.Tip())) {
- setBlockIndexCandidates.insert(pindex);
- }
+ TryAddBlockIndexCandidate(pindex);
std::pair<std::multimap<CBlockIndex*, CBlockIndex*>::iterator, std::multimap<CBlockIndex*, CBlockIndex*>::iterator> range = m_blockman.m_blocks_unlinked.equal_range(pindex);
while (range.first != range.second) {
std::multimap<CBlockIndex*, CBlockIndex*>::iterator it = range.first;
diff --git a/src/validation.h b/src/validation.h
index d34e31d1de..c38381aa36 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -727,6 +727,8 @@ public:
/** Ensures we have a genesis block in the block tree, possibly writing one to disk. */
bool LoadGenesisBlock();
+ void TryAddBlockIndexCandidate(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
+
void PruneBlockIndexCandidates();
void ClearBlockIndexCandidates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);