diff --git a/doc/release-notes.md b/doc/release-notes.md --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -9,4 +9,5 @@ (previously was `Bitcoin Signed Message:`). - A new `getindexinfo` RPC returns the actively running indices of the node, including their current sync status and height. It also accepts an `index_name` - to specify returning only the status of that index. \ No newline at end of file + to specify returning only the status of that index. + - The `getnetworkhashps` RPC no longer accepts a negative number of blocks. diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -96,14 +96,12 @@ "getnetworkhashps", "Returns the estimated network hashes per second based on the last n " "blocks.\n" - "Pass in [blocks] to override # of blocks, -1 specifies since last " - "difficulty change.\n" + "Pass in [nblocks] to override # of blocks.\n" "Pass in [height] to estimate the network speed at the time when a " "certain block was found.\n", { {"nblocks", RPCArg::Type::NUM, /* default */ "120", - "The number of blocks, or -1 for blocks since last difficulty " - "change."}, + "The number of blocks."}, {"height", RPCArg::Type::NUM, /* default */ "-1", "To estimate at the time of the given height."}, }, @@ -113,10 +111,17 @@ } .Check(request); + int nblocks = + !request.params[0].isNull() ? request.params[0].get_int() : 120; + if (nblocks < 0) { + throw JSONRPCError(RPC_INVALID_PARAMETER, + "Negative number of blocks not accepted"); + } + LOCK(cs_main); - return GetNetworkHashPS( - !request.params[0].isNull() ? request.params[0].get_int() : 120, - !request.params[1].isNull() ? request.params[1].get_int() : -1); + return GetNetworkHashPS(nblocks, !request.params[1].isNull() + ? request.params[1].get_int() + : -1); } static bool GenerateBlock(const Config &config, ChainstateManager &chainman, diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -337,6 +337,12 @@ # This should be 2 hashes every 10 minutes or 1/300 assert abs(hashes_per_second * 300 - 1) < 0.0001 + # Passing nblocks = -1 used to mean "since last difficulty change". + # This is now meaningless, as the difficulty adjusts for every block. + assert_raises_rpc_error( + -8, "Negative number of blocks not accepted", + self.nodes[0].getnetworkhashps, -1) + def _test_stopatheight(self): assert_equal(self.nodes[0].getblockcount(), 200) self.nodes[0].generatetoaddress(