From fafaca6cbc2fdabf95c286c9d8346e331a2de216 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Wed, 2 Apr 2025 18:11:18 +0200 Subject: [PATCH] fuzz: Avoid setting the mock-time twice It should be sufficient to set it once. Especially, if the dynamic value is only used by ResetAndInitialize. This also avoids non-determistic code paths, when ResetAndInitialize may re-initialize m_next_inv_to_inbounds. 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 ... - 1126| 3| m_next_inv_to_inbounds = now + m_rng.rand_exp_duration(average_interval); - 1127| 3| } + 1126| 10| m_next_inv_to_inbounds = now + m_rng.rand_exp_duration(average_interval); + 1127| 10| } 1128| 491| return m_next_inv_to_inbounds; ... --- src/test/fuzz/p2p_headers_presync.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/fuzz/p2p_headers_presync.cpp b/src/test/fuzz/p2p_headers_presync.cpp index 5358ebee330..93575877407 100644 --- a/src/test/fuzz/p2p_headers_presync.cpp +++ b/src/test/fuzz/p2p_headers_presync.cpp @@ -162,17 +162,15 @@ FUZZ_TARGET(p2p_headers_presync, .init = initialize) // 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; + CBlockHeader base{chainman.GetParams().GenesisBlock()}; + SetMockTime(base.nTime); LOCK(NetEventsInterface::g_msgproc_mutex); g_testing_setup->ResetAndInitialize(); - CBlockHeader base{chainman.GetParams().GenesisBlock()}; - SetMockTime(base.nTime); - // The chain is just a single block, so this is equal to 1 size_t original_index_size{WITH_LOCK(cs_main, return chainman.m_blockman.m_block_index.size())}; arith_uint256 total_work{WITH_LOCK(cs_main, return chainman.m_best_header->nChainWork)};