@@ -156,9 +156,9 @@ bool CTxMemPool::CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntr
156
156
// GetMemPoolParents() is only valid for entries in the mempool, so we
157
157
// iterate mapTx to find parents.
158
158
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);
162
162
if (parentHashes.size () + 1 > limitAncestorCount) {
163
163
errString = strprintf (" too many unconfirmed parents [limit: %u]" , limitAncestorCount);
164
164
return false ;
@@ -364,12 +364,10 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
364
364
// Update transaction for any feeDelta created by PrioritiseTransaction
365
365
// TODO: refactor so that the fee delta is calculated before inserting
366
366
// 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) {
371
370
mapTx.modify (newit, update_fee_delta (delta));
372
- }
373
371
}
374
372
375
373
// Update cachedInnerUsage to include contained transaction's usage.
@@ -391,11 +389,8 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
391
389
// to clean up the mess we're leaving here.
392
390
393
391
// 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)) {
397
393
UpdateParent (newit, pit, true );
398
- }
399
394
}
400
395
UpdateAncestorsOf (true , newit, setAncestors);
401
396
UpdateEntryForAncestors (newit, setAncestors);
@@ -864,6 +859,29 @@ void CTxMemPool::ClearPrioritisation(const uint256 hash)
864
859
mapDeltas.erase (hash);
865
860
}
866
861
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
+
867
885
bool CTxMemPool::HasNoInputsOf (const CTransaction &tx) const
868
886
{
869
887
for (unsigned int i = 0 ; i < tx.vin .size (); i++)
0 commit comments