@@ -930,7 +930,18 @@ class PeerManagerImpl final : public PeerManager
930
930
*
931
931
* Parameters are picked to be the same as m_recent_rejects, with the same rationale.
932
932
*/
933
- CRollingBloomFilter m_recent_rejects_reconsiderable GUARDED_BY (m_tx_download_mutex){120'000 , 0.000'001 };
933
+ std::unique_ptr<CRollingBloomFilter> m_recent_rejects_reconsiderable GUARDED_BY (m_tx_download_mutex){nullptr };
934
+
935
+ CRollingBloomFilter& RecentRejectsReconsiderableFilter () EXCLUSIVE_LOCKS_REQUIRED(m_tx_download_mutex)
936
+ {
937
+ AssertLockHeld (m_tx_download_mutex);
938
+
939
+ if (!m_recent_rejects_reconsiderable) {
940
+ m_recent_rejects_reconsiderable = std::make_unique<CRollingBloomFilter>(120'000 , 0.000'001 );
941
+ }
942
+
943
+ return *m_recent_rejects_reconsiderable;
944
+ }
934
945
935
946
/*
936
947
* Filter for transactions that have been recently confirmed.
@@ -2092,7 +2103,7 @@ void PeerManagerImpl::ActiveTipChange(const CBlockIndex& new_tip, bool is_ibd)
2092
2103
// to a timelock. Reset the rejection filters to give those transactions another chance if we
2093
2104
// see them again.
2094
2105
RecentRejectsFilter ().reset ();
2095
- m_recent_rejects_reconsiderable .reset ();
2106
+ RecentRejectsReconsiderableFilter () .reset ();
2096
2107
}
2097
2108
}
2098
2109
@@ -2311,7 +2322,7 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid, bool include_reconside
2311
2322
if (m_orphanage.HaveTx (Wtxid::FromUint256 (hash))) return true ;
2312
2323
}
2313
2324
2314
- if (include_reconsiderable && m_recent_rejects_reconsiderable .contains (hash)) return true ;
2325
+ if (include_reconsiderable && RecentRejectsReconsiderableFilter () .contains (hash)) return true ;
2315
2326
2316
2327
if (m_recent_confirmed_transactions.contains (hash)) return true ;
2317
2328
@@ -3206,7 +3217,7 @@ void PeerManagerImpl::ProcessInvalidTx(NodeId nodeid, const CTransactionRef& ptx
3206
3217
// If the result is TX_RECONSIDERABLE, add it to m_recent_rejects_reconsiderable
3207
3218
// because we should not download or submit this transaction by itself again, but may
3208
3219
// submit it as part of a package later.
3209
- m_recent_rejects_reconsiderable .insert (ptx->GetWitnessHash ().ToUint256 ());
3220
+ RecentRejectsReconsiderableFilter () .insert (ptx->GetWitnessHash ().ToUint256 ());
3210
3221
} else {
3211
3222
RecentRejectsFilter ().insert (ptx->GetWitnessHash ().ToUint256 ());
3212
3223
}
@@ -3277,7 +3288,7 @@ void PeerManagerImpl::ProcessPackageResult(const PackageToValidate& package_to_v
3277
3288
const auto & senders = package_to_validate.m_senders ;
3278
3289
3279
3290
if (package_result.m_state .IsInvalid ()) {
3280
- m_recent_rejects_reconsiderable .insert (GetPackageHash (package));
3291
+ RecentRejectsReconsiderableFilter () .insert (GetPackageHash (package));
3281
3292
}
3282
3293
// We currently only expect to process 1-parent-1-child packages. Remove if this changes.
3283
3294
if (!Assume (package.size () == 2 )) return ;
@@ -3331,7 +3342,7 @@ std::optional<PeerManagerImpl::PackageToValidate> PeerManagerImpl::Find1P1CPacka
3331
3342
3332
3343
const auto & parent_wtxid{ptx->GetWitnessHash ()};
3333
3344
3334
- Assume (m_recent_rejects_reconsiderable .contains (parent_wtxid.ToUint256 ()));
3345
+ Assume (RecentRejectsReconsiderableFilter () .contains (parent_wtxid.ToUint256 ()));
3335
3346
3336
3347
// Prefer children from this peer. This helps prevent censorship attempts in which an attacker
3337
3348
// sends lots of fake children for the parent, and we (unluckily) keep selecting the fake
@@ -3343,7 +3354,7 @@ std::optional<PeerManagerImpl::PackageToValidate> PeerManagerImpl::Find1P1CPacka
3343
3354
// most recent) one efficiently.
3344
3355
for (const auto & child : cpfp_candidates_same_peer) {
3345
3356
Package maybe_cpfp_package{ptx, child};
3346
- if (!m_recent_rejects_reconsiderable .contains (GetPackageHash (maybe_cpfp_package))) {
3357
+ if (!RecentRejectsReconsiderableFilter () .contains (GetPackageHash (maybe_cpfp_package))) {
3347
3358
return PeerManagerImpl::PackageToValidate{ptx, child, nodeid, nodeid};
3348
3359
}
3349
3360
}
@@ -3370,7 +3381,7 @@ std::optional<PeerManagerImpl::PackageToValidate> PeerManagerImpl::Find1P1CPacka
3370
3381
// cached in m_recent_rejects_reconsiderable.
3371
3382
const auto [child_tx, child_sender] = cpfp_candidates_different_peer.at (index);
3372
3383
Package maybe_cpfp_package{ptx, child_tx};
3373
- if (!m_recent_rejects_reconsiderable .contains (GetPackageHash (maybe_cpfp_package))) {
3384
+ if (!RecentRejectsReconsiderableFilter () .contains (GetPackageHash (maybe_cpfp_package))) {
3374
3385
return PeerManagerImpl::PackageToValidate{ptx, child_tx, nodeid, child_sender};
3375
3386
}
3376
3387
}
@@ -4562,7 +4573,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4562
4573
}
4563
4574
}
4564
4575
4565
- if (m_recent_rejects_reconsiderable .contains (wtxid)) {
4576
+ if (RecentRejectsReconsiderableFilter () .contains (wtxid)) {
4566
4577
// When a transaction is already in m_recent_rejects_reconsiderable, we shouldn't submit
4567
4578
// it by itself again. However, look for a matching child in the orphanage, as it is
4568
4579
// possible that they succeed as a package.
@@ -4623,7 +4634,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4623
4634
if (RecentRejectsFilter ().contains (parent_txid)) {
4624
4635
fRejectedParents = true ;
4625
4636
break ;
4626
- } else if (m_recent_rejects_reconsiderable .contains (parent_txid) && !m_mempool.exists (GenTxid::Txid (parent_txid))) {
4637
+ } else if (RecentRejectsReconsiderableFilter () .contains (parent_txid) && !m_mempool.exists (GenTxid::Txid (parent_txid))) {
4627
4638
// More than 1 parent in m_recent_rejects_reconsiderable: 1p1c will not be
4628
4639
// sufficient to accept this package, so just give up here.
4629
4640
if (rejected_parent_reconsiderable.has_value ()) {
0 commit comments