fuzz: let the test input toggle IBD in the p2p fuzz targets

process_message, process_messages and p2p_handshake put the node in
IBD via ResetIbd(), so net_processing returns early at the
IsInitialBlockDownload() check and almost never exercises the non-IBD
transaction-handling code paths behind it.

Only ConnectTip() latches the node back out, through
UpdateIBDStatus(). p2p_handshake connects no block, and in
process_message the single message is the whole iteration, so for
those two the non-IBD paths are out of reach entirely.
process_messages could reach them if one of its messages carried a
block building on the tip, but that is unlikely.

For process_message(s), leaving IBD used to be controllable from the
fuzz input via a jump_out_of_ibd bool that called JumpOutOfIbd().
Commit fa0a864b (#20908) dropped that toggle because mocktime made
it redundant: back then IsInitialBlockDownload() evaluated the tip
timestamp against the current mocked time on every call, so
SetMockTime(ConsumeTime(...)) alone could drive the node in and out
of IBD. That stopped working in #34253, which turned
IsInitialBlockDownload() into a lock-free read of the cached
m_cached_is_ibd flag, latched only by UpdateIBDStatus() on chain
activation; mocktime no longer affects it. p2p_handshake never had
such a toggle.

Restore the toggle. In process_message (a single message), the bool
is consumed last. In process_messages and p2p_handshake, the toggle
lives inside the message loop, as it did before fa0a864b. A latched
bool decides before each message whether to call JumpOutOfIbd(), so
some messages can be handled under IBD and the rest after leaving it.

Fixes: #34253
This commit is contained in:
Hao Xu
2026-06-12 19:30:21 +08:00
parent 2a29cee684
commit b11456386b
3 changed files with 20 additions and 3 deletions

View File

@@ -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())};
GetFakeNodeClock().set(1610000000s); // any time to successfully reset ibd
GetFakeNodeClock().set(1610000000s); // 2021-01-07, arbitrary
FakeSteadyClock steady_clock;
chainman.ResetIbd();
chainman.DisableNextWrite();
@@ -126,6 +126,10 @@ FUZZ_TARGET(process_message, .init = initialize_process_message)
connman.FlushSendBuffer(p2p_node);
(void)connman.ReceiveMsgFrom(p2p_node, std::move(net_msg));
if (fuzzed_data_provider.ConsumeBool()) {
chainman.JumpOutOfIbd();
}
bool more_work{true};
while (more_work) {
p2p_node.fPauseSend = false;