mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-03 17:54:19 +02:00
Merge bitcoin/bitcoin#31549: fuzz: Abort if system time is called without mock time being set
a96b84cb1bfuzz: Abort when calling system time without setting mock time (marcofleon)ff21870e20fuzz: Add SetMockTime() to necessary targets (marcofleon) Pull request description: This PR expands the `CheckGlobals` utility that was introduced in https://github.com/bitcoin/bitcoin/pull/31486 and should help with fuzz stability (https://github.com/bitcoin/bitcoin/issues/29018). System time shouldn't be used when running a fuzz test, as it is likely to introduce instability (non-determinism). This PR identifies and fixes the targets that were calling system time without setting mock time at the start of an iteration. Removing`SetMockTime()` from any one of these targets should result in a crash and a message describing the issue. ACKs for top commit: achow101: ACKa96b84cb1bdergoegge: Code review ACKa96b84cb1bbrunoerg: crACKa96b84cb1bTree-SHA512: e093a9feb8a397954f7b1416dfa8790b2733f09d5ac51fda5a9d225a55ebd8f99135aa52bdf5ab531653ad1a3739c4ca2b5349c1d989bb4b009ec8eaad684f7d
This commit is contained in:
@@ -20,10 +20,14 @@
|
||||
void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread::sleep_for(n); }
|
||||
|
||||
static std::atomic<std::chrono::seconds> g_mock_time{}; //!< For testing
|
||||
std::atomic<bool> g_used_system_time{false};
|
||||
|
||||
NodeClock::time_point NodeClock::now() noexcept
|
||||
{
|
||||
const auto mocktime{g_mock_time.load(std::memory_order_relaxed)};
|
||||
if (!mocktime.count()) {
|
||||
g_used_system_time = true;
|
||||
}
|
||||
const auto ret{
|
||||
mocktime.count() ?
|
||||
mocktime :
|
||||
|
||||
Reference in New Issue
Block a user