aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authordergoegge <n.goeggi@gmail.com>2024-04-15 08:53:52 +0100
committerdergoegge <n.goeggi@gmail.com>2024-04-15 09:51:06 +0100
commitc2e0489b7125cceaeef355fc274dd8988822fff4 (patch)
tree472a526e6506186e2c8645150df8517612c9cab7 /src/rpc
parent0de63b8b46eff5cda85b4950062703324ba65a80 (diff)
downloadbitcoin-c2e0489b7125cceaeef355fc274dd8988822fff4.tar.xz
[rpc, bugfix] Enforce maximum value for setmocktime
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/node.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/rpc/node.cpp b/src/rpc/node.cpp
index b8c0080aef..ffc2ee5ab0 100644
--- a/src/rpc/node.cpp
+++ b/src/rpc/node.cpp
@@ -26,6 +26,7 @@
#include <univalue.h>
#include <util/any.h>
#include <util/check.h>
+#include <util/time.h>
#include <stdint.h>
#ifdef HAVE_MALLOC_INFO
@@ -58,9 +59,11 @@ static RPCHelpMan setmocktime()
LOCK(cs_main);
const int64_t time{request.params[0].getInt<int64_t>()};
- if (time < 0) {
- throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime cannot be negative: %s.", time));
+ constexpr int64_t max_time{Ticks<std::chrono::seconds>(std::chrono::nanoseconds::max())};
+ 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);
const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
for (const auto& chain_client : node_context.chain_clients) {