See #27463 for full project tracking.
This contains the first few commits of #30110, which require some thinking about thread safety in review.
- Introduce a new m_tx_download_mutexwhich guards the transaction download data structures includingm_txrequest, the rolling bloom filters, andm_orphanage. Later this should become the mutex guardingTxDownloadManager.- m_txrequestdoesn’t need to be guarded using- cs_mainanymore
- m_recent_confirmed_transactionsdoesn’t need its own lock anymore
- m_orphanagedoesn’t need its own lock anymore
 
- Adds a new ValidationInterfaceevent,ActiveTipChanged, which is a synchronous callback whenever the tip of the active chainstate changes.
- Flush m_recent_rejectsandm_recent_rejects_reconsiderableonActiveTipChangedjust once instead of checking the tip every timeAlreadyHaveTxis called. This should speed up calls to that function (no longer comparing a block hash each time) and removes the need to lockcs_mainevery time it is called.
Motivation:
- These data structures need synchronization. While we are holding m_tx_download_mutex, these should hold:- a tx hash in m_txrequestis not also inm_orphanage
- a tx hash in m_txrequestis not also inm_recent_rejectsorm_recent_confirmed_transactions
- In the future, orphan resolution tracking should also be synchronized. If a tx has an entry in the orphan resolution tracker, it is also in m_orphanage, and not inm_txrequest, etc.
 
- a tx hash in 
- Currently, cs_mainis used to e.g. sync accesses tom_txrequest. We should not broaden the scope of things it locks.
- Currently, we need to know the current chainstate every time we call AlreadyHaveTxso we can decide whether we should update it. Every call compares the current tip hash withhashRecentRejectsChainTip. It is more efficient to have a validation interface callback that updates the rejection filters whenever the chain tip changes.