Skip to content

Commit 15fa5b5

Browse files
committed
validation: call InvalidBlockFound also from AcceptBlock
When a block it found invalid during acceptance (but before connection) we now mark its descendants with BLOCK_FAILED_CHILD and update m_best_header when these things weren't done reliably before. This does not fix a serious bug because the flags and m_best_header were being set on a best-effort basis before and not used for anything critical. Setting these reliably has a slight performance cost (iterating over the entire block index) but leads to more consistency in validation and allows removing m_failed_blocks in a later commit. This can only be triggered by providing a block with sufficient PoW that is otherwise invalid, so it is not a DoS vector.
1 parent 458720e commit 15fa5b5

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/validation.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4537,9 +4537,8 @@ bool ChainstateManager::AcceptBlock(const std::shared_ptr<const CBlock>& pblock,
45374537

45384538
if (!CheckBlock(block, state, params.GetConsensus()) ||
45394539
!ContextualCheckBlock(block, state, *this, pindex->pprev)) {
4540-
if (state.IsInvalid() && state.GetResult() != BlockValidationResult::BLOCK_MUTATED) {
4541-
pindex->nStatus |= BLOCK_FAILED_VALID;
4542-
m_blockman.m_dirty_blockindex.insert(pindex);
4540+
if (Assume(state.IsInvalid())) {
4541+
ActiveChainstate().InvalidBlockFound(pindex, state);
45434542
}
45444543
LogError("%s: %s\n", __func__, state.ToString());
45454544
return false;

0 commit comments

Comments
 (0)