blockstorage: return an error code from ReadRawBlock()

It will enable different error handling flows for different error types.

Also, `ReadRawBlockBench` performance has decreased due to no longer reusing a vector
with an unchanging capacity - mirroring our production code behavior.

Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
Co-authored-by: Lőrinc <pap.lorinc@gmail.com>
This commit is contained in:
Roman Zeyde
2025-12-03 20:06:27 +01:00
parent cca113f5b0
commit f2fd1aa21c
7 changed files with 41 additions and 36 deletions

View File

@@ -2276,8 +2276,9 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
} else if (inv.IsMsgWitnessBlk()) {
// Fast-path: in this case it is possible to serve the block directly from disk,
// as the network format matches the format on disk
std::vector<std::byte> block_data;
if (!m_chainman.m_blockman.ReadRawBlock(block_data, block_pos)) {
if (const auto block_data{m_chainman.m_blockman.ReadRawBlock(block_pos)}) {
MakeAndPushMessage(pfrom, NetMsgType::BLOCK, std::span{*block_data});
} else {
if (WITH_LOCK(m_chainman.GetMutex(), return m_chainman.m_blockman.IsBlockPruned(*pindex))) {
LogDebug(BCLog::NET, "Block was pruned before it could be read, %s\n", pfrom.DisconnectMsg(fLogIPs));
} else {
@@ -2286,7 +2287,6 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
pfrom.fDisconnect = true;
return;
}
MakeAndPushMessage(pfrom, NetMsgType::BLOCK, std::span{block_data});
// Don't set pblock as we've sent the block
} else {
// Send block from disk