mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
[rpc, bugfix] Enforce maximum value for setmocktime
Github-Pull: #29869
Rebased-From: c2e0489b71
This commit is contained in:
parent
602cfd580a
commit
897e5af58a
2 changed files with 6 additions and 3 deletions
|
@ -26,6 +26,7 @@
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
#include <util/any.h>
|
#include <util/any.h>
|
||||||
#include <util/check.h>
|
#include <util/check.h>
|
||||||
|
#include <util/time.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#ifdef HAVE_MALLOC_INFO
|
#ifdef HAVE_MALLOC_INFO
|
||||||
|
@ -58,9 +59,11 @@ static RPCHelpMan setmocktime()
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
const int64_t time{request.params[0].getInt<int64_t>()};
|
const int64_t time{request.params[0].getInt<int64_t>()};
|
||||||
if (time < 0) {
|
constexpr int64_t max_time{Ticks<std::chrono::seconds>(std::chrono::nanoseconds::max())};
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime cannot be negative: %s.", time));
|
if (time < 0 || time > max_time) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime must be in the range [0, %s], not %s.", max_time, time));
|
||||||
}
|
}
|
||||||
|
|
||||||
SetMockTime(time);
|
SetMockTime(time);
|
||||||
const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
|
const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
|
||||||
for (const auto& chain_client : node_context.chain_clients) {
|
for (const auto& chain_client : node_context.chain_clients) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ class UptimeTest(BitcoinTestFramework):
|
||||||
self._test_uptime()
|
self._test_uptime()
|
||||||
|
|
||||||
def _test_negative_time(self):
|
def _test_negative_time(self):
|
||||||
assert_raises_rpc_error(-8, "Mocktime cannot be negative: -1.", self.nodes[0].setmocktime, -1)
|
assert_raises_rpc_error(-8, "Mocktime must be in the range [0, 9223372036], not -1.", self.nodes[0].setmocktime, -1)
|
||||||
|
|
||||||
def _test_uptime(self):
|
def _test_uptime(self):
|
||||||
wait_time = 10
|
wait_time = 10
|
||||||
|
|
Loading…
Reference in a new issue