@@ -572,7 +572,7 @@ void CTxMemPool::remove(const CTransaction& origTx, std::list<CTransaction>& rem
572
572
{
573
573
LOCK (cs);
574
574
const ActivationState as (chainActive.Tip ());
575
- const bool segwitLight = as. IsActive (Fork::SegwitLight) ;
575
+ const TransactionUtxoHasher utxoHasher ;
576
576
std::deque<uint256> txToRemove;
577
577
txToRemove.push_back (origTx.GetHash ());
578
578
if (fRecursive && !mapTx.count (origTx.GetHash ())) {
@@ -581,7 +581,7 @@ void CTxMemPool::remove(const CTransaction& origTx, std::list<CTransaction>& rem
581
581
// happen during chain re-orgs if origTx isn't re-accepted into
582
582
// the mempool for any reason.
583
583
for (unsigned int i = 0 ; i < origTx.vout .size (); i++) {
584
- auto it = mapNextTx.find (COutPoint (segwitLight ? origTx. GetBareTxid () : origTx. GetHash ( ), i));
584
+ auto it = mapNextTx.find (COutPoint (utxoHasher. GetUtxoHash ( origTx), i));
585
585
if (it == mapNextTx.end ())
586
586
continue ;
587
587
txToRemove.push_back (it->second .ptx ->GetHash ());
@@ -595,7 +595,7 @@ void CTxMemPool::remove(const CTransaction& origTx, std::list<CTransaction>& rem
595
595
const CTransaction& tx = mapTx[hash].GetTx ();
596
596
if (fRecursive ) {
597
597
for (unsigned int i = 0 ; i < tx.vout .size (); i++) {
598
- auto it = mapNextTx.find (COutPoint (segwitLight ? tx. GetBareTxid () : tx. GetHash ( ), i));
598
+ auto it = mapNextTx.find (COutPoint (utxoHasher. GetUtxoHash (tx ), i));
599
599
if (it == mapNextTx.end ())
600
600
continue ;
601
601
txToRemove.push_back (it->second .ptx ->GetHash ());
@@ -797,9 +797,18 @@ bool CTxMemPool::lookupOutpoint(const uint256& hash, CTransaction& result) const
797
797
mempool is not allowed in a time window "around" the fork, so that
798
798
this should be good enough. */
799
799
const ActivationState as (chainActive.Tip ());
800
- return as.IsActive (Fork::SegwitLight)
801
- ? lookupBareTxid (hash, result)
802
- : lookup (hash, result);
800
+ const TransactionUtxoHasher utxoHasher;
801
+
802
+ /* The TransactionUtxoHasher can only tell us the txid to use once we
803
+ know the transaction already. Thus we check both txid and bare txid
804
+ in our index; if one of them matches, we then cross-check with the
805
+ then-known transaction that it actually should hash to that UTXO. */
806
+ if (lookup (hash, result) && utxoHasher.GetUtxoHash (result) == hash)
807
+ return true ;
808
+ if (lookupBareTxid (hash, result) && utxoHasher.GetUtxoHash (result) == hash)
809
+ return true ;
810
+
811
+ return false ;
803
812
}
804
813
805
814
CFeeRate CTxMemPool::estimateFee (int nBlocks) const
@@ -890,11 +899,8 @@ bool CCoinsViewMemPool::GetCoins(const uint256& txid, CCoins& coins) const
890
899
891
900
bool CCoinsViewMemPool::HaveCoins (const uint256& txid) const
892
901
{
893
- const ActivationState as (chainActive.Tip ());
894
- const bool segwitLight = as.IsActive (Fork::SegwitLight);
895
- if (segwitLight && mempool.existsBareTxid (txid))
896
- return true ;
897
- if (!segwitLight && mempool.exists (txid))
902
+ CTransaction dummy;
903
+ if (mempool.lookupOutpoint (txid, dummy))
898
904
return true ;
899
905
900
906
return base->HaveCoins (txid);
0 commit comments