Skip to content

Commit aef3b6e

Browse files
committed
Remove transaction equality in favor of explicit hash equality checks.
1 parent 9974be7 commit aef3b6e

File tree

5 files changed

+9
-19
lines changed

5 files changed

+9
-19
lines changed

src/gtest/test_checktransaction.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ TEST(ChecktransactionTests, OverwinterConstructors) {
668668
EXPECT_EQ(tx2.fOverwintered, mtx.fOverwintered);
669669
EXPECT_EQ(tx2.nVersionGroupId, mtx.nVersionGroupId);
670670
EXPECT_EQ(tx2.nExpiryHeight, mtx.nExpiryHeight);
671-
EXPECT_TRUE(tx2 == tx);
671+
EXPECT_TRUE(tx2.GetHash() == tx.GetHash());
672672
}
673673

674674
TEST(ChecktransactionTests, OverwinterSerialization) {

src/primitives/transaction.h

-10
Original file line numberDiff line numberDiff line change
@@ -981,16 +981,6 @@ class CTransaction
981981
return (vin.size() == 1 && vin[0].prevout.IsNull());
982982
}
983983

984-
friend bool operator==(const CTransaction& a, const CTransaction& b)
985-
{
986-
return a.wtxid.hash == b.wtxid.hash;
987-
}
988-
989-
friend bool operator!=(const CTransaction& a, const CTransaction& b)
990-
{
991-
return a.wtxid.hash != b.wtxid.hash;
992-
}
993-
994984
std::string ToString() const;
995985
};
996986

src/test/serialize_tests.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CSerializeMethodsTestSingle
6565
boolval == rhs.boolval && \
6666
stringval == rhs.stringval && \
6767
strcmp(charstrval, rhs.charstrval) == 0 && \
68-
txval == rhs.txval;
68+
txval.GetHash() == rhs.txval.GetHash();
6969
}
7070
};
7171

@@ -300,8 +300,8 @@ static bool isCanonicalException(const std::ios_base::failure& ex)
300300

301301
// The string returned by what() can be different for different platforms.
302302
// Instead of directly comparing the ex.what() with an expected string,
303-
// create an instance of exception to see if ex.what() matches
304-
// the expected explanatory string returned by the exception instance.
303+
// create an instance of exception to see if ex.what() matches
304+
// the expected explanatory string returned by the exception instance.
305305
return strcmp(expectedException.what(), ex.what()) == 0;
306306
}
307307

src/txmempool.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
416416
std::map<COutPoint, CInPoint>::iterator it = mapNextTx.find(txin.prevout);
417417
if (it != mapNextTx.end()) {
418418
const CTransaction &txConflict = *it->second.ptx;
419-
if (txConflict != tx)
419+
if (txConflict.GetHash() != tx.GetHash())
420420
{
421421
remove(txConflict, removed, true);
422422
}
@@ -428,7 +428,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
428428
std::map<uint256, const CTransaction*>::iterator it = mapSproutNullifiers.find(nf);
429429
if (it != mapSproutNullifiers.end()) {
430430
const CTransaction &txConflict = *it->second;
431-
if (txConflict != tx) {
431+
if (txConflict.GetHash() != tx.GetHash()) {
432432
remove(txConflict, removed, true);
433433
}
434434
}
@@ -438,7 +438,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
438438
std::map<uint256, const CTransaction*>::iterator it = mapSaplingNullifiers.find(spendDescription.nullifier);
439439
if (it != mapSaplingNullifiers.end()) {
440440
const CTransaction &txConflict = *it->second;
441-
if (txConflict != tx) {
441+
if (txConflict.GetHash() != tx.GetHash()) {
442442
remove(txConflict, removed, true);
443443
}
444444
}
@@ -447,7 +447,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
447447
std::map<uint256, const CTransaction*>::iterator it = mapOrchardNullifiers.find(orchardNullifier);
448448
if (it != mapOrchardNullifiers.end()) {
449449
const CTransaction &txConflict = *it->second;
450-
if (txConflict != tx) {
450+
if (txConflict.GetHash() != tx.GetHash()) {
451451
remove(txConflict, removed, true);
452452
}
453453
}

src/wallet/wallet.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6482,7 +6482,7 @@ void CMerkleTx::SetMerkleBranch(const CBlock& block)
64826482

64836483
// Locate the transaction
64846484
for (nIndex = 0; nIndex < (int)block.vtx.size(); nIndex++)
6485-
if (block.vtx[nIndex] == *(CTransaction*)this)
6485+
if (block.vtx[nIndex].GetHash() == this->GetHash())
64866486
break;
64876487
if (nIndex == (int)block.vtx.size())
64886488
{

0 commit comments

Comments
 (0)