Context:
Every time a block is connected, a BlockConnected() event is appended to the validation interface queue. This queue is consumed sequentially by a single worker thread. To avoid excessive memory usage, the queue is limited to 10 events at a time, and we stop processing new blocks until the queued events are handled.
Issue:
Within the PeerManager::BlockConnected() listener, we traverse the block twice inside the transaction download manager — despite not needing to handle orphans or transaction requests during IBD.
Extra info about the changes:
The new arg added to BlockConnected() in the first commit is primarily meant to avoid locking cs_main on the
listener side (to avoid calling IsInitialBlockDownload() there).
Another way of implementing this could be to add a bool field enabled to the TxDownloadManager class that is only
set to true when we are out of IBD, so that we don’t have to include a new arg inside the block connection event.
This is open for discussion. Could try implementing this second approach too.