Skip to content

Commit

Permalink
throw an error if an invalid block height is passed to getnetworkhash…
Browse files Browse the repository at this point in the history
…ps RPC endpoint
  • Loading branch information
jlopp committed Sep 30, 2023
1 parent 5bbf735 commit 6074de6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ static UniValue GetNetworkHashPS(int lookup, int height, const CChain& active_ch
pb = active_chain[height];
}

if (height > active_chain.Height()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block does not exist at specified height");
}

if (pb == nullptr || !pb->nHeight)
return 0;

Expand Down
5 changes: 5 additions & 0 deletions test/functional/rpc_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ def _test_getnetworkhashps(self):
""").strip(),
lambda: self.nodes[0].getnetworkhashps("a", []),
)
assert_raises_rpc_error(
-8,
textwrap.dedent("Block does not exist at specified height").strip(),
lambda: self.nodes[0].getnetworkhashps(100, self.nodes[0].getblockcount() + 1),
)
# This should be 2 hashes every 10 minutes or 1/300
assert abs(hashes_per_second * 300 - 1) < 0.0001

Expand Down

0 comments on commit 6074de6

Please sign in to comment.