Skip to content

Commit 135e05c

Browse files
committed
Merge bitcoin/bitcoin#36046: fuzz: Use ImmediateBackgroundTaskRunner in process_messages
fae6665 fuzz: Use ImmediateBackgroundTaskRunner in process_messages (MarcoFalke) Pull request description: The `process_messages` target may complain about false-positive debug lock-order issues: ``` echo 'Gv8uXPBdXV0QEP//dHVhxyoVKP////8A/0BrLmNrAEEAIP+MXHR0OQAAAAD+///txgIUADBgAAEC fgAAAK0ArQEAAAD/AFwAQf9cdHf5XGhlYWRlcltbyzHIw8RcX2Jsb2NrAAAAAGNtcAAAADAftOvd D0sFqXEx6US5VIknlsOJqZ5goMwtmwZBPdCxQZbatBsWPOR3FcUvSLLsKwcgKT8XdmjvDgskH5pK iAUI/uVJTf//fyAAAAAAAQIAAAAAAQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP// //8DAskA/v///wIA+QKVAAAAAAFRAAAAAAAAAAAmaiSqIant4vYcP3HR3v0/qZnfo2lTdVxcaQaJ eZlitIvr2DaXToz5ASAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMgAAAD/XPB0eAD/ AgAAAAD9ABZqCwAAAAAEAAAAXPBhYVtbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tb W1tb//9bW1tbW1tbW1sAAAAxNgAAADc5MzU5NDk2ODEwNzg3NAAAAAICAgL9a4jAhyQCAgICAQAA AAAABSpvdGhlcir/8wICAgICAAAAeAL0AAAAAAAAaW52O///BAAAAAAAtbW1tWFbW2FhtbVhYWFh YSkpW1tbW2QAJwAAAAAAAAAAMTYAAAA3OTM1OTQ5NjgxMDc4NzQAAAACAgIC/WuIwIckAgICAgEA AAAAAAUAAAAAAv7///MAeAL0AAAAAAAAaW52Ow==' | base64 --decode > /tmp/fuzz.input FUZZ=process_messages ./bld-cmake/bin/fuzz /tmp/fuzz.input --printtoconsole=1 | grep -A99 'POTENTIAL DEADLOCK DETECTED' ``` ``` [test] [sync.cpp:108] [potential_deadlock_detected] [error] POTENTIAL DEADLOCK DETECTED [test] [sync.cpp:109] [potential_deadlock_detected] [error] Previous lock order was: [test] [sync.cpp:118] [potential_deadlock_detected] [error] 'NetEventsInterface::g_msgproc_mutex' in test/fuzz/process_messages.cpp:89 (in thread 'test') [test] [sync.cpp:118] [potential_deadlock_detected] [error] 'm_chainstate_mutex' in validation.cpp:3351 (in thread 'test') [test] [sync.cpp:118] [potential_deadlock_detected] [error] 'cs_main' in validation.cpp:3373 (in thread 'test') [test] [sync.cpp:118] [potential_deadlock_detected] [error] (2) 'MempoolMutex()' in validation.cpp:3376 (in thread 'test') [test] [sync.cpp:118] [potential_deadlock_detected] [error] (1) 'm_tx_download_mutex' in net_processing.cpp:2216 (in thread 'test') [test] [sync.cpp:122] [potential_deadlock_detected] [error] Current lock order is: [test] [sync.cpp:133] [potential_deadlock_detected] [error] 'NetEventsInterface::g_msgproc_mutex' in test/fuzz/process_messages.cpp:89 (in thread 'test') [test] [sync.cpp:133] [potential_deadlock_detected] [error] 'cs_main' in net_processing.cpp:4725 (in thread 'test') [test] [sync.cpp:133] [potential_deadlock_detected] [error] (1) 'm_tx_download_mutex' in net_processing.cpp:4725 (in thread 'test') [test] [sync.cpp:133] [potential_deadlock_detected] [error] (2) 'cs' in txmempool.h:521 (in thread 'test') ``` Fix this by using the `ImmediateBackgroundTaskRunner` from `src/test/fuzz/cmpctblock.cpp`. ACKs for top commit: Crypt-iQ: ACK fae6665 sedited: ACK fae6665 marcofleon: tACK fae6665 frankomosh: Tested ACK fae6665 Tree-SHA512: 9cee43aa72495abfd69211004b27ee6857d3a1a6bbab9fdc5a8b5349159a54e270236f198a516a7d9087917af8c95ee626e8307155ded8d08314a6b606dd0c33
2 parents 994c17d + fae6665 commit 135e05c

3 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/test/fuzz/cmpctblock.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <txmempool.h>
3535
#include <uint256.h>
3636
#include <util/check.h>
37-
#include <util/task_runner.h>
3837
#include <util/time.h>
3938
#include <validation.h>
4039
#include <validationinterface.h>
@@ -48,7 +47,6 @@
4847
#include <memory>
4948
#include <optional>
5049
#include <string>
51-
#include <thread>
5250
#include <utility>
5351
#include <vector>
5452

@@ -104,15 +102,6 @@ class FuzzedCBlockHeaderAndShortTxIDs : public CBlockHeaderAndShortTxIDs
104102
};
105103

106104

107-
//! Used to run tasks in a std::thread to avoid DEBUG_LOCKORDER false positives.
108-
class ImmediateBackgroundTaskRunner : public util::TaskRunnerInterface
109-
{
110-
public:
111-
void insert(std::function<void()> func) override { std::thread(std::move(func)).join(); }
112-
void flush() override {}
113-
size_t size() override { return 0; }
114-
};
115-
116105
} // namespace
117106

118107
extern void MakeRandDeterministicDANGEROUS(const uint256& seed) noexcept;

src/test/fuzz/process_messages.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ void initialize_process_messages()
5050
{}),
5151
};
5252
g_setup = testing_setup.get();
53+
// Replace validation_signals before creating chainman and mempool so they use it.
54+
g_setup->m_node.validation_signals = std::make_unique<ValidationSignals>(std::make_unique<ImmediateBackgroundTaskRunner>());
5355
ResetChainmanAndMempool(*g_setup, init_clock);
5456
}
5557

src/test/util/validation.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
#include <consensus/amount.h>
99
#include <primitives/transaction.h>
10+
#include <util/task_runner.h>
1011
#include <validation.h>
1112

13+
#include <cstddef>
14+
#include <functional>
15+
#include <thread>
1216
#include <utility>
1317
#include <vector>
1418

@@ -19,6 +23,15 @@ class CValidationInterface;
1923
class FakeNodeClock;
2024
struct TestingSetup;
2125

26+
/// Runs callbacks synchronously and deterministically, while avoiding DEBUG_LOCKORDER false positives.
27+
class ImmediateBackgroundTaskRunner : public util::TaskRunnerInterface
28+
{
29+
public:
30+
void insert(std::function<void()> func) override { std::thread(std::move(func)).join(); }
31+
void flush() override {}
32+
size_t size() override { return 0; }
33+
};
34+
2235
struct TestBlockManager : public node::BlockManager {
2336
/** Test-only method to clear internal state for fuzzing */
2437
void CleanupForFuzzing();

0 commit comments

Comments
 (0)