Skip to content

Commit aebfd94

Browse files
committed
RPC/blockchain: Restore ability for pruned nodes to getblockfrompeer future blocks
1 parent 9eefcb9 commit aebfd94

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/rpc/blockchain.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,13 @@ static RPCHelpMan getblockfrompeer()
458458
throw JSONRPCError(RPC_MISC_ERROR, "Block header missing");
459459
}
460460

461+
#if 0
461462
// Fetching blocks before the node has syncing past their height can prevent block files from
462463
// being pruned, so we avoid it if the node is in prune mode.
463464
if (chainman.m_blockman.IsPruneMode() && index->nHeight > WITH_LOCK(chainman.GetMutex(), return chainman.ActiveTip()->nHeight)) {
464465
throw JSONRPCError(RPC_MISC_ERROR, "In prune mode, only blocks that the node has already synced previously can be fetched from a peer");
465466
}
467+
#endif
466468

467469
const bool block_has_data = WITH_LOCK(::cs_main, return index->nStatus & BLOCK_HAVE_DATA);
468470
if (block_has_data) {

test/functional/rpc_getblockfrompeer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def run_test(self):
103103
self.log.info("Non-existent peer generates error, even if we already have the block")
104104
assert_raises_rpc_error(-1, "Block already downloaded", self.nodes[0].getblockfrompeer, short_tip, peer_0_peer_1_id + 1)
105105

106-
self.log.info("Don't fetch blocks while the node has not synced past it yet")
106+
self.log.info("Do fetch blocks even if the node has not synced past it yet")
107107
# For this test we need node 1 in prune mode and as a side effect this also disconnects
108108
# the nodes which is also necessary for the rest of the test.
109109
self.restart_node(1, ["-prune=550"])
@@ -119,13 +119,13 @@ def run_test(self):
119119
node1_interface.send_and_ping(msg_headers([block]))
120120

121121
# Get the peer id of the P2PInterface from the pruning node
122+
node1_interface = self.nodes[1].add_p2p_connection(P2PInterface())
122123
node1_peers = self.nodes[1].getpeerinfo()
123-
assert_equal(len(node1_peers), 1)
124-
node1_interface_id = node1_peers[0]["id"]
124+
assert_equal(len(node1_peers), 2)
125+
node1_interface_id = node1_peers[1]["id"]
125126

126-
# Trying to fetch this block from the P2PInterface should not be possible
127-
error_msg = "In prune mode, only blocks that the node has already synced previously can be fetched from a peer"
128-
assert_raises_rpc_error(-1, error_msg, self.nodes[1].getblockfrompeer, blockhash, node1_interface_id)
127+
# Trying to fetch this block from the P2PInterface should be possible
128+
assert_equal(self.nodes[1].getblockfrompeer(blockhash, node1_interface_id), {})
129129

130130
self.log.info("Connect pruned node")
131131
self.connect_nodes(0, 2)

0 commit comments

Comments
 (0)