Skip to content

Commit a90ab4a

Browse files
committed
scripted-diff: Rename lazily initialized bloom filters
-BEGIN VERIFY SCRIPT- sed -i 's/m_recent_confirmed_transactions/m_lazy_recent_confirmed_transactions/g' $(git grep -l 'm_recent_confirmed_transactions') sed -i 's/m_recent_rejects_reconsiderable/m_lazy_recent_rejects_reconsiderable/g' $(git grep -l 'm_recent_rejects_reconsiderable') sed -i 's/m_recent_rejects/m_lazy_recent_rejects/g' $(git grep -l 'm_recent_rejects') -END VERIFY SCRIPT-
1 parent 82de1bc commit a90ab4a

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

src/net_processing.cpp

+34-34
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ class PeerManagerImpl final : public PeerManager
584584
* @param[in] maybe_add_extra_compact_tx Whether this tx should be added to vExtraTxnForCompact.
585585
* Set to false if the tx has already been rejected before,
586586
* e.g. is an orphan, to avoid adding duplicate entries.
587-
* Updates m_txrequest, m_recent_rejects, m_recent_rejects_reconsiderable, m_orphanage, and vExtraTxnForCompact. */
587+
* Updates m_txrequest, m_lazy_recent_rejects, m_lazy_recent_rejects_reconsiderable, m_orphanage, and vExtraTxnForCompact. */
588588
void ProcessInvalidTx(NodeId nodeid, const CTransactionRef& tx, const TxValidationState& result,
589589
bool maybe_add_extra_compact_tx)
590590
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex, m_tx_download_mutex);
@@ -776,9 +776,9 @@ class PeerManagerImpl final : public PeerManager
776776
/** Synchronizes tx download including TxRequestTracker, rejection filters, and TxOrphanage.
777777
* Lock invariants:
778778
* - A txhash (txid or wtxid) in m_txrequest is not also in m_orphanage.
779-
* - A txhash (txid or wtxid) in m_txrequest is not also in m_recent_rejects.
780-
* - A txhash (txid or wtxid) in m_txrequest is not also in m_recent_rejects_reconsiderable.
781-
* - A txhash (txid or wtxid) in m_txrequest is not also in m_recent_confirmed_transactions.
779+
* - A txhash (txid or wtxid) in m_txrequest is not also in m_lazy_recent_rejects.
780+
* - A txhash (txid or wtxid) in m_txrequest is not also in m_lazy_recent_rejects_reconsiderable.
781+
* - A txhash (txid or wtxid) in m_txrequest is not also in m_lazy_recent_confirmed_transactions.
782782
* - Each data structure's limits hold (m_orphanage max size, m_txrequest per-peer limits, etc).
783783
*/
784784
Mutex m_tx_download_mutex ACQUIRED_BEFORE(m_mempool.cs);
@@ -856,9 +856,9 @@ class PeerManagerImpl final : public PeerManager
856856
/** Check whether we already have this gtxid in:
857857
* - mempool
858858
* - orphanage
859-
* - m_recent_rejects
860-
* - m_recent_rejects_reconsiderable (if include_reconsiderable = true)
861-
* - m_recent_confirmed_transactions
859+
* - m_lazy_recent_rejects
860+
* - m_lazy_recent_rejects_reconsiderable (if include_reconsiderable = true)
861+
* - m_lazy_recent_confirmed_transactions
862862
* */
863863
bool AlreadyHaveTx(const GenTxid& gtxid, bool include_reconsiderable)
864864
EXCLUSIVE_LOCKS_REQUIRED(m_tx_download_mutex);
@@ -897,17 +897,17 @@ class PeerManagerImpl final : public PeerManager
897897
*
898898
* Memory used: 1.3 MB
899899
*/
900-
std::unique_ptr<CRollingBloomFilter> m_recent_rejects GUARDED_BY(m_tx_download_mutex){nullptr};
900+
std::unique_ptr<CRollingBloomFilter> m_lazy_recent_rejects GUARDED_BY(m_tx_download_mutex){nullptr};
901901

902902
CRollingBloomFilter& RecentRejectsFilter() EXCLUSIVE_LOCKS_REQUIRED(m_tx_download_mutex)
903903
{
904904
AssertLockHeld(m_tx_download_mutex);
905905

906-
if (!m_recent_rejects) {
907-
m_recent_rejects = std::make_unique<CRollingBloomFilter>(120'000, 0.000'001);
906+
if (!m_lazy_recent_rejects) {
907+
m_lazy_recent_rejects = std::make_unique<CRollingBloomFilter>(120'000, 0.000'001);
908908
}
909909

910-
return *m_recent_rejects;
910+
return *m_lazy_recent_rejects;
911911
}
912912

913913
/**
@@ -916,7 +916,7 @@ class PeerManagerImpl final : public PeerManager
916916
* eligible for reconsideration if submitted with other transactions.
917917
* (2) packages (see GetPackageHash) we have already rejected before and should not retry.
918918
*
919-
* Similar to m_recent_rejects, this filter is used to save bandwidth when e.g. all of our peers
919+
* Similar to m_lazy_recent_rejects, this filter is used to save bandwidth when e.g. all of our peers
920920
* have larger mempools and thus lower minimum feerates than us.
921921
*
922922
* When a transaction's error is TxValidationResult::TX_RECONSIDERABLE (in a package or by
@@ -928,19 +928,19 @@ class PeerManagerImpl final : public PeerManager
928928
*
929929
* Reset this filter when the chain tip changes.
930930
*
931-
* Parameters are picked to be the same as m_recent_rejects, with the same rationale.
931+
* Parameters are picked to be the same as m_lazy_recent_rejects, with the same rationale.
932932
*/
933-
std::unique_ptr<CRollingBloomFilter> m_recent_rejects_reconsiderable GUARDED_BY(m_tx_download_mutex){nullptr};
933+
std::unique_ptr<CRollingBloomFilter> m_lazy_recent_rejects_reconsiderable GUARDED_BY(m_tx_download_mutex){nullptr};
934934

935935
CRollingBloomFilter& RecentRejectsReconsiderableFilter() EXCLUSIVE_LOCKS_REQUIRED(m_tx_download_mutex)
936936
{
937937
AssertLockHeld(m_tx_download_mutex);
938938

939-
if (!m_recent_rejects_reconsiderable) {
940-
m_recent_rejects_reconsiderable = std::make_unique<CRollingBloomFilter>(120'000, 0.000'001);
939+
if (!m_lazy_recent_rejects_reconsiderable) {
940+
m_lazy_recent_rejects_reconsiderable = std::make_unique<CRollingBloomFilter>(120'000, 0.000'001);
941941
}
942942

943-
return *m_recent_rejects_reconsiderable;
943+
return *m_lazy_recent_rejects_reconsiderable;
944944
}
945945

946946
/*
@@ -958,17 +958,17 @@ class PeerManagerImpl final : public PeerManager
958958
* transaction per day that would be inadvertently ignored (which is the
959959
* same probability that we have in the reject filter).
960960
*/
961-
std::unique_ptr<CRollingBloomFilter> m_recent_confirmed_transactions GUARDED_BY(m_tx_download_mutex){nullptr};
961+
std::unique_ptr<CRollingBloomFilter> m_lazy_recent_confirmed_transactions GUARDED_BY(m_tx_download_mutex){nullptr};
962962

963963
CRollingBloomFilter& RecentConfirmedTransactionsFilter() EXCLUSIVE_LOCKS_REQUIRED(m_tx_download_mutex)
964964
{
965965
AssertLockHeld(m_tx_download_mutex);
966966

967-
if (!m_recent_confirmed_transactions) {
968-
m_recent_confirmed_transactions = std::make_unique<CRollingBloomFilter>(48'000, 0.000'001);
967+
if (!m_lazy_recent_confirmed_transactions) {
968+
m_lazy_recent_confirmed_transactions = std::make_unique<CRollingBloomFilter>(48'000, 0.000'001);
969969
}
970970

971-
return *m_recent_confirmed_transactions;
971+
return *m_lazy_recent_confirmed_transactions;
972972
}
973973

974974
/**
@@ -3225,7 +3225,7 @@ void PeerManagerImpl::ProcessInvalidTx(NodeId nodeid, const CTransactionRef& ptx
32253225
// for concerns around weakening security of unupgraded nodes
32263226
// if we start doing this too early.
32273227
if (state.GetResult() == TxValidationResult::TX_RECONSIDERABLE) {
3228-
// If the result is TX_RECONSIDERABLE, add it to m_recent_rejects_reconsiderable
3228+
// If the result is TX_RECONSIDERABLE, add it to m_lazy_recent_rejects_reconsiderable
32293229
// because we should not download or submit this transaction by itself again, but may
32303230
// submit it as part of a package later.
32313231
RecentRejectsReconsiderableFilter().insert(ptx->GetWitnessHash().ToUint256());
@@ -3389,7 +3389,7 @@ std::optional<PeerManagerImpl::PackageToValidate> PeerManagerImpl::Find1P1CPacka
33893389

33903390
for (const auto index : tx_indices) {
33913391
// If we already tried a package and failed for any reason, the combined hash was
3392-
// cached in m_recent_rejects_reconsiderable.
3392+
// cached in m_lazy_recent_rejects_reconsiderable.
33933393
const auto [child_tx, child_sender] = cpfp_candidates_different_peer.at(index);
33943394
Package maybe_cpfp_package{ptx, child_tx};
33953395
if (!RecentRejectsReconsiderableFilter().contains(GetPackageHash(maybe_cpfp_package))) {
@@ -4585,7 +4585,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
45854585
}
45864586

45874587
if (RecentRejectsReconsiderableFilter().contains(wtxid)) {
4588-
// When a transaction is already in m_recent_rejects_reconsiderable, we shouldn't submit
4588+
// When a transaction is already in m_lazy_recent_rejects_reconsiderable, we shouldn't submit
45894589
// it by itself again. However, look for a matching child in the orphanage, as it is
45904590
// possible that they succeed as a package.
45914591
LogPrint(BCLog::TXPACKAGES, "found tx %s (wtxid=%s) in reconsiderable rejects, looking for child in orphanage\n",
@@ -4597,20 +4597,20 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
45974597
ProcessPackageResult(package_to_validate.value(), package_result);
45984598
}
45994599
}
4600-
// If a tx is detected by m_recent_rejects it is ignored. Because we haven't
4600+
// If a tx is detected by m_lazy_recent_rejects it is ignored. Because we haven't
46014601
// submitted the tx to our mempool, we won't have computed a DoS
46024602
// score for it or determined exactly why we consider it invalid.
46034603
//
46044604
// This means we won't penalize any peer subsequently relaying a DoSy
46054605
// tx (even if we penalized the first peer who gave it to us) because
4606-
// we have to account for m_recent_rejects showing false positives. In
4606+
// we have to account for m_lazy_recent_rejects showing false positives. In
46074607
// other words, we shouldn't penalize a peer if we aren't *sure* they
46084608
// submitted a DoSy tx.
46094609
//
4610-
// Note that m_recent_rejects doesn't just record DoSy or invalid
4610+
// Note that m_lazy_recent_rejects doesn't just record DoSy or invalid
46114611
// transactions, but any tx not accepted by the mempool, which may be
46124612
// due to node policy (vs. consensus). So we can't blanket penalize a
4613-
// peer simply for relaying a tx that our m_recent_rejects has caught,
4613+
// peer simply for relaying a tx that our m_lazy_recent_rejects has caught,
46144614
// regardless of false positives.
46154615
return;
46164616
}
@@ -4637,16 +4637,16 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
46374637
std::sort(unique_parents.begin(), unique_parents.end());
46384638
unique_parents.erase(std::unique(unique_parents.begin(), unique_parents.end()), unique_parents.end());
46394639

4640-
// Distinguish between parents in m_recent_rejects and m_recent_rejects_reconsiderable.
4641-
// We can tolerate having up to 1 parent in m_recent_rejects_reconsiderable since we
4642-
// submit 1p1c packages. However, fail immediately if any are in m_recent_rejects.
4640+
// Distinguish between parents in m_lazy_recent_rejects and m_lazy_recent_rejects_reconsiderable.
4641+
// We can tolerate having up to 1 parent in m_lazy_recent_rejects_reconsiderable since we
4642+
// submit 1p1c packages. However, fail immediately if any are in m_lazy_recent_rejects.
46434643
std::optional<uint256> rejected_parent_reconsiderable;
46444644
for (const uint256& parent_txid : unique_parents) {
46454645
if (RecentRejectsFilter().contains(parent_txid)) {
46464646
fRejectedParents = true;
46474647
break;
46484648
} else if (RecentRejectsReconsiderableFilter().contains(parent_txid) && !m_mempool.exists(GenTxid::Txid(parent_txid))) {
4649-
// More than 1 parent in m_recent_rejects_reconsiderable: 1p1c will not be
4649+
// More than 1 parent in m_lazy_recent_rejects_reconsiderable: 1p1c will not be
46504650
// sufficient to accept this package, so just give up here.
46514651
if (rejected_parent_reconsiderable.has_value()) {
46524652
fRejectedParents = true;
@@ -4666,7 +4666,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
46664666
// protocol for getting all unconfirmed parents.
46674667
const auto gtxid{GenTxid::Txid(parent_txid)};
46684668
AddKnownTx(*peer, parent_txid);
4669-
// Exclude m_recent_rejects_reconsiderable: the missing parent may have been
4669+
// Exclude m_lazy_recent_rejects_reconsiderable: the missing parent may have been
46704670
// previously rejected for being too low feerate. This orphan might CPFP it.
46714671
if (!AlreadyHaveTx(gtxid, /*include_reconsiderable=*/false)) AddTxAnnouncement(pfrom, gtxid, current_time);
46724672
}
@@ -6339,7 +6339,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
63396339
entry.second.GetHash().ToString(), entry.first);
63406340
}
63416341
for (const GenTxid& gtxid : requestable) {
6342-
// Exclude m_recent_rejects_reconsiderable: we may be requesting a missing parent
6342+
// Exclude m_lazy_recent_rejects_reconsiderable: we may be requesting a missing parent
63436343
// that was previously rejected for being too low feerate.
63446344
if (!AlreadyHaveTx(gtxid, /*include_reconsiderable=*/false)) {
63456345
LogPrint(BCLog::NET, "Requesting %s %s peer=%d\n", gtxid.IsWtxid() ? "wtx" : "tx",

test/functional/mempool_reorg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def run_test(self):
162162
self.log.info("Generate a block")
163163
last_block = self.generate(self.nodes[0], 1)
164164
# generate() implicitly syncs blocks, so that peer 1 gets the block before timelock_tx
165-
# Otherwise, peer 1 would put the timelock_tx in m_recent_rejects
165+
# Otherwise, peer 1 would put the timelock_tx in m_lazy_recent_rejects
166166

167167
self.log.info("The time-locked transaction can now be spent")
168168
timelock_tx_id = self.nodes[0].sendrawtransaction(timelock_tx)

test/functional/p2p_permissions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def check_tx_relay(self):
121121
tx.vout[0].nValue += 1
122122
txid = tx.rehash()
123123
# Send the transaction twice. The first time, it'll be rejected by ATMP because it conflicts
124-
# with a mempool transaction. The second time, it'll be in the m_recent_rejects filter.
124+
# with a mempool transaction. The second time, it'll be in the m_lazy_recent_rejects filter.
125125
p2p_rebroadcast_wallet.send_txs_and_test(
126126
[tx],
127127
self.nodes[1],

0 commit comments

Comments
 (0)