Skip to content

Commit 7fa851f

Browse files
committed
rpc: Pruned nodes can not fetch unsynced blocks
While a node is still catching up to the tip that it is aware of via the headers, the user can currently use to fetch blocks close to the tip. These blocks are stored in the current block/rev file which otherwise contains blocks the node is receiving as part of the syncing process. This creates a problem for pruned nodes: The files containing a fetched block are not pruned during syncing because they contain a block close to the tip. This means the entire file will not be pruned until the tip have moved on far enough from the fetched block. In extreme cases with heavy pruning (550) and multiple blocks being fetched this could mean that the disc usage far exceeds what the user expects, potentially running out of space.
1 parent 1b2e1d1 commit 7fa851f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/rpc/blockchain.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,12 @@ static RPCHelpMan getblockfrompeer()
453453
throw JSONRPCError(RPC_MISC_ERROR, "Block header missing");
454454
}
455455

456+
// Fetching blocks before the node has syncing past their height can prevent block files from
457+
// being pruned, so we avoid it if the node is in prune mode.
458+
if (index->nHeight > chainman.ActiveChain().Tip()->nHeight && node::fPruneMode) {
459+
throw JSONRPCError(RPC_MISC_ERROR, "In prune mode, only blocks that the node has already synced previously can be fetched from a peer");
460+
}
461+
456462
const bool block_has_data = WITH_LOCK(::cs_main, return index->nStatus & BLOCK_HAVE_DATA);
457463
if (block_has_data) {
458464
throw JSONRPCError(RPC_MISC_ERROR, "Block already downloaded");

0 commit comments

Comments
 (0)