| 437 | } |
| 438 | |
| 439 | static RPCHelpMan setmocktime() |
| 440 | { |
| 441 | return RPCHelpMan{"setmocktime", |
| 442 | "\nSet the local time to given timestamp (-regtest only)\n", |
| 443 | { |
| 444 | {"timestamp", RPCArg::Type::NUM, RPCArg::Optional::NO, UNIX_EPOCH_TIME + "\n" |
| 445 | "Pass 0 to go back to using the system time."}, |
| 446 | }, |
| 447 | RPCResult{RPCResult::Type::NONE, "", ""}, |
| 448 | RPCExamples{""}, |
| 449 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 450 | { |
| 451 | if (!Params().IsMockableChain()) { |
| 452 | throw std::runtime_error("setmocktime is for regression testing (-regtest mode) only"); |
| 453 | } |
| 454 | |
| 455 | // For now, don't change mocktime if we're in the middle of validation, as |
| 456 | // this could have an effect on mempool time-based eviction, as well as |
| 457 | // IsCurrentForFeeEstimation() and IsInitialBlockDownload(). |
| 458 | // TODO: figure out the right way to synchronize around mocktime, and |
| 459 | // ensure all call sites of GetTime() are accessing this safely. |
| 460 | LOCK(cs_main); |
| 461 | |
| 462 | RPCTypeCheck(request.params, {UniValue::VNUM}); |
| 463 | const int64_t time{request.params[0].get_int64()}; |
| 464 | if (time < 0) { |
| 465 | throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime cannot be negative: %s.", time)); |
| 466 | } |
| 467 | SetMockTime(time); |
| 468 | auto node_context = util::AnyPtr<NodeContext>(request.context); |
| 469 | if (node_context) { |
| 470 | for (const auto& chain_client : node_context->chain_clients) { |
| 471 | chain_client->setMockTime(time); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | return NullUniValue; |
| 476 | }, |
| 477 | }; |
| 478 | } |
| 479 | |
| 480 | #if defined(USE_SYSCALL_SANDBOX) |
| 481 | static RPCHelpMan invokedisallowedsyscall() |
nothing calls this directly
no test coverage detected