diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -131,7 +131,7 @@ }; RecursiveMutex g_cs_orphans; -std::map mapOrphanTransactions GUARDED_BY(g_cs_orphans); +std::map mapOrphanTransactions GUARDED_BY(g_cs_orphans); void EraseOrphansFor(NodeId peer); @@ -245,7 +245,7 @@ } }; std::map::iterator, IteratorComparator>> + std::set::iterator, IteratorComparator>> mapOrphanTransactionsByPrev GUARDED_BY(g_cs_orphans); static size_t vExtraTxnForCompactIt GUARDED_BY(g_cs_orphans) = 0; @@ -1026,7 +1026,7 @@ bool AddOrphanTx(const CTransactionRef &tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans) { - const uint256 &txid = tx->GetId(); + const auto &txid = tx->GetId(); if (mapOrphanTransactions.count(txid)) { return false; } @@ -1060,14 +1060,13 @@ return true; } -static int EraseOrphanTx(uint256 hash) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans) { - std::map::iterator it = - mapOrphanTransactions.find(hash); +static int EraseOrphanTx(TxId hash) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans) { + const auto it = mapOrphanTransactions.find(hash); if (it == mapOrphanTransactions.end()) { return 0; } for (const CTxIn &txin : it->second.tx->vin) { - auto itPrev = mapOrphanTransactionsByPrev.find(txin.prevout); + const auto itPrev = mapOrphanTransactionsByPrev.find(txin.prevout); if (itPrev == mapOrphanTransactionsByPrev.end()) { continue; } @@ -1083,10 +1082,10 @@ void EraseOrphansFor(NodeId peer) { LOCK(g_cs_orphans); int nErased = 0; - std::map::iterator iter = mapOrphanTransactions.begin(); + auto iter = mapOrphanTransactions.begin(); while (iter != mapOrphanTransactions.end()) { // Increment to avoid iterator becoming invalid. - std::map::iterator maybeErase = iter++; + const auto maybeErase = iter++; if (maybeErase->second.fromPeer == peer) { nErased += EraseOrphanTx(maybeErase->second.tx->GetId()); } @@ -1108,10 +1107,9 @@ int nErased = 0; int64_t nMinExpTime = nNow + ORPHAN_TX_EXPIRE_TIME - ORPHAN_TX_EXPIRE_INTERVAL; - std::map::iterator iter = - mapOrphanTransactions.begin(); + auto iter = mapOrphanTransactions.begin(); while (iter != mapOrphanTransactions.end()) { - std::map::iterator maybeErase = iter++; + const auto maybeErase = iter++; if (maybeErase->second.nTimeExpire <= nNow) { nErased += EraseOrphanTx(maybeErase->second.tx->GetId()); } else { @@ -1130,9 +1128,8 @@ FastRandomContext rng; while (mapOrphanTransactions.size() > nMaxOrphans) { // Evict a random orphan: - uint256 randomhash = rng.rand256(); - std::map::iterator it = - mapOrphanTransactions.lower_bound(randomhash); + const auto randomhash = TxId{rng.rand256()}; + auto it = mapOrphanTransactions.lower_bound(randomhash); if (it == mapOrphanTransactions.end()) { it = mapOrphanTransactions.begin(); } @@ -1236,7 +1233,7 @@ const std::vector &vtxConflicted) { LOCK(g_cs_orphans); - std::vector vOrphanErase; + std::vector vOrphanErase; for (const CTransactionRef &ptx : pblock->vtx) { const CTransaction &tx = *ptx; @@ -1251,7 +1248,7 @@ for (auto mi = itByPrev->second.begin(); mi != itByPrev->second.end(); ++mi) { const CTransaction &orphanTx = *(*mi)->second.tx; - const uint256 &orphanHash = orphanTx.GetHash(); + const auto &orphanHash = orphanTx.GetId(); vOrphanErase.push_back(orphanHash); } } @@ -1260,7 +1257,7 @@ // Erase orphan transactions included or precluded by this block if (vOrphanErase.size()) { int nErased = 0; - for (const uint256 &orphanId : vOrphanErase) { + for (const auto &orphanId : vOrphanErase) { nErased += EraseOrphanTx(orphanId); } LogPrint(BCLog::MEMPOOL, @@ -1440,7 +1437,7 @@ { LOCK(g_cs_orphans); - if (mapOrphanTransactions.count(inv.hash)) { + if (mapOrphanTransactions.count(TxId(inv.hash))) { return true; } } @@ -2782,7 +2779,7 @@ } std::deque vWorkQueue; - std::vector vEraseQueue; + std::vector vEraseQueue; CTransactionRef ptx; vRecv >> ptx; const CTransaction &tx = *ptx; @@ -2891,7 +2888,7 @@ } } - for (const uint256 &hash : vEraseQueue) { + for (const auto &hash : vEraseQueue) { EraseOrphanTx(hash); } } else if (fMissingInputs) {