mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 23:07:59 +01:00
Add wrapper for adding entries to a chainstate's block index candidates
This commit is contained in:
parent
471da5f6e7
commit
10c05710ce
2 changed files with 12 additions and 3 deletions
|
@ -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). */
|
/** 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)
|
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();
|
queue.pop_front();
|
||||||
pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx;
|
pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx;
|
||||||
pindex->nSequenceId = m_chainman.nBlockSequenceId++;
|
pindex->nSequenceId = m_chainman.nBlockSequenceId++;
|
||||||
if (m_chain.Tip() == nullptr || !setBlockIndexCandidates.value_comp()(pindex, m_chain.Tip())) {
|
TryAddBlockIndexCandidate(pindex);
|
||||||
setBlockIndexCandidates.insert(pindex);
|
|
||||||
}
|
|
||||||
std::pair<std::multimap<CBlockIndex*, CBlockIndex*>::iterator, std::multimap<CBlockIndex*, CBlockIndex*>::iterator> range = m_blockman.m_blocks_unlinked.equal_range(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) {
|
while (range.first != range.second) {
|
||||||
std::multimap<CBlockIndex*, CBlockIndex*>::iterator it = range.first;
|
std::multimap<CBlockIndex*, CBlockIndex*>::iterator it = range.first;
|
||||||
|
|
|
@ -727,6 +727,8 @@ public:
|
||||||
/** Ensures we have a genesis block in the block tree, possibly writing one to disk. */
|
/** Ensures we have a genesis block in the block tree, possibly writing one to disk. */
|
||||||
bool LoadGenesisBlock();
|
bool LoadGenesisBlock();
|
||||||
|
|
||||||
|
void TryAddBlockIndexCandidate(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
void PruneBlockIndexCandidates();
|
void PruneBlockIndexCandidates();
|
||||||
|
|
||||||
void ClearBlockIndexCandidates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
void ClearBlockIndexCandidates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||||
|
|
Loading…
Add table
Reference in a new issue