@@ -897,7 +897,18 @@ class PeerManagerImpl final : public PeerManager
897
897
*
898
898
* Memory used: 1.3 MB
899
899
*/
900
- CRollingBloomFilter m_recent_rejects GUARDED_BY (m_tx_download_mutex){120'000 , 0.000'001 };
900
+ std::unique_ptr<CRollingBloomFilter> m_recent_rejects GUARDED_BY (m_tx_download_mutex){nullptr };
901
+
902
+ CRollingBloomFilter& RecentRejectsFilter () EXCLUSIVE_LOCKS_REQUIRED(m_tx_download_mutex)
903
+ {
904
+ AssertLockHeld (m_tx_download_mutex);
905
+
906
+ if (!m_recent_rejects) {
907
+ m_recent_rejects = std::make_unique<CRollingBloomFilter>(120'000 , 0.000'001 );
908
+ }
909
+
910
+ return *m_recent_rejects;
911
+ }
901
912
902
913
/* *
903
914
* Filter for:
@@ -2080,7 +2091,7 @@ void PeerManagerImpl::ActiveTipChange(const CBlockIndex& new_tip, bool is_ibd)
2080
2091
// If the chain tip has changed, previously rejected transactions might now be valid, e.g. due
2081
2092
// to a timelock. Reset the rejection filters to give those transactions another chance if we
2082
2093
// see them again.
2083
- m_recent_rejects .reset ();
2094
+ RecentRejectsFilter () .reset ();
2084
2095
m_recent_rejects_reconsiderable.reset ();
2085
2096
}
2086
2097
}
@@ -2304,7 +2315,7 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid, bool include_reconside
2304
2315
2305
2316
if (m_recent_confirmed_transactions.contains (hash)) return true ;
2306
2317
2307
- return m_recent_rejects .contains (hash) || m_mempool.exists (gtxid);
2318
+ return RecentRejectsFilter () .contains (hash) || m_mempool.exists (gtxid);
2308
2319
}
2309
2320
2310
2321
bool PeerManagerImpl::AlreadyHaveBlock (const uint256& block_hash)
@@ -3197,7 +3208,7 @@ void PeerManagerImpl::ProcessInvalidTx(NodeId nodeid, const CTransactionRef& ptx
3197
3208
// submit it as part of a package later.
3198
3209
m_recent_rejects_reconsiderable.insert (ptx->GetWitnessHash ().ToUint256 ());
3199
3210
} else {
3200
- m_recent_rejects .insert (ptx->GetWitnessHash ().ToUint256 ());
3211
+ RecentRejectsFilter () .insert (ptx->GetWitnessHash ().ToUint256 ());
3201
3212
}
3202
3213
m_txrequest.ForgetTxHash (ptx->GetWitnessHash ());
3203
3214
// If the transaction failed for TX_INPUTS_NOT_STANDARD,
@@ -3211,7 +3222,7 @@ void PeerManagerImpl::ProcessInvalidTx(NodeId nodeid, const CTransactionRef& ptx
3211
3222
// We only add the txid if it differs from the wtxid, to avoid wasting entries in the
3212
3223
// rolling bloom filter.
3213
3224
if (state.GetResult () == TxValidationResult::TX_INPUTS_NOT_STANDARD && ptx->HasWitness ()) {
3214
- m_recent_rejects .insert (ptx->GetHash ().ToUint256 ());
3225
+ RecentRejectsFilter () .insert (ptx->GetHash ().ToUint256 ());
3215
3226
m_txrequest.ForgetTxHash (ptx->GetHash ());
3216
3227
}
3217
3228
if (maybe_add_extra_compact_tx && RecursiveDynamicUsage (*ptx) < 100000 ) {
@@ -4609,7 +4620,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4609
4620
// submit 1p1c packages. However, fail immediately if any are in m_recent_rejects.
4610
4621
std::optional<uint256> rejected_parent_reconsiderable;
4611
4622
for (const uint256& parent_txid : unique_parents) {
4612
- if (m_recent_rejects .contains (parent_txid)) {
4623
+ if (RecentRejectsFilter () .contains (parent_txid)) {
4613
4624
fRejectedParents = true ;
4614
4625
break ;
4615
4626
} else if (m_recent_rejects_reconsiderable.contains (parent_txid) && !m_mempool.exists (GenTxid::Txid (parent_txid))) {
@@ -4658,8 +4669,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4658
4669
// regardless of what witness is provided, we will not accept
4659
4670
// this, so we don't need to allow for redownload of this txid
4660
4671
// from any of our non-wtxidrelay peers.
4661
- m_recent_rejects .insert (tx.GetHash ().ToUint256 ());
4662
- m_recent_rejects .insert (tx.GetWitnessHash ().ToUint256 ());
4672
+ RecentRejectsFilter () .insert (tx.GetHash ().ToUint256 ());
4673
+ RecentRejectsFilter () .insert (tx.GetWitnessHash ().ToUint256 ());
4663
4674
m_txrequest.ForgetTxHash (tx.GetHash ());
4664
4675
m_txrequest.ForgetTxHash (tx.GetWitnessHash ());
4665
4676
}
0 commit comments