mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
[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.
This commit is contained in:
parent
37dcd12d53
commit
fde1bf4f61
1 changed files with 15 additions and 16 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue