@@ -318,7 +318,8 @@ class PeerManagerImpl final : public PeerManager
318
318
/* * The height of the best chain */
319
319
std::atomic<int > m_best_height{-1 };
320
320
321
- int64_t m_stale_tip_check_time; // !< Next time to check for stale tip
321
+ /* * Next time to check for stale tip */
322
+ int64_t m_stale_tip_check_time{0 };
322
323
323
324
/* * Whether this node is running in blocks only mode */
324
325
const bool m_ignore_incoming_txs;
@@ -443,16 +444,26 @@ class PeerManagerImpl final : public PeerManager
443
444
*
444
445
* Memory used: 1.3MB
445
446
*/
446
- std::unique_ptr< CRollingBloomFilter> recentRejects GUARDED_BY (cs_main);
447
+ CRollingBloomFilter m_recent_rejects GUARDED_BY (:: cs_main){ 120'000 , 0.000'001 } ;
447
448
uint256 hashRecentRejectsChainTip GUARDED_BY (cs_main);
448
449
449
450
/*
450
451
* Filter for transactions that have been recently confirmed.
451
452
* We use this to avoid requesting transactions that have already been
452
453
* confirnmed.
454
+ *
455
+ * Blocks don't typically have more than 4000 transactions, so this should
456
+ * be at least six blocks (~1 hr) worth of transactions that we can store,
457
+ * inserting both a txid and wtxid for every observed transaction.
458
+ * If the number of transactions appearing in a block goes up, or if we are
459
+ * seeing getdata requests more than an hour after initial announcement, we
460
+ * can increase this number.
461
+ * The false positive rate of 1/1M should come out to less than 1
462
+ * transaction per day that would be inadvertently ignored (which is the
463
+ * same probability that we have in the reject filter).
453
464
*/
454
465
Mutex m_recent_confirmed_transactions_mutex;
455
- std::unique_ptr< CRollingBloomFilter> m_recent_confirmed_transactions GUARDED_BY (m_recent_confirmed_transactions_mutex);
466
+ CRollingBloomFilter m_recent_confirmed_transactions GUARDED_BY (m_recent_confirmed_transactions_mutex){ 48'000 , 0.000'001 } ;
456
467
457
468
/* Returns a bool indicating whether we requested this block.
458
469
* Also used if a block was /not/ received and timed out or started with another peer
@@ -1567,23 +1578,9 @@ PeerManagerImpl::PeerManagerImpl(const CChainParams& chainparams, CConnman& conn
1567
1578
m_cj_ctx(cj_ctx),
1568
1579
m_llmq_ctx(llmq_ctx),
1569
1580
m_govman(govman),
1570
- m_stale_tip_check_time(0 ),
1571
1581
m_ignore_incoming_txs(ignore_incoming_txs)
1572
1582
{
1573
1583
assert (std::addressof (g_chainman) == std::addressof (m_chainman));
1574
- // Initialize global variables that cannot be constructed at startup.
1575
- recentRejects.reset (new CRollingBloomFilter (120000 , 0.000001 ));
1576
-
1577
- // Blocks don't typically have more than 4000 transactions, so this should
1578
- // be at least six blocks (~1 hr) worth of transactions that we can store.
1579
- // If the number of transactions appearing in a block goes up, or if we are
1580
- // seeing getdata requests more than an hour after initial announcement, we
1581
- // can increase this number.
1582
- // The false positive rate of 1/1M should come out to less than 1
1583
- // transaction per day that would be inadvertently ignored (which is the
1584
- // same probability that we have in the reject filter).
1585
- m_recent_confirmed_transactions.reset (new CRollingBloomFilter (24000 , 0.000001 ));
1586
-
1587
1584
const Consensus::Params& consensusParams = Params ().GetConsensus ();
1588
1585
// Stale tip checking and peer eviction are on two different timers, but we
1589
1586
// don't want them to get out of sync due to drift in the scheduler, so we
@@ -1652,7 +1649,7 @@ void PeerManagerImpl::BlockConnected(const std::shared_ptr<const CBlock>& pblock
1652
1649
{
1653
1650
LOCK (m_recent_confirmed_transactions_mutex);
1654
1651
for (const auto & ptx : pblock->vtx ) {
1655
- m_recent_confirmed_transactions-> insert (ptx->GetHash ());
1652
+ m_recent_confirmed_transactions. insert (ptx->GetHash ());
1656
1653
}
1657
1654
}
1658
1655
}
@@ -1668,7 +1665,7 @@ void PeerManagerImpl::BlockDisconnected(const std::shared_ptr<const CBlock> &blo
1668
1665
// presumably the most common case of relaying a confirmed transaction
1669
1666
// should be just after a new block containing it is found.
1670
1667
LOCK (m_recent_confirmed_transactions_mutex);
1671
- m_recent_confirmed_transactions-> reset ();
1668
+ m_recent_confirmed_transactions. reset ();
1672
1669
}
1673
1670
1674
1671
// All of the following cache a recent block, and are protected by cs_most_recent_block
@@ -1805,15 +1802,14 @@ bool PeerManagerImpl::AlreadyHave(const CInv& inv)
1805
1802
case MSG_TX:
1806
1803
case MSG_DSTX:
1807
1804
{
1808
- assert (recentRejects);
1809
1805
if (m_chainman.ActiveChain ().Tip ()->GetBlockHash () != hashRecentRejectsChainTip)
1810
1806
{
1811
1807
// If the chain tip has changed previously rejected transactions
1812
1808
// might be now valid, e.g. due to a nLockTime'd tx becoming valid,
1813
1809
// or a double-spend. Reset the rejects filter and give those
1814
1810
// txs a second chance.
1815
1811
hashRecentRejectsChainTip = m_chainman.ActiveChain ().Tip ()->GetBlockHash ();
1816
- recentRejects-> reset ();
1812
+ m_recent_rejects. reset ();
1817
1813
}
1818
1814
1819
1815
{
@@ -1823,15 +1819,15 @@ bool PeerManagerImpl::AlreadyHave(const CInv& inv)
1823
1819
1824
1820
{
1825
1821
LOCK (m_recent_confirmed_transactions_mutex);
1826
- if (m_recent_confirmed_transactions-> contains (inv.hash )) return true ;
1822
+ if (m_recent_confirmed_transactions. contains (inv.hash )) return true ;
1827
1823
}
1828
1824
1829
1825
// When we receive an islock for a previously rejected transaction, we have to
1830
1826
// drop the first-seen tx (which such a locked transaction was conflicting with)
1831
1827
// and re-request the locked transaction (which did not make it into the mempool
1832
1828
// previously due to txn-mempool-conflict rule). This means that we must ignore
1833
- // recentRejects filter for such locked txes here.
1834
- // We also ignore recentRejects filter for DSTX-es because a malicious peer might
1829
+ // m_recent_rejects filter for such locked txes here.
1830
+ // We also ignore m_recent_rejects filter for DSTX-es because a malicious peer might
1835
1831
// relay a valid DSTX as a regular TX first which would skip all the specific checks
1836
1832
// but would cause such tx to be rejected by ATMP due to 0 fee. Ignoring it here
1837
1833
// should let DSTX to be propagated by honest peer later. Note, that a malicious
@@ -1842,7 +1838,7 @@ bool PeerManagerImpl::AlreadyHave(const CInv& inv)
1842
1838
m_llmq_ctx->isman ->IsWaitingForTx (inv.hash ) ||
1843
1839
m_llmq_ctx->isman ->IsLocked (inv.hash );
1844
1840
1845
- return (!fIgnoreRecentRejects && recentRejects-> contains (inv.hash )) ||
1841
+ return (!fIgnoreRecentRejects && m_recent_rejects. contains (inv.hash )) ||
1846
1842
(inv.type == MSG_DSTX && static_cast <bool >(CCoinJoin::GetDSTX (inv.hash ))) ||
1847
1843
m_mempool.exists (inv.hash ) ||
1848
1844
(g_txindex != nullptr && g_txindex->HasTx (inv.hash ));
@@ -2553,8 +2549,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
2553
2549
// Has inputs but not accepted to mempool
2554
2550
// Probably non-standard or insufficient fee
2555
2551
LogPrint (BCLog::MEMPOOL, " removed orphan tx %s\n " , orphanHash.ToString ());
2556
- assert (recentRejects);
2557
- recentRejects->insert (orphanHash);
2552
+ m_recent_rejects.insert (orphanHash);
2558
2553
EraseOrphanTx (orphanHash);
2559
2554
done = true ;
2560
2555
}
@@ -3608,7 +3603,7 @@ void PeerManagerImpl::ProcessMessage(
3608
3603
{
3609
3604
bool fRejectedParents = false ; // It may be the case that the orphans parents have all been rejected
3610
3605
for (const CTxIn& txin : tx.vin ) {
3611
- if (recentRejects-> contains (txin.prevout .hash )) {
3606
+ if (m_recent_rejects. contains (txin.prevout .hash )) {
3612
3607
fRejectedParents = true ;
3613
3608
break ;
3614
3609
}
@@ -3637,12 +3632,11 @@ void PeerManagerImpl::ProcessMessage(
3637
3632
LogPrint (BCLog::MEMPOOL, " not keeping orphan with rejected parents %s\n " ,tx.GetHash ().ToString ());
3638
3633
// We will continue to reject this tx since it has rejected
3639
3634
// parents so avoid re-requesting it from other peers.
3640
- recentRejects-> insert (tx.GetHash ());
3635
+ m_recent_rejects. insert (tx.GetHash ());
3641
3636
m_llmq_ctx->isman ->TransactionRemovedFromMempool (ptx);
3642
3637
}
3643
3638
} else {
3644
- assert (recentRejects);
3645
- recentRejects->insert (tx.GetHash ());
3639
+ m_recent_rejects.insert (tx.GetHash ());
3646
3640
if (RecursiveDynamicUsage (*ptx) < 100000 ) {
3647
3641
AddToCompactExtraTransactions (ptx);
3648
3642
}
@@ -3661,21 +3655,21 @@ void PeerManagerImpl::ProcessMessage(
3661
3655
}
3662
3656
}
3663
3657
3664
- // If a tx has been detected by recentRejects , we will have reached
3658
+ // If a tx has been detected by m_recent_rejects , we will have reached
3665
3659
// this point and the tx will have been ignored. Because we haven't run
3666
3660
// the tx through AcceptToMemoryPool, we won't have computed a DoS
3667
3661
// score for it or determined exactly why we consider it invalid.
3668
3662
//
3669
3663
// This means we won't penalize any peer subsequently relaying a DoSy
3670
3664
// tx (even if we penalized the first peer who gave it to us) because
3671
- // we have to account for recentRejects showing false positives. In
3665
+ // we have to account for m_recent_rejects showing false positives. In
3672
3666
// other words, we shouldn't penalize a peer if we aren't *sure* they
3673
3667
// submitted a DoSy tx.
3674
3668
//
3675
- // Note that recentRejects doesn't just record DoSy or invalid
3669
+ // Note that m_recent_rejects doesn't just record DoSy or invalid
3676
3670
// transactions, but any tx not accepted by the m_mempool, which may be
3677
3671
// due to node policy (vs. consensus). So we can't blanket penalize a
3678
- // peer simply for relaying a tx that our recentRejects has caught,
3672
+ // peer simply for relaying a tx that our m_recent_rejects has caught,
3679
3673
// regardless of false positives.
3680
3674
3681
3675
if (state.IsInvalid ())
0 commit comments