mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-02 09:15:04 +02:00
refactor: Use MockableSteadyClock in ReportHeadersPresync
This allows the clock to be mockable in tests. Also, replace cs_main
with GetMutex() while touching this function.
Also, use the ElapseSteady test helper in the p2p_headers_presync fuzz
target to make it more deterministic.
The m_last_presync_update variable is a global that is not reset in
ResetAndInitialize. However, it is only used for logging, so completely
disable it for now.
Without this patch, the tool would report a diff:
cargo run --manifest-path ./contrib/devtools/deterministic-fuzz-coverage/Cargo.toml -- $PWD/bld-cmake/ $PWD/../qa-assets/fuzz_corpora/ p2p_headers_presync 32
...
4468| 81| auto now = std::chrono::steady_clock::now();
4469| 81| if (now < m_last_presync_update + std::chrono::milliseconds{250}) return;
- ^80
+ ^79
...
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include <test/util/net.h>
|
||||
#include <test/util/script.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/time.h>
|
||||
#include <uint256.h>
|
||||
#include <validation.h>
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user