Skip to content

Commit 569ceb0

Browse files
Crypt-iQfanquake
authored andcommitted
net: check for empty header before calling FillBlock
Previously in debug builds, this would cause an Assume crash if FillBlock had been called previously. This could happen when multiple blocktxn messages were received. Co-Authored-By: Greg Sanders <[email protected]> Github-Pull: #33296 Rebased-From: 5e585a0
1 parent 4c940d4 commit 569ceb0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/net_processing.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,6 +3315,16 @@ void PeerManagerImpl::ProcessCompactBlockTxns(CNode& pfrom, Peer& peer, const Bl
33153315

33163316
PartiallyDownloadedBlock& partialBlock = *range_flight.first->second.second->partialBlock;
33173317

3318+
if (partialBlock.header.IsNull()) {
3319+
// It is possible for the header to be empty if a previous call to FillBlock wiped the header, but left
3320+
// the PartiallyDownloadedBlock pointer around (i.e. did not call RemoveBlockRequest). In this case, we
3321+
// should not call LookupBlockIndex below.
3322+
RemoveBlockRequest(block_transactions.blockhash, pfrom.GetId());
3323+
Misbehaving(peer, "previous compact block reconstruction attempt failed");
3324+
LogDebug(BCLog::NET, "Peer %d sent compact block transactions multiple times", pfrom.GetId());
3325+
return;
3326+
}
3327+
33183328
// We should not have gotten this far in compact block processing unless it's attached to a known header
33193329
const CBlockIndex* prev_block{Assume(m_chainman.m_blockman.LookupBlockIndex(partialBlock.header.hashPrevBlock))};
33203330
ReadStatus status = partialBlock.FillBlock(*pblock, block_transactions.txn,
@@ -3326,6 +3336,9 @@ void PeerManagerImpl::ProcessCompactBlockTxns(CNode& pfrom, Peer& peer, const Bl
33263336
} else if (status == READ_STATUS_FAILED) {
33273337
if (first_in_flight) {
33283338
// Might have collided, fall back to getdata now :(
3339+
// We keep the failed partialBlock to disallow processing another compact block announcement from the same
3340+
// peer for the same block. We let the full block download below continue under the same m_downloading_since
3341+
// timer.
33293342
std::vector<CInv> invs;
33303343
invs.emplace_back(MSG_BLOCK | GetFetchFlags(peer), block_transactions.blockhash);
33313344
MakeAndPushMessage(pfrom, NetMsgType::GETDATA, invs);

0 commit comments

Comments
 (0)