Skip to content

Commit fde1bf4

Browse files
committed
[net processing] Default initialize m_recent_confirmed_transactions
Now that m_recent_confirmed_transactions is owned by PeerManagerImpl, and PeerManagerImpl's lifetime is managed by the node context, we can just default initialize m_recent_confirmed_transactions during object initialization. We can also remove the unique_ptr indirection.
1 parent 37dcd12 commit fde1bf4

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/net_processing.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,19 @@ class PeerManagerImpl final : public PeerManager
477477
* Filter for transactions that have been recently confirmed.
478478
* We use this to avoid requesting transactions that have already been
479479
* confirnmed.
480+
*
481+
* Blocks don't typically have more than 4000 transactions, so this should
482+
* be at least six blocks (~1 hr) worth of transactions that we can store,
483+
* inserting both a txid and wtxid for every observed transaction.
484+
* If the number of transactions appearing in a block goes up, or if we are
485+
* seeing getdata requests more than an hour after initial announcement, we
486+
* can increase this number.
487+
* The false positive rate of 1/1M should come out to less than 1
488+
* transaction per day that would be inadvertently ignored (which is the
489+
* same probability that we have in the reject filter).
480490
*/
481491
Mutex m_recent_confirmed_transactions_mutex;
482-
std::unique_ptr<CRollingBloomFilter> m_recent_confirmed_transactions GUARDED_BY(m_recent_confirmed_transactions_mutex);
492+
CRollingBloomFilter m_recent_confirmed_transactions GUARDED_BY(m_recent_confirmed_transactions_mutex){48'000, 0.000'001};
483493

484494
/** Have we requested this block from a peer */
485495
bool IsBlockRequested(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@@ -1396,17 +1406,6 @@ PeerManagerImpl::PeerManagerImpl(const CChainParams& chainparams, CConnman& conn
13961406
m_mempool(pool),
13971407
m_ignore_incoming_txs(ignore_incoming_txs)
13981408
{
1399-
// Blocks don't typically have more than 4000 transactions, so this should
1400-
// be at least six blocks (~1 hr) worth of transactions that we can store,
1401-
// inserting both a txid and wtxid for every observed transaction.
1402-
// If the number of transactions appearing in a block goes up, or if we are
1403-
// seeing getdata requests more than an hour after initial announcement, we
1404-
// can increase this number.
1405-
// The false positive rate of 1/1M should come out to less than 1
1406-
// transaction per day that would be inadvertently ignored (which is the
1407-
// same probability that we have in the reject filter).
1408-
m_recent_confirmed_transactions.reset(new CRollingBloomFilter(48000, 0.000001));
1409-
14101409
// Stale tip checking and peer eviction are on two different timers, but we
14111410
// don't want them to get out of sync due to drift in the scheduler, so we
14121411
// combine them in one function and schedule at the quicker (peer-eviction)
@@ -1432,9 +1431,9 @@ void PeerManagerImpl::BlockConnected(const std::shared_ptr<const CBlock>& pblock
14321431
{
14331432
LOCK(m_recent_confirmed_transactions_mutex);
14341433
for (const auto& ptx : pblock->vtx) {
1435-
m_recent_confirmed_transactions->insert(ptx->GetHash());
1434+
m_recent_confirmed_transactions.insert(ptx->GetHash());
14361435
if (ptx->GetHash() != ptx->GetWitnessHash()) {
1437-
m_recent_confirmed_transactions->insert(ptx->GetWitnessHash());
1436+
m_recent_confirmed_transactions.insert(ptx->GetWitnessHash());
14381437
}
14391438
}
14401439
}
@@ -1458,7 +1457,7 @@ void PeerManagerImpl::BlockDisconnected(const std::shared_ptr<const CBlock> &blo
14581457
// presumably the most common case of relaying a confirmed transaction
14591458
// should be just after a new block containing it is found.
14601459
LOCK(m_recent_confirmed_transactions_mutex);
1461-
m_recent_confirmed_transactions->reset();
1460+
m_recent_confirmed_transactions.reset();
14621461
}
14631462

14641463
// All of the following cache a recent block, and are protected by cs_most_recent_block
@@ -1613,7 +1612,7 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid)
16131612

16141613
{
16151614
LOCK(m_recent_confirmed_transactions_mutex);
1616-
if (m_recent_confirmed_transactions->contains(hash)) return true;
1615+
if (m_recent_confirmed_transactions.contains(hash)) return true;
16171616
}
16181617

16191618
return m_recent_rejects.contains(hash) || m_mempool.exists(gtxid);

0 commit comments

Comments
 (0)