Skip to content

Commit 6cbf2e5

Browse files
committed
rpc: Improve gettxoutproof error when only header is available.
1 parent 69fc867 commit 6cbf2e5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/rpc/txoutproof.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <merkleblock.h>
1111
#include <node/blockstorage.h>
1212
#include <primitives/transaction.h>
13+
#include <rpc/blockchain.h>
1314
#include <rpc/server.h>
1415
#include <rpc/server_util.h>
1516
#include <rpc/util.h>
@@ -96,6 +97,10 @@ static RPCHelpMan gettxoutproof()
9697
}
9798
}
9899

100+
{
101+
LOCK(cs_main);
102+
CheckBlockDataAvailability(chainman.m_blockman, *pblockindex, /*check_for_undo=*/false);
103+
}
99104
CBlock block;
100105
if (!chainman.m_blockman.ReadBlockFromDisk(block, *pblockindex)) {
101106
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");

test/functional/rpc_txoutproof.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ def run_test(self):
6767
assert_equal(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid_spent], blockhash)), [txid_spent])
6868
# We can't get the proof if we specify a non-existent block
6969
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].gettxoutproof, [txid_spent], "0000000000000000000000000000000000000000000000000000000000000000")
70+
# We can't get the proof if we only have the header of the specified block
71+
block = self.generateblock(self.nodes[0], output="raw(55)", transactions=[], submit=False)
72+
self.nodes[0].submitheader(block["hex"])
73+
assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", self.nodes[0].gettxoutproof, [txid_spent], block['hash'])
7074
# We can get the proof if the transaction is unspent
7175
assert_equal(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid_unspent])), [txid_unspent])
7276
# We can get the proof if we provide a list of transactions and one of them is unspent. The ordering of the list should not matter.

0 commit comments

Comments
 (0)