Skip to content

Commit 82de1bc

Browse files
committed
[net processing] Lazily initialize m_recent_confirmed_transactions
1 parent fa0c87f commit 82de1bc

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/net_processing.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,18 @@ class PeerManagerImpl final : public PeerManager
958958
* transaction per day that would be inadvertently ignored (which is the
959959
* same probability that we have in the reject filter).
960960
*/
961-
CRollingBloomFilter m_recent_confirmed_transactions GUARDED_BY(m_tx_download_mutex){48'000, 0.000'001};
961+
std::unique_ptr<CRollingBloomFilter> m_recent_confirmed_transactions GUARDED_BY(m_tx_download_mutex){nullptr};
962+
963+
CRollingBloomFilter& RecentConfirmedTransactionsFilter() EXCLUSIVE_LOCKS_REQUIRED(m_tx_download_mutex)
964+
{
965+
AssertLockHeld(m_tx_download_mutex);
966+
967+
if (!m_recent_confirmed_transactions) {
968+
m_recent_confirmed_transactions = std::make_unique<CRollingBloomFilter>(48'000, 0.000'001);
969+
}
970+
971+
return *m_recent_confirmed_transactions;
972+
}
962973

963974
/**
964975
* For sending `inv`s to inbound peers, we use a single (exponentially
@@ -2141,9 +2152,9 @@ void PeerManagerImpl::BlockConnected(
21412152
m_orphanage.EraseForBlock(*pblock);
21422153

21432154
for (const auto& ptx : pblock->vtx) {
2144-
m_recent_confirmed_transactions.insert(ptx->GetHash().ToUint256());
2155+
RecentConfirmedTransactionsFilter().insert(ptx->GetHash().ToUint256());
21452156
if (ptx->HasWitness()) {
2146-
m_recent_confirmed_transactions.insert(ptx->GetWitnessHash().ToUint256());
2157+
RecentConfirmedTransactionsFilter().insert(ptx->GetWitnessHash().ToUint256());
21472158
}
21482159
m_txrequest.ForgetTxHash(ptx->GetHash());
21492160
m_txrequest.ForgetTxHash(ptx->GetWitnessHash());
@@ -2161,7 +2172,7 @@ void PeerManagerImpl::BlockDisconnected(const std::shared_ptr<const CBlock> &blo
21612172
// presumably the most common case of relaying a confirmed transaction
21622173
// should be just after a new block containing it is found.
21632174
LOCK(m_tx_download_mutex);
2164-
m_recent_confirmed_transactions.reset();
2175+
RecentConfirmedTransactionsFilter().reset();
21652176
}
21662177

21672178
/**
@@ -2324,7 +2335,7 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid, bool include_reconside
23242335

23252336
if (include_reconsiderable && RecentRejectsReconsiderableFilter().contains(hash)) return true;
23262337

2327-
if (m_recent_confirmed_transactions.contains(hash)) return true;
2338+
if (RecentConfirmedTransactionsFilter().contains(hash)) return true;
23282339

23292340
return RecentRejectsFilter().contains(hash) || m_mempool.exists(gtxid);
23302341
}

0 commit comments

Comments
 (0)