Skip to content

Commit 158623b

Browse files
committed
[refactor] change Workspace::m_conflicts and adjacent funcs/structs to use Txid
It's preferable to use type-safe transaction identifiers to avoid confusing txid and wtxid. The next commit will add a reference to this set; we use this opportunity to change it to Txid ahead of time instead of adding new uses of uint256.
1 parent 60f6773 commit 158623b

File tree

6 files changed

+7
-9
lines changed

6 files changed

+7
-9
lines changed

src/policy/rbf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ std::optional<std::string> HasNoNewUnconfirmed(const CTransaction& tx,
115115
}
116116

117117
std::optional<std::string> EntriesAndTxidsDisjoint(const CTxMemPool::setEntries& ancestors,
118-
const std::set<uint256>& direct_conflicts,
118+
const std::set<Txid>& direct_conflicts,
119119
const uint256& txid)
120120
{
121121
for (CTxMemPool::txiter ancestorIt : ancestors) {
122-
const uint256& hashAncestor = ancestorIt->GetTx().GetHash();
122+
const Txid& hashAncestor = ancestorIt->GetTx().GetHash();
123123
if (direct_conflicts.count(hashAncestor)) {
124124
return strprintf("%s spends conflicting transaction %s",
125125
txid.ToString(),

src/policy/rbf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ std::optional<std::string> HasNoNewUnconfirmed(const CTransaction& tx, const CTx
8080
* @returns error message if the sets intersect, std::nullopt if they are disjoint.
8181
*/
8282
std::optional<std::string> EntriesAndTxidsDisjoint(const CTxMemPool::setEntries& ancestors,
83-
const std::set<uint256>& direct_conflicts,
83+
const std::set<Txid>& direct_conflicts,
8484
const uint256& txid);
8585

8686
/** Check that the feerate of the replacement transaction(s) is higher than the feerate of each

src/test/rbf_tests.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ BOOST_FIXTURE_TEST_CASE(rbf_helper_functions, TestChain100Setup)
135135
// Tests for EntriesAndTxidsDisjoint
136136
BOOST_CHECK(EntriesAndTxidsDisjoint(empty_set, {tx1->GetHash()}, unused_txid) == std::nullopt);
137137
BOOST_CHECK(EntriesAndTxidsDisjoint(set_12_normal, {tx3->GetHash()}, unused_txid) == std::nullopt);
138-
// EntriesAndTxidsDisjoint uses txids, not wtxids.
139-
BOOST_CHECK(EntriesAndTxidsDisjoint({entry2}, {tx2->GetWitnessHash()}, unused_txid) == std::nullopt);
140138
BOOST_CHECK(EntriesAndTxidsDisjoint({entry2}, {tx2->GetHash()}, unused_txid).has_value());
141139
BOOST_CHECK(EntriesAndTxidsDisjoint(set_12_normal, {tx1->GetHash()}, unused_txid).has_value());
142140
BOOST_CHECK(EntriesAndTxidsDisjoint(set_12_normal, {tx2->GetHash()}, unused_txid).has_value());

src/txmempool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
454454
cachedInnerUsage += entry.DynamicMemoryUsage();
455455

456456
const CTransaction& tx = newit->GetTx();
457-
std::set<uint256> setParentTransactions;
457+
std::set<Txid> setParentTransactions;
458458
for (unsigned int i = 0; i < tx.vin.size(); i++) {
459459
mapNextTx.insert(std::make_pair(&tx.vin[i].prevout, &tx));
460460
setParentTransactions.insert(tx.vin[i].prevout.hash);
@@ -969,7 +969,7 @@ std::optional<CTxMemPool::txiter> CTxMemPool::GetIter(const uint256& txid) const
969969
return std::nullopt;
970970
}
971971

972-
CTxMemPool::setEntries CTxMemPool::GetIterSet(const std::set<uint256>& hashes) const
972+
CTxMemPool::setEntries CTxMemPool::GetIterSet(const std::set<Txid>& hashes) const
973973
{
974974
CTxMemPool::setEntries ret;
975975
for (const auto& h : hashes) {

src/txmempool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ class CTxMemPool
522522
/** Translate a set of hashes into a set of pool iterators to avoid repeated lookups.
523523
* Does not require that all of the hashes correspond to actual transactions in the mempool,
524524
* only returns the ones that exist. */
525-
setEntries GetIterSet(const std::set<uint256>& hashes) const EXCLUSIVE_LOCKS_REQUIRED(cs);
525+
setEntries GetIterSet(const std::set<Txid>& hashes) const EXCLUSIVE_LOCKS_REQUIRED(cs);
526526

527527
/** Translate a list of hashes into a list of mempool iterators to avoid repeated lookups.
528528
* The nth element in txids becomes the nth element in the returned vector. If any of the txids

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ class MemPoolAccept
582582
struct Workspace {
583583
explicit Workspace(const CTransactionRef& ptx) : m_ptx(ptx), m_hash(ptx->GetHash()) {}
584584
/** Txids of mempool transactions that this transaction directly conflicts with. */
585-
std::set<uint256> m_conflicts;
585+
std::set<Txid> m_conflicts;
586586
/** Iterators to mempool entries that this transaction directly conflicts with. */
587587
CTxMemPool::setEntries m_iters_conflicting;
588588
/** Iterators to all mempool entries that would be replaced by this transaction, including

0 commit comments

Comments
 (0)