mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-15 00:14:08 +02:00
Change pindexMostWork parameter of ActivateBestChainStep() to reference
ActivateBestChainStep() is always called with non-nullptr pindexMostWork parameter, change the type of the parameter from pointer to reference to enforce this. Also rename the parameter (prefix p doesn't make sense any more).
This commit is contained in:
@@ -3172,18 +3172,18 @@ void Chainstate::PruneBlockIndexCandidates() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to make some progress towards making pindexMostWork the active block.
|
||||
* pblock is either nullptr or a pointer to a CBlock corresponding to pindexMostWork.
|
||||
* Try to make some progress towards making index_most_work the active block.
|
||||
* pblock is either nullptr or a pointer to a CBlock corresponding to index_most_work.
|
||||
*
|
||||
* @returns true unless a system error occurred
|
||||
*/
|
||||
bool Chainstate::ActivateBestChainStep(BlockValidationState& state, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, std::vector<ConnectedBlock>& connected_blocks)
|
||||
bool Chainstate::ActivateBestChainStep(BlockValidationState& state, CBlockIndex& index_most_work, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, std::vector<ConnectedBlock>& connected_blocks)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
if (m_mempool) AssertLockHeld(m_mempool->cs);
|
||||
|
||||
const CBlockIndex* pindexOldTip = m_chain.Tip();
|
||||
const CBlockIndex* pindexFork = pindexMostWork ? m_chain.FindFork(*pindexMostWork) : nullptr;
|
||||
const CBlockIndex* pindexFork = m_chain.FindFork(index_most_work);
|
||||
|
||||
// Disconnect active blocks which are no longer in the best chain.
|
||||
bool fBlocksDisconnected = false;
|
||||
@@ -3207,13 +3207,13 @@ bool Chainstate::ActivateBestChainStep(BlockValidationState& state, CBlockIndex*
|
||||
std::vector<CBlockIndex*> vpindexToConnect;
|
||||
bool fContinue = true;
|
||||
int nHeight = pindexFork ? pindexFork->nHeight : -1;
|
||||
while (fContinue && nHeight != pindexMostWork->nHeight) {
|
||||
while (fContinue && nHeight != index_most_work.nHeight) {
|
||||
// Don't iterate the entire list of potential improvements toward the best tip, as we likely only need
|
||||
// a few blocks along the way.
|
||||
int nTargetHeight = std::min(nHeight + 32, pindexMostWork->nHeight);
|
||||
int nTargetHeight = std::min(nHeight + 32, index_most_work.nHeight);
|
||||
vpindexToConnect.clear();
|
||||
vpindexToConnect.reserve(nTargetHeight - nHeight);
|
||||
CBlockIndex* pindexIter = pindexMostWork->GetAncestor(nTargetHeight);
|
||||
CBlockIndex* pindexIter = index_most_work.GetAncestor(nTargetHeight);
|
||||
while (pindexIter && pindexIter->nHeight != nHeight) {
|
||||
vpindexToConnect.push_back(pindexIter);
|
||||
pindexIter = pindexIter->pprev;
|
||||
@@ -3222,7 +3222,7 @@ bool Chainstate::ActivateBestChainStep(BlockValidationState& state, CBlockIndex*
|
||||
|
||||
// Connect new blocks.
|
||||
for (CBlockIndex* pindexConnect : vpindexToConnect | std::views::reverse) {
|
||||
if (!ConnectTip(state, pindexConnect, pindexConnect == pindexMostWork ? pblock : std::shared_ptr<const CBlock>(), connected_blocks, disconnectpool)) {
|
||||
if (!ConnectTip(state, pindexConnect, pindexConnect == &index_most_work ? pblock : std::shared_ptr<const CBlock>(), connected_blocks, disconnectpool)) {
|
||||
if (state.IsInvalid()) {
|
||||
// The block violates a consensus rule.
|
||||
if (state.GetResult() != BlockValidationResult::BLOCK_MUTATED) {
|
||||
@@ -3372,7 +3372,7 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
|
||||
// in case snapshot validation is completed during ActivateBestChainStep, the
|
||||
// result of GetRole() changes from BACKGROUND to NORMAL.
|
||||
const ChainstateRole chainstate_role{this->GetRole()};
|
||||
if (!ActivateBestChainStep(state, pindexMostWork, pblock && pblock->GetHash() == pindexMostWork->GetBlockHash() ? pblock : nullBlockPtr, fInvalidFound, connected_blocks)) {
|
||||
if (!ActivateBestChainStep(state, *pindexMostWork, pblock && pblock->GetHash() == pindexMostWork->GetBlockHash() ? pblock : nullBlockPtr, fInvalidFound, connected_blocks)) {
|
||||
// A system error occurred
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user