aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2021-02-15 22:53:06 +1000
committerAnthony Towns <aj@erisian.com.au>2021-02-27 01:08:09 +1000
commitf8c0688b9490c8d4902530ba3c3b6fbd8b48e0de (patch)
tree0d11b535636c6c46064266c43f90b9bc4b096da5
parent6bd4963c069bfd0af420e8a3fb724c3b693a1e76 (diff)
downloadbitcoin-f8c0688b9490c8d4902530ba3c3b6fbd8b48e0de.tar.xz
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-
-rw-r--r--src/test/denialofservice_tests.cpp10
-rw-r--r--src/txorphanage.cpp74
-rw-r--r--src/txorphanage.h20
3 files changed, 52 insertions, 52 deletions
diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp
index 35f16aa69d..5906913b58 100644
--- a/src/test/denialofservice_tests.cpp
+++ b/src/test/denialofservice_tests.cpp
@@ -289,15 +289,15 @@ class TxOrphanageTest : public TxOrphanage
public:
inline size_t CountOrphans() const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
{
- return mapOrphanTransactions.size();
+ return m_orphans.size();
}
CTransactionRef RandomOrphan() EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
{
- std::map<uint256, COrphanTx>::iterator it;
- it = mapOrphanTransactions.lower_bound(InsecureRand256());
- if (it == mapOrphanTransactions.end())
- it = mapOrphanTransactions.begin();
+ std::map<uint256, OrphanTx>::iterator it;
+ it = m_orphans.lower_bound(InsecureRand256());
+ if (it == m_orphans.end())
+ it = m_orphans.begin();
return it->second.tx;
}
};
diff --git a/src/txorphanage.cpp b/src/txorphanage.cpp
index f758107b82..ed4783f1a5 100644
--- a/src/txorphanage.cpp
+++ b/src/txorphanage.cpp
@@ -22,7 +22,7 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
AssertLockHeld(g_cs_orphans);
const uint256& hash = tx->GetHash();
- if (mapOrphanTransactions.count(hash))
+ if (m_orphans.count(hash))
return false;
// Ignore big transactions, to avoid a
@@ -39,49 +39,49 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
return false;
}
- auto ret = mapOrphanTransactions.emplace(hash, COrphanTx{tx, peer, GetTime() + ORPHAN_TX_EXPIRE_TIME, g_orphan_list.size()});
+ auto ret = m_orphans.emplace(hash, OrphanTx{tx, peer, GetTime() + ORPHAN_TX_EXPIRE_TIME, m_orphan_list.size()});
assert(ret.second);
- g_orphan_list.push_back(ret.first);
+ m_orphan_list.push_back(ret.first);
// Allow for lookups in the orphan pool by wtxid, as well as txid
- g_orphans_by_wtxid.emplace(tx->GetWitnessHash(), ret.first);
+ m_wtxid_to_orphan_it.emplace(tx->GetWitnessHash(), ret.first);
for (const CTxIn& txin : tx->vin) {
- mapOrphanTransactionsByPrev[txin.prevout].insert(ret.first);
+ m_outpoint_to_orphan_it[txin.prevout].insert(ret.first);
}
LogPrint(BCLog::MEMPOOL, "stored orphan tx %s (mapsz %u outsz %u)\n", hash.ToString(),
- mapOrphanTransactions.size(), mapOrphanTransactionsByPrev.size());
+ m_orphans.size(), m_outpoint_to_orphan_it.size());
return true;
}
int TxOrphanage::EraseTx(const uint256& txid)
{
AssertLockHeld(g_cs_orphans);
- std::map<uint256, COrphanTx>::iterator it = mapOrphanTransactions.find(txid);
- if (it == mapOrphanTransactions.end())
+ std::map<uint256, OrphanTx>::iterator it = m_orphans.find(txid);
+ if (it == m_orphans.end())
return 0;
for (const CTxIn& txin : it->second.tx->vin)
{
- auto itPrev = mapOrphanTransactionsByPrev.find(txin.prevout);
- if (itPrev == mapOrphanTransactionsByPrev.end())
+ auto itPrev = m_outpoint_to_orphan_it.find(txin.prevout);
+ if (itPrev == m_outpoint_to_orphan_it.end())
continue;
itPrev->second.erase(it);
if (itPrev->second.empty())
- mapOrphanTransactionsByPrev.erase(itPrev);
+ m_outpoint_to_orphan_it.erase(itPrev);
}
size_t old_pos = it->second.list_pos;
- assert(g_orphan_list[old_pos] == it);
- if (old_pos + 1 != g_orphan_list.size()) {
- // Unless we're deleting the last entry in g_orphan_list, move the last
+ assert(m_orphan_list[old_pos] == it);
+ if (old_pos + 1 != m_orphan_list.size()) {
+ // Unless we're deleting the last entry in m_orphan_list, move the last
// entry to the position we're deleting.
- auto it_last = g_orphan_list.back();
- g_orphan_list[old_pos] = it_last;
+ auto it_last = m_orphan_list.back();
+ m_orphan_list[old_pos] = it_last;
it_last->second.list_pos = old_pos;
}
- g_orphan_list.pop_back();
- g_orphans_by_wtxid.erase(it->second.tx->GetWitnessHash());
+ m_orphan_list.pop_back();
+ m_wtxid_to_orphan_it.erase(it->second.tx->GetWitnessHash());
- mapOrphanTransactions.erase(it);
+ m_orphans.erase(it);
return 1;
}
@@ -90,10 +90,10 @@ void TxOrphanage::EraseForPeer(NodeId peer)
AssertLockHeld(g_cs_orphans);
int nErased = 0;
- std::map<uint256, COrphanTx>::iterator iter = mapOrphanTransactions.begin();
- while (iter != mapOrphanTransactions.end())
+ std::map<uint256, OrphanTx>::iterator iter = m_orphans.begin();
+ while (iter != m_orphans.end())
{
- std::map<uint256, COrphanTx>::iterator maybeErase = iter++; // increment to avoid iterator becoming invalid
+ std::map<uint256, OrphanTx>::iterator maybeErase = iter++; // increment to avoid iterator becoming invalid
if (maybeErase->second.fromPeer == peer)
{
nErased += EraseTx(maybeErase->second.tx->GetHash());
@@ -102,7 +102,7 @@ void TxOrphanage::EraseForPeer(NodeId peer)
if (nErased > 0) LogPrint(BCLog::MEMPOOL, "Erased %d orphan tx from peer=%d\n", nErased, peer);
}
-unsigned int TxOrphanage::LimitOrphans(unsigned int nMaxOrphans)
+unsigned int TxOrphanage::LimitOrphans(unsigned int max_orphans)
{
AssertLockHeld(g_cs_orphans);
@@ -113,10 +113,10 @@ unsigned int TxOrphanage::LimitOrphans(unsigned int nMaxOrphans)
// Sweep out expired orphan pool entries:
int nErased = 0;
int64_t nMinExpTime = nNow + ORPHAN_TX_EXPIRE_TIME - ORPHAN_TX_EXPIRE_INTERVAL;
- std::map<uint256, COrphanTx>::iterator iter = mapOrphanTransactions.begin();
- while (iter != mapOrphanTransactions.end())
+ std::map<uint256, OrphanTx>::iterator iter = m_orphans.begin();
+ while (iter != m_orphans.end())
{
- std::map<uint256, COrphanTx>::iterator maybeErase = iter++;
+ std::map<uint256, OrphanTx>::iterator maybeErase = iter++;
if (maybeErase->second.nTimeExpire <= nNow) {
nErased += EraseTx(maybeErase->second.tx->GetHash());
} else {
@@ -128,11 +128,11 @@ unsigned int TxOrphanage::LimitOrphans(unsigned int nMaxOrphans)
if (nErased > 0) LogPrint(BCLog::MEMPOOL, "Erased %d orphan tx due to expiration\n", nErased);
}
FastRandomContext rng;
- while (mapOrphanTransactions.size() > nMaxOrphans)
+ while (m_orphans.size() > max_orphans)
{
// Evict a random orphan:
- size_t randompos = rng.randrange(g_orphan_list.size());
- EraseTx(g_orphan_list[randompos]->first);
+ size_t randompos = rng.randrange(m_orphan_list.size());
+ EraseTx(m_orphan_list[randompos]->first);
++nEvicted;
}
return nEvicted;
@@ -142,8 +142,8 @@ void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>
{
AssertLockHeld(g_cs_orphans);
for (unsigned int i = 0; i < tx.vout.size(); i++) {
- const auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(tx.GetHash(), i));
- if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
+ const auto it_by_prev = m_outpoint_to_orphan_it.find(COutPoint(tx.GetHash(), i));
+ if (it_by_prev != m_outpoint_to_orphan_it.end()) {
for (const auto& elem : it_by_prev->second) {
orphan_work_set.insert(elem->first);
}
@@ -155,9 +155,9 @@ bool TxOrphanage::HaveTx(const GenTxid& gtxid) const
{
LOCK(g_cs_orphans);
if (gtxid.IsWtxid()) {
- return g_orphans_by_wtxid.count(gtxid.GetHash());
+ return m_wtxid_to_orphan_it.count(gtxid.GetHash());
} else {
- return mapOrphanTransactions.count(gtxid.GetHash());
+ return m_orphans.count(gtxid.GetHash());
}
}
@@ -165,8 +165,8 @@ std::pair<CTransactionRef, NodeId> TxOrphanage::GetTx(const uint256& txid) const
{
AssertLockHeld(g_cs_orphans);
- const auto it = mapOrphanTransactions.find(txid);
- if (it == mapOrphanTransactions.end()) return {nullptr, -1};
+ const auto it = m_orphans.find(txid);
+ if (it == m_orphans.end()) return {nullptr, -1};
return {it->second.tx, it->second.fromPeer};
}
@@ -181,8 +181,8 @@ void TxOrphanage::EraseForBlock(const CBlock& block)
// Which orphan pool entries must we evict?
for (const auto& txin : tx.vin) {
- auto itByPrev = mapOrphanTransactionsByPrev.find(txin.prevout);
- if (itByPrev == mapOrphanTransactionsByPrev.end()) continue;
+ auto itByPrev = m_outpoint_to_orphan_it.find(txin.prevout);
+ if (itByPrev == m_outpoint_to_orphan_it.end()) continue;
for (auto mi = itByPrev->second.begin(); mi != itByPrev->second.end(); ++mi) {
const CTransaction& orphanTx = *(*mi)->second.tx;
const uint256& orphanHash = orphanTx.GetHash();
diff --git a/src/txorphanage.h b/src/txorphanage.h
index 6b9837815b..a5e6764d75 100644
--- a/src/txorphanage.h
+++ b/src/txorphanage.h
@@ -36,14 +36,14 @@ public:
void EraseForBlock(const CBlock& block) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans);
/** Limit the orphanage to the given maximum */
- unsigned int LimitOrphans(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
+ unsigned int LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
/** Add any orphans that list a particular tx as a parent into a peer's work set
* (ie orphans that may have found their final missing parent, and so should be reconsidered for the mempool) */
void AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work_set) const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
protected:
- struct COrphanTx {
+ struct OrphanTx {
CTransactionRef tx;
NodeId fromPeer;
int64_t nTimeExpire;
@@ -52,9 +52,9 @@ protected:
/** Map from txid to orphan transaction record. Limited by
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */
- std::map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(g_cs_orphans);
+ std::map<uint256, OrphanTx> m_orphans GUARDED_BY(g_cs_orphans);
- using OrphanMap = decltype(mapOrphanTransactions);
+ using OrphanMap = decltype(m_orphans);
struct IteratorComparator
{
@@ -65,16 +65,16 @@ protected:
}
};
- /** Index from the parents' COutPoint into the mapOrphanTransactions. Used
- * to remove orphan transactions from the mapOrphanTransactions */
- std::map<COutPoint, std::set<OrphanMap::iterator, IteratorComparator>> mapOrphanTransactionsByPrev GUARDED_BY(g_cs_orphans);
+ /** Index from the parents' COutPoint into the m_orphans. Used
+ * to remove orphan transactions from the m_orphans */
+ std::map<COutPoint, std::set<OrphanMap::iterator, IteratorComparator>> m_outpoint_to_orphan_it GUARDED_BY(g_cs_orphans);
/** Orphan transactions in vector for quick random eviction */
- std::vector<OrphanMap::iterator> g_orphan_list GUARDED_BY(g_cs_orphans);
+ std::vector<OrphanMap::iterator> m_orphan_list GUARDED_BY(g_cs_orphans);
- /** Index from wtxid into the mapOrphanTransactions to lookup orphan
+ /** Index from wtxid into the m_orphans to lookup orphan
* transactions using their witness ids. */
- std::map<uint256, OrphanMap::iterator> g_orphans_by_wtxid GUARDED_BY(g_cs_orphans);
+ std::map<uint256, OrphanMap::iterator> m_wtxid_to_orphan_it GUARDED_BY(g_cs_orphans);
};
#endif // BITCOIN_TXORPHANAGE_H