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_mutex
which guards the transaction download data structures includingm_txrequest
, the rolling bloom filters, andm_orphanage
. Later this should become the mutex guardingTxDownloadManager
.m_txrequest
doesn’t need to be guarded usingcs_main
anymorem_recent_confirmed_transactions
doesn’t need its own lock anymorem_orphanage
doesn’t need its own lock anymore
- Adds a new
ValidationInterface
event,ActiveTipChanged
, which is a synchronous callback whenever the tip of the active chainstate changes. - Flush
m_recent_rejects
andm_recent_rejects_reconsiderable
onActiveTipChanged
just once instead of checking the tip every timeAlreadyHaveTx
is called. This should speed up calls to that function (no longer comparing a block hash each time) and removes the need to lockcs_main
every 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_txrequest
is not also inm_orphanage
- a tx hash in
m_txrequest
is not also inm_recent_rejects
orm_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_main
is 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
AlreadyHaveTx
so 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.