Skip to content

Commit 4406c3e

Browse files
committed
Merge pull request #5459
3497022 Reject headers that build on an invalid parent (Pieter Wuille)
2 parents 66ef824 + 3497022 commit 4406c3e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,10 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<CBl
449449
// are not yet downloaded and not in flight to vBlocks. In the mean time, update
450450
// pindexLastCommonBlock as long as all ancestors are already downloaded.
451451
BOOST_FOREACH(CBlockIndex* pindex, vToFetch) {
452+
if (!pindex->IsValid(BLOCK_VALID_TREE)) {
453+
// We consider the chain that this peer is on invalid.
454+
return;
455+
}
452456
if (pindex->nStatus & BLOCK_HAVE_DATA) {
453457
if (pindex->nChainTx)
454458
state->pindexLastCommonBlock = pindex;
@@ -2563,6 +2567,8 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
25632567
if (mi == mapBlockIndex.end())
25642568
return state.DoS(10, error("%s : prev block not found", __func__), 0, "bad-prevblk");
25652569
pindexPrev = (*mi).second;
2570+
if (pindexPrev->nStatus & BLOCK_FAILED_MASK)
2571+
return state.DoS(100, error("%s : prev block invalid", __func__), REJECT_INVALID, "bad-prevblk");
25662572
}
25672573

25682574
if (!ContextualCheckBlockHeader(block, state, pindexPrev))

0 commit comments

Comments
 (0)