Skip to content

Commit b858b72

Browse files
committed
Merge bitcoin/bitcoin#31841: fuzz: Use immediate task runner to increase fuzz stability
fa4fb6a fuzz: Use serial task runner to increase fuzz stability (MarcoFalke) Pull request description: Leaking a scheduler with a non-empty queue from the fuzz initialization phase into the fuzz target execution phase is problematic, because it messes with coverage data. This in turn is problematic, because it leads to: * Decrease in fuzz target execution stability (non-determinism when running the fuzz target). * Decrease in fuzz input merge stability (non-determinism when selecting a minimum set of fuzz input to reach maximum coverage), which leads to qa-assets bloat. Fix one such issue. Tracking issue: bitcoin/bitcoin#29018 Can be tested via: `RUST_BACKTRACE=1 cargo run --manifest-path ./contrib/devtools/deterministic-fuzz-coverage/Cargo.toml -- $PWD/bld-cmake $PWD/../b-c-qa-assets/fuzz_corpora/ partially_downloaded_block`. The failure is non-deterministic (obviously) and will show coverage in validation signals such as `UpdatedBlockTip` before this change and will have this one fixed after this change. ACKs for top commit: marcofleon: ACK fa4fb6a dergoegge: Code review ACK fa4fb6a Tree-SHA512: fd1f66562c1d3c21553c7dd324399cdc16faa2fedfdb8e7544ea6a68b8b356e7c81d81815ecf70e0d334307dab6b275c1889b3b889b6f15eec514beee22c95f4
2 parents 998386d + fa4fb6a commit b858b72

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/test/util/setup_common.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <util/rbf.h>
5050
#include <util/strencodings.h>
5151
#include <util/string.h>
52+
#include <util/task_runner.h>
5253
#include <util/thread.h>
5354
#include <util/threadnames.h>
5455
#include <util/time.h>
@@ -220,12 +221,15 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, TestOpts opts)
220221
{
221222
const CChainParams& chainparams = Params();
222223

223-
// We have to run a scheduler thread to prevent ActivateBestChain
224+
// A task runner is required to prevent ActivateBestChain
224225
// from blocking due to queue overrun.
225226
if (opts.setup_validation_interface) {
226227
m_node.scheduler = std::make_unique<CScheduler>();
227228
m_node.scheduler->m_service_thread = std::thread(util::TraceThread, "scheduler", [&] { m_node.scheduler->serviceQueue(); });
228-
m_node.validation_signals = std::make_unique<ValidationSignals>(std::make_unique<SerialTaskRunner>(*m_node.scheduler));
229+
m_node.validation_signals =
230+
// Use synchronous task runner while fuzzing to avoid non-determinism
231+
G_FUZZING ? std::make_unique<ValidationSignals>(std::make_unique<util::ImmediateTaskRunner>()) :
232+
std::make_unique<ValidationSignals>(std::make_unique<SerialTaskRunner>(*m_node.scheduler));
229233
}
230234

231235
bilingual_str error{};

0 commit comments

Comments
 (0)