Skip to content

Commit

Permalink
Allow specifying custom block status in AddToBlockIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed May 14, 2019
1 parent ec9e819 commit 67857a1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3074,7 +3074,7 @@ bool ResetBlockFailureFlags(CBlockIndex *pindex) {
return true;
}

CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
CBlockIndex* AddToBlockIndex(const CBlockHeader& block, enum BlockStatus nStatus = BLOCK_VALID_TREE)
{
// Check for duplicate
uint256 hash = block.GetHash();
Expand All @@ -3100,9 +3100,14 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
}
pindexNew->nTimeMax = (pindexNew->pprev ? std::max(pindexNew->pprev->nTimeMax, pindexNew->nTime) : pindexNew->nTime);
pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew);
pindexNew->RaiseValidity(BLOCK_VALID_TREE);
if (pindexBestHeader == NULL || pindexBestHeader->nChainWork < pindexNew->nChainWork)
pindexBestHeader = pindexNew;
if (nStatus & BLOCK_VALID_MASK) {
pindexNew->RaiseValidity(nStatus);
if (pindexBestHeader == NULL || pindexBestHeader->nChainWork < pindexNew->nChainWork)
pindexBestHeader = pindexNew;
} else {
pindexNew->RaiseValidity(BLOCK_VALID_TREE); // required validity level
pindexNew->nStatus |= nStatus;
}

setDirtyBlockIndex.insert(pindexNew);

Expand Down

0 comments on commit 67857a1

Please sign in to comment.