Skip to content

Commit

Permalink
Add conflicting blocks to the block index but also mark as invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed May 14, 2019
1 parent ef315ca commit 1916980
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 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, bool fValid = true)
{
// Check for duplicate
uint256 hash = block.GetHash();
Expand All @@ -3100,9 +3100,13 @@ 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 (fValid) {
pindexNew->RaiseValidity(BLOCK_VALID_TREE);
if (pindexBestHeader == NULL || pindexBestHeader->nChainWork < pindexNew->nChainWork)
pindexBestHeader = pindexNew;
} else {
pindexNew->nStatus |= BLOCK_FAILED_VALID;
}

setDirtyBlockIndex.insert(pindexNew);

Expand Down Expand Up @@ -3479,6 +3483,10 @@ static bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state
return error("%s: Consensus::ContextualCheckBlockHeader: %s, %s", __func__, hash.ToString(), FormatStateMessage(state));

if (llmq::chainLocksHandler->HasConflictingChainLock(pindexPrev->nHeight + 1, hash)) {
if (pindex == NULL) {
// add it to the block index but also mark it as invalid immediately
AddToBlockIndex(block, false);
}
return state.DoS(10, error("%s: header %s conflicts with chainlock", __func__, hash.ToString()), REJECT_INVALID, "bad-chainlock");
}
}
Expand Down

0 comments on commit 1916980

Please sign in to comment.