aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2021-03-31 18:40:47 +0100
committerJohn Newbery <john@johnnewbery.com>2021-07-20 13:15:26 +0100
commitfde1bf4f6136638e84cdf9806eedaae08e841bbf (patch)
treee466562c1d7b004679aeaeca71f6312533b60d7f /src/net_processing.cpp
parent37dcd12d539e4a875581fa049aa0f7fafeb932a4 (diff)
downloadbitcoin-fde1bf4f6136638e84cdf9806eedaae08e841bbf.tar.xz
[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.
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 94ecbdf983..c418620859 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -477,9 +477,19 @@ private:
* Filter for transactions that have been recently confirmed.
* We use this to avoid requesting transactions that have already been
* confirnmed.
+ *
+ * Blocks don't typically have more than 4000 transactions, so this should
+ * be at least six blocks (~1 hr) worth of transactions that we can store,
+ * inserting both a txid and wtxid for every observed transaction.
+ * If the number of transactions appearing in a block goes up, or if we are
+ * seeing getdata requests more than an hour after initial announcement, we
+ * can increase this number.
+ * The false positive rate of 1/1M should come out to less than 1
+ * transaction per day that would be inadvertently ignored (which is the
+ * same probability that we have in the reject filter).
*/
Mutex m_recent_confirmed_transactions_mutex;
- std::unique_ptr<CRollingBloomFilter> m_recent_confirmed_transactions GUARDED_BY(m_recent_confirmed_transactions_mutex);
+ CRollingBloomFilter m_recent_confirmed_transactions GUARDED_BY(m_recent_confirmed_transactions_mutex){48'000, 0.000'001};
/** Have we requested this block from a peer */
bool IsBlockRequested(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@@ -1396,17 +1406,6 @@ PeerManagerImpl::PeerManagerImpl(const CChainParams& chainparams, CConnman& conn
m_mempool(pool),
m_ignore_incoming_txs(ignore_incoming_txs)
{
- // Blocks don't typically have more than 4000 transactions, so this should
- // be at least six blocks (~1 hr) worth of transactions that we can store,
- // inserting both a txid and wtxid for every observed transaction.
- // If the number of transactions appearing in a block goes up, or if we are
- // seeing getdata requests more than an hour after initial announcement, we
- // can increase this number.
- // The false positive rate of 1/1M should come out to less than 1
- // transaction per day that would be inadvertently ignored (which is the
- // same probability that we have in the reject filter).
- m_recent_confirmed_transactions.reset(new CRollingBloomFilter(48000, 0.000001));
-
// Stale tip checking and peer eviction are on two different timers, but we
// don't want them to get out of sync due to drift in the scheduler, so we
// 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
{
LOCK(m_recent_confirmed_transactions_mutex);
for (const auto& ptx : pblock->vtx) {
- m_recent_confirmed_transactions->insert(ptx->GetHash());
+ m_recent_confirmed_transactions.insert(ptx->GetHash());
if (ptx->GetHash() != ptx->GetWitnessHash()) {
- m_recent_confirmed_transactions->insert(ptx->GetWitnessHash());
+ m_recent_confirmed_transactions.insert(ptx->GetWitnessHash());
}
}
}
@@ -1458,7 +1457,7 @@ void PeerManagerImpl::BlockDisconnected(const std::shared_ptr<const CBlock> &blo
// presumably the most common case of relaying a confirmed transaction
// should be just after a new block containing it is found.
LOCK(m_recent_confirmed_transactions_mutex);
- m_recent_confirmed_transactions->reset();
+ m_recent_confirmed_transactions.reset();
}
// 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)
{
LOCK(m_recent_confirmed_transactions_mutex);
- if (m_recent_confirmed_transactions->contains(hash)) return true;
+ if (m_recent_confirmed_transactions.contains(hash)) return true;
}
return m_recent_rejects.contains(hash) || m_mempool.exists(gtxid);