Skip to content

Commit fdcf0a1

Browse files
committed
fixup: bare hasher in txmempool
1 parent f92bc9a commit fdcf0a1

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

divi/src/txmempool.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ void CTxMemPool::remove(const CTransaction& origTx, std::list<CTransaction>& rem
572572
{
573573
LOCK(cs);
574574
const ActivationState as(chainActive.Tip());
575-
const bool segwitLight = as.IsActive(Fork::SegwitLight);
575+
const TransactionUtxoHasher utxoHasher;
576576
std::deque<uint256> txToRemove;
577577
txToRemove.push_back(origTx.GetHash());
578578
if (fRecursive && !mapTx.count(origTx.GetHash())) {
@@ -581,7 +581,7 @@ void CTxMemPool::remove(const CTransaction& origTx, std::list<CTransaction>& rem
581581
// happen during chain re-orgs if origTx isn't re-accepted into
582582
// the mempool for any reason.
583583
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));
585585
if (it == mapNextTx.end())
586586
continue;
587587
txToRemove.push_back(it->second.ptx->GetHash());
@@ -595,7 +595,7 @@ void CTxMemPool::remove(const CTransaction& origTx, std::list<CTransaction>& rem
595595
const CTransaction& tx = mapTx[hash].GetTx();
596596
if (fRecursive) {
597597
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));
599599
if (it == mapNextTx.end())
600600
continue;
601601
txToRemove.push_back(it->second.ptx->GetHash());
@@ -797,9 +797,18 @@ bool CTxMemPool::lookupOutpoint(const uint256& hash, CTransaction& result) const
797797
mempool is not allowed in a time window "around" the fork, so that
798798
this should be good enough. */
799799
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;
803812
}
804813

805814
CFeeRate CTxMemPool::estimateFee(int nBlocks) const
@@ -890,11 +899,8 @@ bool CCoinsViewMemPool::GetCoins(const uint256& txid, CCoins& coins) const
890899

891900
bool CCoinsViewMemPool::HaveCoins(const uint256& txid) const
892901
{
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))
898904
return true;
899905

900906
return base->HaveCoins(txid);

0 commit comments

Comments
 (0)