Skip to content

Commit 1b045b5

Browse files
author
MarcoFalke
committed
Merge #21053: rpc, test: document {previous,next}blockhash as optional
ba7e17e rpc, test: document {previous,next}blockhash as optional (Sebastian Falbesoner) Pull request description: This PR updates the result help of the following RPCs w.r.t. the `previousblockhash` and `nextblockhash` fields: - getblockheader - getblock Also adds trivial tests on genesis block (should not contain "previousblockhash") and best block (should not contain "nextblockhash"). Top commit has no ACKs. Tree-SHA512: ef42c5c773fc436e1b4a67be14e2532e800e1e30e45e54a57431c6abb714d2c069c70d40ea4012d549293b823a1973b3f569484b3273679683b28ed40abf46bb
2 parents a9335e4 + ba7e17e commit 1b045b5

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/rpc/blockchain.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,8 @@ static RPCHelpMan getblockheader()
800800
{RPCResult::Type::NUM, "difficulty", "The difficulty"},
801801
{RPCResult::Type::STR_HEX, "chainwork", "Expected number of hashes required to produce the current chain"},
802802
{RPCResult::Type::NUM, "nTx", "The number of transactions in the block"},
803-
{RPCResult::Type::STR_HEX, "previousblockhash", "The hash of the previous block"},
804-
{RPCResult::Type::STR_HEX, "nextblockhash", "The hash of the next block"},
803+
{RPCResult::Type::STR_HEX, "previousblockhash", /* optional */ true, "The hash of the previous block (if available)"},
804+
{RPCResult::Type::STR_HEX, "nextblockhash", /* optional */ true, "The hash of the next block (if available)"},
805805
}},
806806
RPCResult{"for verbose=false",
807807
RPCResult::Type::STR_HEX, "", "A string that is serialized, hex-encoded data for block 'hash'"},
@@ -908,8 +908,8 @@ static RPCHelpMan getblock()
908908
{RPCResult::Type::NUM, "difficulty", "The difficulty"},
909909
{RPCResult::Type::STR_HEX, "chainwork", "Expected number of hashes required to produce the chain up to this block (in hex)"},
910910
{RPCResult::Type::NUM, "nTx", "The number of transactions in the block"},
911-
{RPCResult::Type::STR_HEX, "previousblockhash", "The hash of the previous block"},
912-
{RPCResult::Type::STR_HEX, "nextblockhash", "The hash of the next block"},
911+
{RPCResult::Type::STR_HEX, "previousblockhash", /* optional */ true, "The hash of the previous block (if available)"},
912+
{RPCResult::Type::STR_HEX, "nextblockhash", /* optional */ true, "The hash of the next block (if available)"},
913913
}},
914914
RPCResult{"for verbosity = 2",
915915
RPCResult::Type::OBJ, "", "",

test/functional/rpc_blockchain.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ def _test_getblockheader(self):
316316
header.calc_sha256()
317317
assert_equal(header.hash, besthash)
318318

319+
assert 'previousblockhash' not in node.getblockheader(node.getblockhash(0))
320+
assert 'nextblockhash' not in node.getblockheader(node.getbestblockhash())
321+
319322
def _test_getdifficulty(self):
320323
difficulty = self.nodes[0].getdifficulty()
321324
# 1 hash in 2 should be valid, so difficulty should be 1/2**31
@@ -420,6 +423,9 @@ def move_block_file(old, new):
420423
# Restore chain state
421424
move_block_file('rev_wrong', 'rev00000.dat')
422425

426+
assert 'previousblockhash' not in node.getblock(node.getblockhash(0))
427+
assert 'nextblockhash' not in node.getblock(node.getbestblockhash())
428+
423429

424430
if __name__ == '__main__':
425431
BlockchainTest().main()

0 commit comments

Comments
 (0)