diff --git a/src/test/fuzz/p2p_headers_presync.cpp b/src/test/fuzz/p2p_headers_presync.cpp index 43e6493ae35..5358ebee330 100644 --- a/src/test/fuzz/p2p_headers_presync.cpp +++ b/src/test/fuzz/p2p_headers_presync.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -158,6 +159,9 @@ FUZZ_TARGET(p2p_headers_presync, .init = initialize) { SeedRandomStateForTest(SeedRand::ZEROS); FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; + // The steady clock is currently only used for logging, so a constant + // time-point seems acceptable for now. + ElapseSteady elapse_steady{}; SetMockTime(ConsumeTime(fuzzed_data_provider)); ChainstateManager& chainman = *g_testing_setup->m_node.chainman; diff --git a/src/validation.cpp b/src/validation.cpp index fedcb9ca57f..aa1effb736f 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4456,16 +4456,16 @@ bool ChainstateManager::ProcessNewBlockHeaders(std::span hea void ChainstateManager::ReportHeadersPresync(const arith_uint256& work, int64_t height, int64_t timestamp) { - AssertLockNotHeld(cs_main); + AssertLockNotHeld(GetMutex()); { - LOCK(cs_main); + LOCK(GetMutex()); // Don't report headers presync progress if we already have a post-minchainwork header chain. // This means we lose reporting for potentially legitimate, but unlikely, deep reorgs, but // prevent attackers that spam low-work headers from filling our logs. if (m_best_header->nChainWork >= UintToArith256(GetConsensus().nMinimumChainWork)) return; // Rate limit headers presync updates to 4 per second, as these are not subject to DoS // protection. - auto now = std::chrono::steady_clock::now(); + auto now = MockableSteadyClock::now(); if (now < m_last_presync_update + std::chrono::milliseconds{250}) return; m_last_presync_update = now; } diff --git a/src/validation.h b/src/validation.h index f6cbee28fc5..e361c7af101 100644 --- a/src/validation.h +++ b/src/validation.h @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2022 The Bitcoin Core developers +// Copyright (c) 2009-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -933,7 +933,7 @@ private: friend Chainstate; /** Most recent headers presync progress update, for rate-limiting. */ - std::chrono::time_point m_last_presync_update GUARDED_BY(::cs_main) {}; + MockableSteadyClock::time_point m_last_presync_update GUARDED_BY(GetMutex()){}; std::array m_warningcache GUARDED_BY(::cs_main);