Skip to content

Commit b2b3619

Browse files
committed
Implement CTransaction::IsEquivalentTo(...)
Define CTransaction::IsEquivalentTo(const CTransaction& tx) True if only scriptSigs are different. In other words, true if the two transactions are malleability clones. In other words, true if the two transactions have the same effect on the outside universe. In the wallet, only SyncMetaData for equivalent transactions.
1 parent c8a1350 commit b2b3619

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/primitives/transaction.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) {
8787
return *this;
8888
}
8989

90+
bool CTransaction::IsEquivalentTo(const CTransaction& tx) const
91+
{
92+
CMutableTransaction tx1 = *this;
93+
CMutableTransaction tx2 = tx;
94+
for (unsigned int i = 0; i < tx1.vin.size(); i++) tx1.vin[i].scriptSig = CScript();
95+
for (unsigned int i = 0; i < tx2.vin.size(); i++) tx2.vin[i].scriptSig = CScript();
96+
return CTransaction(tx1) == CTransaction(tx2);
97+
}
98+
9099
CAmount CTransaction::GetValueOut() const
91100
{
92101
CAmount nValueOut = 0;

src/primitives/transaction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ class CTransaction
222222
return hash;
223223
}
224224

225+
// True if only scriptSigs are different
226+
bool IsEquivalentTo(const CTransaction& tx) const;
227+
225228
// Return sum of txouts.
226229
CAmount GetValueOut() const;
227230
// GetValueIn() is a method on CCoinsViewCache, because

src/wallet/wallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ void CWallet::SyncMetaData(pair<TxSpends::iterator, TxSpends::iterator> range)
417417
const uint256& hash = it->second;
418418
CWalletTx* copyTo = &mapWallet[hash];
419419
if (copyFrom == copyTo) continue;
420+
if (!copyFrom->IsEquivalentTo(*copyTo)) continue;
420421
copyTo->mapValue = copyFrom->mapValue;
421422
copyTo->vOrderForm = copyFrom->vOrderForm;
422423
// fTimeReceivedIsTxTime not copied on purpose

0 commit comments

Comments
 (0)