Skip to content

Commit

Permalink
Add blocks (headers) to block index even if they conflict with chainl…
Browse files Browse the repository at this point in the history
…ocks
  • Loading branch information
UdjinM6 committed May 14, 2019
1 parent 67857a1 commit dc3e71b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ enum BlockStatus: uint32_t {
BLOCK_FAILED_VALID = 32, //!< stage after last reached validness failed
BLOCK_FAILED_CHILD = 64, //!< descends from failed block
BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD,

BLOCK_CONFLICT_CHAINLOCK = 128, //!< conflicts with chainlock system
};

/** The block chain is a tree shaped structure starting with the
Expand Down
10 changes: 9 additions & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3473,17 +3473,25 @@ static bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state
if (mi == mapBlockIndex.end())
return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk");
pindexPrev = (*mi).second;
assert(pindexPrev);

if (pindexPrev->nStatus & BLOCK_FAILED_MASK)
return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk");

assert(pindexPrev);
if (pindexPrev->nStatus & BLOCK_CONFLICT_CHAINLOCK)
// it's ok-ish, the other node is probably missing the latest chainlock
return state.DoS(10, error("%s: prev block %s conflicts with chainlock", __func__, block.hashPrevBlock.ToString()), REJECT_INVALID, "bad-prevblk-chainlock");

if (fCheckpointsEnabled && !CheckIndexAgainstCheckpoint(pindexPrev, state, chainparams, hash))
return error("%s: CheckIndexAgainstCheckpoint(): %s", __func__, state.GetRejectReason().c_str());

if (!ContextualCheckBlockHeader(block, state, chainparams.GetConsensus(), pindexPrev, GetAdjustedTime()))
return error("%s: Consensus::ContextualCheckBlockHeader: %s, %s", __func__, hash.ToString(), FormatStateMessage(state));

if (llmq::chainLocksHandler->HasConflictingChainLock(pindexPrev->nHeight + 1, hash)) {
if (pindex == NULL) {
AddToBlockIndex(block, BLOCK_CONFLICT_CHAINLOCK);
}
return state.DoS(10, error("%s: conflicting with chainlock", __func__), REJECT_INVALID, "bad-chainlock");
}
}
Expand Down

0 comments on commit dc3e71b

Please sign in to comment.