DEBUG_LOCKORDER was reporting a false positive deadlock with the cmpctblock fuzz harness when using ImmediateTaskRunner. Since it is single-threaded, ImmediateTaskRunner callbacks added LockOrders that could never happen outside of a fuzz test.
First a block would get connected:
- LOCK(mempool.cs)
- BlockConnected (fuzz test runs in same thread)
- LOCK(m_tx_download_mutex)
Then a later iteration of the LIMITED_WHILE would send a TX:
- LOCK(m_tx_download_mutex)
- LOCK(mempool.cs)
causing a false positive deadlock. Normally, the BlockConnected callback would run in a different thread and no deadlock is reported.
Fix this by launching a thread that runs the callback and is immediately joined. I compared this PR to another branch (https://github.com/Crypt-iQ/bitcoin/commit/0028847c6b8b937031228e9a1fce83982976d86e) that uses a ThreadPool and found this PR to be more stable and ~4% quicker.