Merge bitcoin/bitcoin#36063: refactor: [test] Remove deprecated SetMockTime(i64) alias
What changed, and why it matters
This commit is a code cleanup in Bitcoin Core's test and utility code. It removes an old, deprecated shortcut function called SetMockTime that accepted a plain integer, and updates the few remaining callers to use a modern, type-safe time API. There is no security vulnerability here; it is purely a refactoring change to make the codebase easier to maintain.
No security action required. Treat as normal code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The merge removes the deprecated SetMockTime(int64_t) overload from src/util/time.h and src/util/time.cpp. All remaining callers are updated to pass std::chrono::seconds or use the new FakeNodeClock helper in tests. The RPC setmocktime path, fuzz initialization, HTTP server tests, mempool fee estimator tests, and wallet interface are adjusted accordingly. The change is a non-functional refactor with no behavior modification.
Changed components
src/util/time.hsrc/util/time.cppsrc/rpc/node.cppsrc/wallet/interfaces.cppsrc/test/fuzz/fuzz.cppsrc/test/httpserver_tests.cppsrc/test/mempool_fee_estimator_tests.cppInspect captured patch +6 / −15
### 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/test/httpserver_tests.cpp
@@ -805,7 +805,7 @@ BOOST_AUTO_TEST_CASE(http_server_socket_tests)
{
// Hard code the timestamp for the Date header in the HTTP response
// Wed Dec 11 00:47:09 2024 UTC
- SetMockTime(1733878029);
+ FakeNodeClock clock{1733878029s};
// Prepare a request handler that just stores received requests so we can examine them.
// Mutex is required to prevent a race between this test's main thread and the server's I/O loop.
### src/test/mempool_fee_estimator_tests.cpp
@@ -105,6 +105,7 @@ BOOST_AUTO_TEST_CASE(calculate_max_weight_percentiles)
BOOST_AUTO_TEST_CASE(mempool_fee_rate_estimator_cache)
{
+ FakeNodeClock clock{};
MemPoolFeeRateEstimatorCache cache;
const uint256 tip_hash{uint256::ONE};
const uint256 next_tip_hash{uint256{2}};
@@ -122,10 +123,9 @@ BOOST_AUTO_TEST_CASE(mempool_fee_rate_estimator_cache)
BOOST_CHECK(cached->m_economical == economical);
BOOST_CHECK(!cache.GetCachedEstimate(next_tip_hash));
- SetMockTime(GetTime<std::chrono::seconds>() + CACHE_LIFE + std::chrono::seconds{1});
+ clock += CACHE_LIFE + std::chrono::seconds{1};
BOOST_CHECK(cache.IsStale());
BOOST_CHECK(!cache.GetCachedEstimate(tip_hash));
- SetMockTime(0);
}
BOOST_AUTO_TEST_CASE(MempoolFeeRateEstimator)
### 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.