mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-12 05:32:22 +02:00
fuzz: share a single FakeNodeClock in the chainman-resetting fuzz targets
cmpctblock, process_message, process_messages, and utxo_snapshot rebuild
the chainman from a helper called out of the target body, while the
body itself holds or mutates mocktime through a FakeNodeClock. Since
FakeNodeClock is a LimitOne type, the helper cannot hold one of its
own and reaches for the SetMockTime() global mutator instead, so it is
unclear which of the two owns mocktime.
Add a GetFakeNodeClock() that returns a single process-wide
FakeNodeClock and route these targets through it, replacing their
local FakeNodeClock and genesis-time SetMockTime() calls.
It is initialized with 0s rather than a default-constructed
FakeNodeClock{}, which would read mocktime at whatever point the
static happens to be constructed. Every user sets the time before use
anyway.
This commit is contained in:
@@ -46,7 +46,7 @@ std::string_view LIMIT_TO_MESSAGE_TYPE{};
|
||||
|
||||
void ResetChainman(TestingSetup& setup)
|
||||
{
|
||||
SetMockTime(setup.m_node.chainman->GetParams().GenesisBlock().Time());
|
||||
GetFakeNodeClock().set(setup.m_node.chainman->GetParams().GenesisBlock().Time());
|
||||
setup.m_node.chainman.reset();
|
||||
setup.m_make_chainman();
|
||||
setup.LoadVerifyActivateChainstate();
|
||||
@@ -83,7 +83,7 @@ FUZZ_TARGET(process_message, .init = initialize_process_message)
|
||||
connman.Reset();
|
||||
auto& chainman{static_cast<TestChainstateManager&>(*node.chainman)};
|
||||
const auto block_index_size{WITH_LOCK(chainman.GetMutex(), return chainman.BlockIndex().size())};
|
||||
FakeNodeClock clock{1610000000s}; // any time to successfully reset ibd
|
||||
GetFakeNodeClock().set(1610000000s); // any time to successfully reset ibd
|
||||
FakeSteadyClock steady_clock;
|
||||
chainman.ResetIbd();
|
||||
chainman.DisableNextWrite();
|
||||
@@ -117,7 +117,7 @@ FUZZ_TARGET(process_message, .init = initialize_process_message)
|
||||
connman.AddTestNode(p2p_node);
|
||||
FillNode(fuzzed_data_provider, connman, p2p_node);
|
||||
|
||||
clock.set(ConsumeTime(fuzzed_data_provider));
|
||||
GetFakeNodeClock().set(ConsumeTime(fuzzed_data_provider));
|
||||
|
||||
CSerializedNetMsg net_msg;
|
||||
net_msg.m_type = random_message_type;
|
||||
|
||||
Reference in New Issue
Block a user