@@ -156,9 +156,9 @@ bool CTxMemPool::CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntr
156156 // GetMemPoolParents() is only valid for entries in the mempool, so we
157157 // iterate mapTx to find parents.
158158 for (unsigned int i = 0 ; i < tx.vin .size (); i++) {
159- txiter piter = mapTx. find (tx.vin [i].prevout .hash );
160- if (piter != mapTx. end () ) {
161- parentHashes.insert (piter);
159+ boost::optional< txiter> piter = GetIter (tx.vin [i].prevout .hash );
160+ if (piter) {
161+ parentHashes.insert (* piter);
162162 if (parentHashes.size () + 1 > limitAncestorCount) {
163163 errString = strprintf (" too many unconfirmed parents [limit: %u]" , limitAncestorCount);
164164 return false ;
@@ -364,12 +364,10 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
364364 // Update transaction for any feeDelta created by PrioritiseTransaction
365365 // TODO: refactor so that the fee delta is calculated before inserting
366366 // into mapTx.
367- std::map<uint256, CAmount>::const_iterator pos = mapDeltas.find (entry.GetTx ().GetHash ());
368- if (pos != mapDeltas.end ()) {
369- const CAmount &delta = pos->second ;
370- if (delta) {
367+ CAmount delta{0 };
368+ ApplyDelta (entry.GetTx ().GetHash (), delta);
369+ if (delta) {
371370 mapTx.modify (newit, update_fee_delta (delta));
372- }
373371 }
374372
375373 // Update cachedInnerUsage to include contained transaction's usage.
@@ -391,11 +389,8 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
391389 // to clean up the mess we're leaving here.
392390
393391 // Update ancestors with information about this tx
394- for (const uint256 &phash : setParentTransactions) {
395- txiter pit = mapTx.find (phash);
396- if (pit != mapTx.end ()) {
392+ for (const auto & pit : GetIterSet (setParentTransactions)) {
397393 UpdateParent (newit, pit, true );
398- }
399394 }
400395 UpdateAncestorsOf (true , newit, setAncestors);
401396 UpdateEntryForAncestors (newit, setAncestors);
@@ -864,6 +859,29 @@ void CTxMemPool::ClearPrioritisation(const uint256 hash)
864859 mapDeltas.erase (hash);
865860}
866861
862+ const CTransaction* CTxMemPool::GetConflictTx (const COutPoint& prevout) const
863+ {
864+ const auto it = mapNextTx.find (prevout);
865+ return it == mapNextTx.end () ? nullptr : it->second ;
866+ }
867+
868+ boost::optional<CTxMemPool::txiter> CTxMemPool::GetIter (const uint256& txid) const
869+ {
870+ auto it = mapTx.find (txid);
871+ if (it != mapTx.end ()) return it;
872+ return boost::optional<txiter>{};
873+ }
874+
875+ CTxMemPool::setEntries CTxMemPool::GetIterSet (const std::set<uint256>& hashes) const
876+ {
877+ CTxMemPool::setEntries ret;
878+ for (const auto & h : hashes) {
879+ const auto mi = GetIter (h);
880+ if (mi) ret.insert (*mi);
881+ }
882+ return ret;
883+ }
884+
867885bool CTxMemPool::HasNoInputsOf (const CTransaction &tx) const
868886{
869887 for (unsigned int i = 0 ; i < tx.vin .size (); i++)
0 commit comments