util: refactor: Remove deprecated SetMockTime(i64) alias
What changed, and why it matters
This is a small internal cleanup change in Bitcoin Core. It removes an old, redundant shortcut function called SetMockTime that accepted a plain integer, and updates the few remaining callers to use the newer version that takes a typed chrono duration. There is no security fix here; it is purely a code simplification and modernization.
No security action needed. Treat as routine refactoring; normal review and CI testing are sufficient.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit deletes the deprecated SetMockTime(int64_t) overload and its declaration in src/util/time.h. The three remaining callers (RPC setmocktime, fuzz harness initialization, and wallet interface mock-time bridge) are updated to explicitly construct std::chrono::seconds before calling SetMockTime. The behavior is functionally identical because the removed overload did exactly that same conversion internally.
Changed components
src/util/time.hsrc/util/time.cppsrc/rpc/node.cppsrc/test/fuzz/fuzz.cppsrc/wallet/interfaces.cppInspect captured patch +3 / −12
### src/rpc/node.cpp
@@ -69,7 +69,7 @@ static RPCMethod setmocktime()
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime must be in the range [0, %s], not %s.", max_time, time));
}
- SetMockTime(time);
+ SetMockTime(std::chrono::seconds{time});
const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
for (const auto& chain_client : node_context.chain_clients) {
chain_client->setMockTime(time);
### src/test/fuzz/fuzz.cpp
@@ -100,7 +100,7 @@ static void initialize()
SeedRandomStateForTest(SeedRand::ZEROS);
// Set time to the genesis block timestamp for deterministic initialization.
- SetMockTime(1231006505);
+ SetMockTime(1231006505s);
// Terminate immediately if a fuzzing harness ever tries to create a socket.
// Individual tests can override this by pointing CreateSock to a mocked alternative.
### src/util/time.cpp
@@ -49,7 +49,6 @@ NodeClock::time_point NodeClock::now() noexcept
return time_point{ret};
};
-void SetMockTime(int64_t nMockTimeIn) { SetMockTime(std::chrono::seconds{nMockTimeIn}); }
void SetMockTime(std::chrono::time_point<NodeClock, std::chrono::seconds> mock) { SetMockTime(mock.time_since_epoch()); }
void SetMockTime(std::chrono::seconds mock_time_in)
{
### src/util/time.h
@@ -112,14 +112,6 @@ using MillisecondsDouble = std::chrono::duration<double, std::chrono::millisecon
*/
int64_t GetTime();
-/**
- * DEPRECATED
- * Use SetMockTime with chrono type
- *
- * @param[in] nMockTimeIn Time in seconds.
- */
-void SetMockTime(int64_t nMockTimeIn);
-
/** For testing. Set e.g. with the setmocktime rpc, or -mocktime argument */
void SetMockTime(std::chrono::seconds mock_time_in);
void SetMockTime(std::chrono::time_point<NodeClock, std::chrono::seconds> mock);
### src/wallet/interfaces.cpp
@@ -562,7 +562,7 @@ class WalletLoaderImpl : public WalletLoader
return StartWallets(m_context);
}
void stop() override { return UnloadWallets(m_context); }
- void setMockTime(int64_t time) override { return SetMockTime(time); }
+ void setMockTime(int64_t time) override { return SetMockTime(std::chrono::seconds{time}); }
void schedulerMockForward(std::chrono::seconds delta) override { Assert(m_context.scheduler)->MockForward(delta); }
//! WalletLoader methodsWhy this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.