Skip to content

Commit f8c0688

Browse files
committed
scripted-diff: Update txorphanage naming convention
-BEGIN VERIFY SCRIPT- sed -i 's/mapOrphanTransactionsByPrev/m_outpoint_to_orphan_it/g' src/txorphanage.h src/txorphanage.cpp sed -i 's/mapOrphanTransactions/m_orphans/g' src/txorphanage.h src/txorphanage.cpp src/net_processing.cpp src/test/denialofservice_tests.cpp sed -i 's/g_orphan_list/m_orphan_list/g' src/txorphanage.h src/txorphanage.cpp sed -i 's/g_orphans_by_wtxid/m_wtxid_to_orphan_it/g' src/txorphanage.h src/txorphanage.cpp sed -i 's/nMaxOrphans/max_orphans/g' src/txorphanage.h src/txorphanage.cpp sed -i 's/COrphanTx/OrphanTx/g' src/txorphanage.h src/txorphanage.cpp src/test/denialofservice_tests.cpp -END VERIFY SCRIPT-
1 parent 6bd4963 commit f8c0688

File tree

3 files changed

+52
-52
lines changed

3 files changed

+52
-52
lines changed

src/test/denialofservice_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,15 @@ class TxOrphanageTest : public TxOrphanage
289289
public:
290290
inline size_t CountOrphans() const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
291291
{
292-
return mapOrphanTransactions.size();
292+
return m_orphans.size();
293293
}
294294

295295
CTransactionRef RandomOrphan() EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
296296
{
297-
std::map<uint256, COrphanTx>::iterator it;
298-
it = mapOrphanTransactions.lower_bound(InsecureRand256());
299-
if (it == mapOrphanTransactions.end())
300-
it = mapOrphanTransactions.begin();
297+
std::map<uint256, OrphanTx>::iterator it;
298+
it = m_orphans.lower_bound(InsecureRand256());
299+
if (it == m_orphans.end())
300+
it = m_orphans.begin();
301301
return it->second.tx;
302302
}
303303
};

src/txorphanage.cpp

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
2222
AssertLockHeld(g_cs_orphans);
2323

2424
const uint256& hash = tx->GetHash();
25-
if (mapOrphanTransactions.count(hash))
25+
if (m_orphans.count(hash))
2626
return false;
2727

2828
// Ignore big transactions, to avoid a
@@ -39,49 +39,49 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
3939
return false;
4040
}
4141

42-
auto ret = mapOrphanTransactions.emplace(hash, COrphanTx{tx, peer, GetTime() + ORPHAN_TX_EXPIRE_TIME, g_orphan_list.size()});
42+
auto ret = m_orphans.emplace(hash, OrphanTx{tx, peer, GetTime() + ORPHAN_TX_EXPIRE_TIME, m_orphan_list.size()});
4343
assert(ret.second);
44-
g_orphan_list.push_back(ret.first);
44+
m_orphan_list.push_back(ret.first);
4545
// Allow for lookups in the orphan pool by wtxid, as well as txid
46-
g_orphans_by_wtxid.emplace(tx->GetWitnessHash(), ret.first);
46+
m_wtxid_to_orphan_it.emplace(tx->GetWitnessHash(), ret.first);
4747
for (const CTxIn& txin : tx->vin) {
48-
mapOrphanTransactionsByPrev[txin.prevout].insert(ret.first);
48+
m_outpoint_to_orphan_it[txin.prevout].insert(ret.first);
4949
}
5050

5151
LogPrint(BCLog::MEMPOOL, "stored orphan tx %s (mapsz %u outsz %u)\n", hash.ToString(),
52-
mapOrphanTransactions.size(), mapOrphanTransactionsByPrev.size());
52+
m_orphans.size(), m_outpoint_to_orphan_it.size());
5353
return true;
5454
}
5555

5656
int TxOrphanage::EraseTx(const uint256& txid)
5757
{
5858
AssertLockHeld(g_cs_orphans);
59-
std::map<uint256, COrphanTx>::iterator it = mapOrphanTransactions.find(txid);
60-
if (it == mapOrphanTransactions.end())
59+
std::map<uint256, OrphanTx>::iterator it = m_orphans.find(txid);
60+
if (it == m_orphans.end())
6161
return 0;
6262
for (const CTxIn& txin : it->second.tx->vin)
6363
{
64-
auto itPrev = mapOrphanTransactionsByPrev.find(txin.prevout);
65-
if (itPrev == mapOrphanTransactionsByPrev.end())
64+
auto itPrev = m_outpoint_to_orphan_it.find(txin.prevout);
65+
if (itPrev == m_outpoint_to_orphan_it.end())
6666
continue;
6767
itPrev->second.erase(it);
6868
if (itPrev->second.empty())
69-
mapOrphanTransactionsByPrev.erase(itPrev);
69+
m_outpoint_to_orphan_it.erase(itPrev);
7070
}
7171

7272
size_t old_pos = it->second.list_pos;
73-
assert(g_orphan_list[old_pos] == it);
74-
if (old_pos + 1 != g_orphan_list.size()) {
75-
// Unless we're deleting the last entry in g_orphan_list, move the last
73+
assert(m_orphan_list[old_pos] == it);
74+
if (old_pos + 1 != m_orphan_list.size()) {
75+
// Unless we're deleting the last entry in m_orphan_list, move the last
7676
// entry to the position we're deleting.
77-
auto it_last = g_orphan_list.back();
78-
g_orphan_list[old_pos] = it_last;
77+
auto it_last = m_orphan_list.back();
78+
m_orphan_list[old_pos] = it_last;
7979
it_last->second.list_pos = old_pos;
8080
}
81-
g_orphan_list.pop_back();
82-
g_orphans_by_wtxid.erase(it->second.tx->GetWitnessHash());
81+
m_orphan_list.pop_back();
82+
m_wtxid_to_orphan_it.erase(it->second.tx->GetWitnessHash());
8383

84-
mapOrphanTransactions.erase(it);
84+
m_orphans.erase(it);
8585
return 1;
8686
}
8787

@@ -90,10 +90,10 @@ void TxOrphanage::EraseForPeer(NodeId peer)
9090
AssertLockHeld(g_cs_orphans);
9191

9292
int nErased = 0;
93-
std::map<uint256, COrphanTx>::iterator iter = mapOrphanTransactions.begin();
94-
while (iter != mapOrphanTransactions.end())
93+
std::map<uint256, OrphanTx>::iterator iter = m_orphans.begin();
94+
while (iter != m_orphans.end())
9595
{
96-
std::map<uint256, COrphanTx>::iterator maybeErase = iter++; // increment to avoid iterator becoming invalid
96+
std::map<uint256, OrphanTx>::iterator maybeErase = iter++; // increment to avoid iterator becoming invalid
9797
if (maybeErase->second.fromPeer == peer)
9898
{
9999
nErased += EraseTx(maybeErase->second.tx->GetHash());
@@ -102,7 +102,7 @@ void TxOrphanage::EraseForPeer(NodeId peer)
102102
if (nErased > 0) LogPrint(BCLog::MEMPOOL, "Erased %d orphan tx from peer=%d\n", nErased, peer);
103103
}
104104

105-
unsigned int TxOrphanage::LimitOrphans(unsigned int nMaxOrphans)
105+
unsigned int TxOrphanage::LimitOrphans(unsigned int max_orphans)
106106
{
107107
AssertLockHeld(g_cs_orphans);
108108

@@ -113,10 +113,10 @@ unsigned int TxOrphanage::LimitOrphans(unsigned int nMaxOrphans)
113113
// Sweep out expired orphan pool entries:
114114
int nErased = 0;
115115
int64_t nMinExpTime = nNow + ORPHAN_TX_EXPIRE_TIME - ORPHAN_TX_EXPIRE_INTERVAL;
116-
std::map<uint256, COrphanTx>::iterator iter = mapOrphanTransactions.begin();
117-
while (iter != mapOrphanTransactions.end())
116+
std::map<uint256, OrphanTx>::iterator iter = m_orphans.begin();
117+
while (iter != m_orphans.end())
118118
{
119-
std::map<uint256, COrphanTx>::iterator maybeErase = iter++;
119+
std::map<uint256, OrphanTx>::iterator maybeErase = iter++;
120120
if (maybeErase->second.nTimeExpire <= nNow) {
121121
nErased += EraseTx(maybeErase->second.tx->GetHash());
122122
} else {
@@ -128,11 +128,11 @@ unsigned int TxOrphanage::LimitOrphans(unsigned int nMaxOrphans)
128128
if (nErased > 0) LogPrint(BCLog::MEMPOOL, "Erased %d orphan tx due to expiration\n", nErased);
129129
}
130130
FastRandomContext rng;
131-
while (mapOrphanTransactions.size() > nMaxOrphans)
131+
while (m_orphans.size() > max_orphans)
132132
{
133133
// Evict a random orphan:
134-
size_t randompos = rng.randrange(g_orphan_list.size());
135-
EraseTx(g_orphan_list[randompos]->first);
134+
size_t randompos = rng.randrange(m_orphan_list.size());
135+
EraseTx(m_orphan_list[randompos]->first);
136136
++nEvicted;
137137
}
138138
return nEvicted;
@@ -142,8 +142,8 @@ void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>
142142
{
143143
AssertLockHeld(g_cs_orphans);
144144
for (unsigned int i = 0; i < tx.vout.size(); i++) {
145-
const auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(tx.GetHash(), i));
146-
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
145+
const auto it_by_prev = m_outpoint_to_orphan_it.find(COutPoint(tx.GetHash(), i));
146+
if (it_by_prev != m_outpoint_to_orphan_it.end()) {
147147
for (const auto& elem : it_by_prev->second) {
148148
orphan_work_set.insert(elem->first);
149149
}
@@ -155,18 +155,18 @@ bool TxOrphanage::HaveTx(const GenTxid& gtxid) const
155155
{
156156
LOCK(g_cs_orphans);
157157
if (gtxid.IsWtxid()) {
158-
return g_orphans_by_wtxid.count(gtxid.GetHash());
158+
return m_wtxid_to_orphan_it.count(gtxid.GetHash());
159159
} else {
160-
return mapOrphanTransactions.count(gtxid.GetHash());
160+
return m_orphans.count(gtxid.GetHash());
161161
}
162162
}
163163

164164
std::pair<CTransactionRef, NodeId> TxOrphanage::GetTx(const uint256& txid) const
165165
{
166166
AssertLockHeld(g_cs_orphans);
167167

168-
const auto it = mapOrphanTransactions.find(txid);
169-
if (it == mapOrphanTransactions.end()) return {nullptr, -1};
168+
const auto it = m_orphans.find(txid);
169+
if (it == m_orphans.end()) return {nullptr, -1};
170170
return {it->second.tx, it->second.fromPeer};
171171
}
172172

@@ -181,8 +181,8 @@ void TxOrphanage::EraseForBlock(const CBlock& block)
181181

182182
// Which orphan pool entries must we evict?
183183
for (const auto& txin : tx.vin) {
184-
auto itByPrev = mapOrphanTransactionsByPrev.find(txin.prevout);
185-
if (itByPrev == mapOrphanTransactionsByPrev.end()) continue;
184+
auto itByPrev = m_outpoint_to_orphan_it.find(txin.prevout);
185+
if (itByPrev == m_outpoint_to_orphan_it.end()) continue;
186186
for (auto mi = itByPrev->second.begin(); mi != itByPrev->second.end(); ++mi) {
187187
const CTransaction& orphanTx = *(*mi)->second.tx;
188188
const uint256& orphanHash = orphanTx.GetHash();

src/txorphanage.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ class TxOrphanage {
3636
void EraseForBlock(const CBlock& block) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans);
3737

3838
/** Limit the orphanage to the given maximum */
39-
unsigned int LimitOrphans(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
39+
unsigned int LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
4040

4141
/** Add any orphans that list a particular tx as a parent into a peer's work set
4242
* (ie orphans that may have found their final missing parent, and so should be reconsidered for the mempool) */
4343
void AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work_set) const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
4444

4545
protected:
46-
struct COrphanTx {
46+
struct OrphanTx {
4747
CTransactionRef tx;
4848
NodeId fromPeer;
4949
int64_t nTimeExpire;
@@ -52,9 +52,9 @@ class TxOrphanage {
5252

5353
/** Map from txid to orphan transaction record. Limited by
5454
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */
55-
std::map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(g_cs_orphans);
55+
std::map<uint256, OrphanTx> m_orphans GUARDED_BY(g_cs_orphans);
5656

57-
using OrphanMap = decltype(mapOrphanTransactions);
57+
using OrphanMap = decltype(m_orphans);
5858

5959
struct IteratorComparator
6060
{
@@ -65,16 +65,16 @@ class TxOrphanage {
6565
}
6666
};
6767

68-
/** Index from the parents' COutPoint into the mapOrphanTransactions. Used
69-
* to remove orphan transactions from the mapOrphanTransactions */
70-
std::map<COutPoint, std::set<OrphanMap::iterator, IteratorComparator>> mapOrphanTransactionsByPrev GUARDED_BY(g_cs_orphans);
68+
/** Index from the parents' COutPoint into the m_orphans. Used
69+
* to remove orphan transactions from the m_orphans */
70+
std::map<COutPoint, std::set<OrphanMap::iterator, IteratorComparator>> m_outpoint_to_orphan_it GUARDED_BY(g_cs_orphans);
7171

7272
/** Orphan transactions in vector for quick random eviction */
73-
std::vector<OrphanMap::iterator> g_orphan_list GUARDED_BY(g_cs_orphans);
73+
std::vector<OrphanMap::iterator> m_orphan_list GUARDED_BY(g_cs_orphans);
7474

75-
/** Index from wtxid into the mapOrphanTransactions to lookup orphan
75+
/** Index from wtxid into the m_orphans to lookup orphan
7676
* transactions using their witness ids. */
77-
std::map<uint256, OrphanMap::iterator> g_orphans_by_wtxid GUARDED_BY(g_cs_orphans);
77+
std::map<uint256, OrphanMap::iterator> m_wtxid_to_orphan_it GUARDED_BY(g_cs_orphans);
7878
};
7979

8080
#endif // BITCOIN_TXORPHANAGE_H

0 commit comments

Comments
 (0)