Skip to content

Commit eeac506

Browse files
committed
net_processing: move AlreadyHaveTx into PeerManageImpl
Allows making recentRejects and g_recent_confirmed_transactions members rather than globals.
1 parent 9781c08 commit eeac506

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/net_processing.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,9 @@ class PeerManagerImpl final : public PeerManager
362362

363363
/** Number of outbound peers with m_chain_sync.m_protect. */
364364
int m_outbound_peers_with_protect_from_disconnect GUARDED_BY(cs_main) = 0;
365-
};
366-
} // namespace
367365

368-
namespace {
366+
bool AlreadyHaveTx(const GenTxid& gtxid, const CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
367+
369368
/**
370369
* Filter for transactions that were recently rejected by
371370
* AcceptToMemoryPool. These are not rerequested until the chain tip
@@ -408,9 +407,12 @@ namespace {
408407
* We use this to avoid requesting transactions that have already been
409408
* confirnmed.
410409
*/
411-
Mutex g_cs_recent_confirmed_transactions;
412-
std::unique_ptr<CRollingBloomFilter> g_recent_confirmed_transactions GUARDED_BY(g_cs_recent_confirmed_transactions);
410+
Mutex m_recent_confirmed_transactions_mutex;
411+
std::unique_ptr<CRollingBloomFilter> m_recent_confirmed_transactions GUARDED_BY(m_recent_confirmed_transactions_mutex);
412+
};
413+
} // namespace
413414

415+
namespace {
414416
/** Blocks that are in flight, and that are in the queue to be downloaded. */
415417
struct QueuedBlock {
416418
uint256 hash;
@@ -1344,7 +1346,7 @@ PeerManagerImpl::PeerManagerImpl(const CChainParams& chainparams, CConnman& conn
13441346
// The false positive rate of 1/1M should come out to less than 1
13451347
// transaction per day that would be inadvertently ignored (which is the
13461348
// same probability that we have in the reject filter).
1347-
g_recent_confirmed_transactions.reset(new CRollingBloomFilter(48000, 0.000001));
1349+
m_recent_confirmed_transactions.reset(new CRollingBloomFilter(48000, 0.000001));
13481350

13491351
// Stale tip checking and peer eviction are on two different timers, but we
13501352
// don't want them to get out of sync due to drift in the scheduler, so we
@@ -1397,11 +1399,11 @@ void PeerManagerImpl::BlockConnected(const std::shared_ptr<const CBlock>& pblock
13971399
g_last_tip_update = GetTime();
13981400
}
13991401
{
1400-
LOCK(g_cs_recent_confirmed_transactions);
1402+
LOCK(m_recent_confirmed_transactions_mutex);
14011403
for (const auto& ptx : pblock->vtx) {
1402-
g_recent_confirmed_transactions->insert(ptx->GetHash());
1404+
m_recent_confirmed_transactions->insert(ptx->GetHash());
14031405
if (ptx->GetHash() != ptx->GetWitnessHash()) {
1404-
g_recent_confirmed_transactions->insert(ptx->GetWitnessHash());
1406+
m_recent_confirmed_transactions->insert(ptx->GetWitnessHash());
14051407
}
14061408
}
14071409
}
@@ -1424,8 +1426,8 @@ void PeerManagerImpl::BlockDisconnected(const std::shared_ptr<const CBlock> &blo
14241426
// block's worth of transactions in it, but that should be fine, since
14251427
// presumably the most common case of relaying a confirmed transaction
14261428
// should be just after a new block containing it is found.
1427-
LOCK(g_cs_recent_confirmed_transactions);
1428-
g_recent_confirmed_transactions->reset();
1429+
LOCK(m_recent_confirmed_transactions_mutex);
1430+
m_recent_confirmed_transactions->reset();
14291431
}
14301432

14311433
// All of the following cache a recent block, and are protected by cs_most_recent_block
@@ -1563,7 +1565,7 @@ void PeerManagerImpl::BlockChecked(const CBlock& block, const BlockValidationSta
15631565
//
15641566

15651567

1566-
bool static AlreadyHaveTx(const GenTxid& gtxid, const CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1568+
bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid, const CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
15671569
{
15681570
assert(recentRejects);
15691571
if (::ChainActive().Tip()->GetBlockHash() != hashRecentRejectsChainTip) {
@@ -1587,8 +1589,8 @@ bool static AlreadyHaveTx(const GenTxid& gtxid, const CTxMemPool& mempool) EXCLU
15871589
}
15881590

15891591
{
1590-
LOCK(g_cs_recent_confirmed_transactions);
1591-
if (g_recent_confirmed_transactions->contains(hash)) return true;
1592+
LOCK(m_recent_confirmed_transactions_mutex);
1593+
if (m_recent_confirmed_transactions->contains(hash)) return true;
15921594
}
15931595

15941596
return recentRejects->contains(hash) || mempool.exists(gtxid);

0 commit comments

Comments
 (0)