Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ static constexpr auto BLOCK_STALLING_TIMEOUT_MAX{64s};
static const int MAX_CMPCTBLOCK_DEPTH = 5;
/** Maximum depth of blocks we're willing to respond to GETBLOCKTXN requests for. */
static const int MAX_BLOCKTXN_DEPTH = 10;
static_assert(MAX_BLOCKTXN_DEPTH <= MIN_BLOCKS_TO_KEEP, "MAX_BLOCKTXN_DEPTH too high");
/** Size of the "block download window": how far ahead of our current height do we fetch?
* Larger windows tolerate larger download speed differences between peer, but increase the potential
* degree of disordering of blocks on disk (which make reindexing and pruning harder). We'll probably
Expand Down Expand Up @@ -4501,6 +4502,7 @@ void PeerManagerImpl::ProcessMessage(
return;
}

FlatFilePos block_pos{};
{
LOCK(cs_main);

Expand All @@ -4511,13 +4513,20 @@ void PeerManagerImpl::ProcessMessage(
}

if (pindex->nHeight >= m_chainman.ActiveChain().Height() - MAX_BLOCKTXN_DEPTH) {
CBlock block;
bool ret = ReadBlockFromDisk(block, pindex, m_chainparams.GetConsensus());
assert(ret);
block_pos = pindex->GetBlockPos();
}
}

SendBlockTransactions(pfrom, block, req);
if (!block_pos.IsNull()) {
CBlock block;
const auto hash = ReadBlockFromDisk(block, block_pos, m_chainparams.GetConsensus());
if (!hash || *hash != req.blockhash) {
LogPrint(BCLog::NET, "Peer %d sent us a getblocktxn for a block we could not read\n", pfrom.GetId());
return;
Comment on lines +4523 to 4525

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Nitpick: Log message conflates I/O failure with hash mismatch

After dropping cs_main, the failure path emits the same "a block we could not read" line for two distinct conditions: ReadBlockFromDisk returning nullopt (open/deserialize/PoW failure) and the read succeeding with *hash != req.blockhash (a stale FlatFilePos / disk-state inconsistency after the lock was released). Distinguishing these helps operators tell transient I/O or pruning issues from a position-vs-hash race. Diagnostic quality only; not a defect.

source: ['claude']

}

SendBlockTransactions(pfrom, block, req);
return;
}

// If an older block is requested (should never happen in practice,
Expand Down
Loading