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;
...
This commit is contained in:
MarcoFalke 2025-04-02 18:11:18 +02:00
parent fad22149f4
commit fafaca6cbc
No known key found for this signature in database

View file

@ -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)};