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.
This commit is contained in:
1 parent
458720e5e9
commit
15fa5b5a90
1 file changed
+2
-3
+2
-3
@@ -4537,9 +4537,8 @@ bool ChainstateManager::AcceptBlock(const std::shared_ptr<const CBlock>& pblock,
|
|||||||
|
|
||||||
if (!CheckBlock(block, state, params.GetConsensus()) ||
|
if (!CheckBlock(block, state, params.GetConsensus()) ||
|
||||||
!ContextualCheckBlock(block, state, *this, pindex->pprev)) {
|
!ContextualCheckBlock(block, state, *this, pindex->pprev)) {
|
||||||
if (state.IsInvalid() && state.GetResult() != BlockValidationResult::BLOCK_MUTATED) {
|
if (Assume(state.IsInvalid())) {
|
||||||
pindex->nStatus |= BLOCK_FAILED_VALID;
|
ActiveChainstate().InvalidBlockFound(pindex, state);
|
||||||
m_blockman.m_dirty_blockindex.insert(pindex);
|
|
||||||
}
|
}
|
||||||
LogError("%s: %s\n", __func__, state.ToString());
|
LogError("%s: %s\n", __func__, state.ToString());
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in new issue
Block a user