From e5b537bbdfbfb43ac7bd8e91958e4a2bbd2577ff Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Tue, 16 Jul 2024 14:11:13 -0400 Subject: [PATCH] rest: improve error when only header of a block is available. This avoids calling ReadRawBlockFromDisk() when the block is expected not to be available because we haven't downloaded it yet and only know the header. --- src/rest.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rest.cpp b/src/rest.cpp index c42bc8e40c2..4732922a156 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -309,8 +309,11 @@ static bool rest_block(const std::any& context, if (!pblockindex) { return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); } - if (chainman.m_blockman.IsBlockPruned(*pblockindex)) { - return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)"); + if (!(pblockindex->nStatus & BLOCK_HAVE_DATA)) { + if (chainman.m_blockman.IsBlockPruned(*pblockindex)) { + return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)"); + } + return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (not fully downloaded)"); } pos = pblockindex->GetBlockPos(); }