Skip to content

Commit d2ecd68

Browse files
committed
policy, refactor: Convert uint256 to Txid
1 parent f6c0d1d commit d2ecd68

File tree

8 files changed

+22
-23
lines changed

8 files changed

+22
-23
lines changed

src/policy/fees.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,16 +519,16 @@ void TxConfirmStats::removeTx(unsigned int entryHeight, unsigned int nBestSeenHe
519519
}
520520
}
521521

522-
bool CBlockPolicyEstimator::removeTx(uint256 hash)
522+
bool CBlockPolicyEstimator::removeTx(Txid hash)
523523
{
524524
LOCK(m_cs_fee_estimator);
525525
return _removeTx(hash, /*inBlock=*/false);
526526
}
527527

528-
bool CBlockPolicyEstimator::_removeTx(const uint256& hash, bool inBlock)
528+
bool CBlockPolicyEstimator::_removeTx(const Txid& hash, bool inBlock)
529529
{
530530
AssertLockHeld(m_cs_fee_estimator);
531-
std::map<uint256, TxStatsInfo>::iterator pos = mapMemPoolTxs.find(hash);
531+
std::map<Txid, TxStatsInfo>::iterator pos = mapMemPoolTxs.find(hash);
532532
if (pos != mapMemPoolTxs.end()) {
533533
feeStats->removeTx(pos->second.blockHeight, nBestSeenHeight, pos->second.bucketIndex, inBlock);
534534
shortStats->removeTx(pos->second.blockHeight, nBestSeenHeight, pos->second.bucketIndex, inBlock);

src/policy/fees.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class CBlockPolicyEstimator : public CValidationInterface
212212
EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator);
213213

214214
/** Remove a transaction from the mempool tracking stats for non BLOCK removal reasons*/
215-
bool removeTx(uint256 hash)
215+
bool removeTx(Txid hash)
216216
EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator);
217217

218218
/** DEPRECATED. Return a feerate estimate */
@@ -287,7 +287,7 @@ class CBlockPolicyEstimator : public CValidationInterface
287287
};
288288

289289
// map of txids to information about that transaction
290-
std::map<uint256, TxStatsInfo> mapMemPoolTxs GUARDED_BY(m_cs_fee_estimator);
290+
std::map<Txid, TxStatsInfo> mapMemPoolTxs GUARDED_BY(m_cs_fee_estimator);
291291

292292
/** Classes to track historical data on transaction confirmations */
293293
std::unique_ptr<TxConfirmStats> feeStats PT_GUARDED_BY(m_cs_fee_estimator);
@@ -315,7 +315,7 @@ class CBlockPolicyEstimator : public CValidationInterface
315315
unsigned int MaxUsableEstimate() const EXCLUSIVE_LOCKS_REQUIRED(m_cs_fee_estimator);
316316

317317
/** A non-thread-safe helper for the removeTx function */
318-
bool _removeTx(const uint256& hash, bool inBlock)
318+
bool _removeTx(const Txid& hash, bool inBlock)
319319
EXCLUSIVE_LOCKS_REQUIRED(m_cs_fee_estimator);
320320
};
321321

src/policy/packages.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/** IsTopoSortedPackage where a set of txids has been pre-populated. The set is assumed to be correct and
1818
* is mutated within this function (even if return value is false). */
19-
bool IsTopoSortedPackage(const Package& txns, std::unordered_set<uint256, SaltedTxidHasher>& later_txids)
19+
bool IsTopoSortedPackage(const Package& txns, std::unordered_set<Txid, SaltedTxidHasher>& later_txids)
2020
{
2121
// Avoid misusing this function: later_txids should contain the txids of txns.
2222
Assume(txns.size() == later_txids.size());
@@ -42,7 +42,7 @@ bool IsTopoSortedPackage(const Package& txns, std::unordered_set<uint256, Salted
4242

4343
bool IsTopoSortedPackage(const Package& txns)
4444
{
45-
std::unordered_set<uint256, SaltedTxidHasher> later_txids;
45+
std::unordered_set<Txid, SaltedTxidHasher> later_txids;
4646
std::transform(txns.cbegin(), txns.cend(), std::inserter(later_txids, later_txids.end()),
4747
[](const auto& tx) { return tx->GetHash(); });
4848

@@ -91,7 +91,7 @@ bool IsWellFormedPackage(const Package& txns, PackageValidationState& state, boo
9191
return state.Invalid(PackageValidationResult::PCKG_POLICY, "package-too-large");
9292
}
9393

94-
std::unordered_set<uint256, SaltedTxidHasher> later_txids;
94+
std::unordered_set<Txid, SaltedTxidHasher> later_txids;
9595
std::transform(txns.cbegin(), txns.cend(), std::inserter(later_txids, later_txids.end()),
9696
[](const auto& tx) { return tx->GetHash(); });
9797

@@ -123,7 +123,7 @@ bool IsChildWithParents(const Package& package)
123123

124124
// The package is expected to be sorted, so the last transaction is the child.
125125
const auto& child = package.back();
126-
std::unordered_set<uint256, SaltedTxidHasher> input_txids;
126+
std::unordered_set<Txid, SaltedTxidHasher> input_txids;
127127
std::transform(child->vin.cbegin(), child->vin.cend(),
128128
std::inserter(input_txids, input_txids.end()),
129129
[](const auto& input) { return input.prevout.hash; });
@@ -136,7 +136,7 @@ bool IsChildWithParents(const Package& package)
136136
bool IsChildWithParentsTree(const Package& package)
137137
{
138138
if (!IsChildWithParents(package)) return false;
139-
std::unordered_set<uint256, SaltedTxidHasher> parent_txids;
139+
std::unordered_set<Txid, SaltedTxidHasher> parent_txids;
140140
std::transform(package.cbegin(), package.cend() - 1, std::inserter(parent_txids, parent_txids.end()),
141141
[](const auto& ptx) { return ptx->GetHash(); });
142142
// Each parent must not have an input who is one of the other parents.

src/policy/rbf.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ std::optional<std::string> GetEntriesForConflicts(const CTransaction& tx,
6262
CTxMemPool::setEntries& all_conflicts)
6363
{
6464
AssertLockHeld(pool.cs);
65-
const uint256 txid = tx.GetHash();
6665
uint64_t nConflictingCount = 0;
6766
for (const auto& mi : iters_conflicting) {
6867
nConflictingCount += mi->GetCountWithDescendants();
@@ -72,7 +71,7 @@ std::optional<std::string> GetEntriesForConflicts(const CTransaction& tx,
7271
// times), but we just want to be conservative to avoid doing too much work.
7372
if (nConflictingCount > MAX_REPLACEMENT_CANDIDATES) {
7473
return strprintf("rejecting replacement %s; too many potential replacements (%d > %d)",
75-
txid.ToString(),
74+
tx.GetHash().ToString(),
7675
nConflictingCount,
7776
MAX_REPLACEMENT_CANDIDATES);
7877
}
@@ -89,7 +88,7 @@ std::optional<std::string> HasNoNewUnconfirmed(const CTransaction& tx,
8988
const CTxMemPool::setEntries& iters_conflicting)
9089
{
9190
AssertLockHeld(pool.cs);
92-
std::set<uint256> parents_of_conflicts;
91+
std::set<Txid> parents_of_conflicts;
9392
for (const auto& mi : iters_conflicting) {
9493
for (const CTxIn& txin : mi->GetTx().vin) {
9594
parents_of_conflicts.insert(txin.prevout.hash);
@@ -118,7 +117,7 @@ std::optional<std::string> HasNoNewUnconfirmed(const CTransaction& tx,
118117

119118
std::optional<std::string> EntriesAndTxidsDisjoint(const CTxMemPool::setEntries& ancestors,
120119
const std::set<Txid>& direct_conflicts,
121-
const uint256& txid)
120+
const Txid& txid)
122121
{
123122
for (CTxMemPool::txiter ancestorIt : ancestors) {
124123
const Txid& hashAncestor = ancestorIt->GetTx().GetHash();
@@ -133,7 +132,7 @@ std::optional<std::string> EntriesAndTxidsDisjoint(const CTxMemPool::setEntries&
133132

134133
std::optional<std::string> PaysMoreThanConflicts(const CTxMemPool::setEntries& iters_conflicting,
135134
CFeeRate replacement_feerate,
136-
const uint256& txid)
135+
const Txid& txid)
137136
{
138137
for (const auto& mi : iters_conflicting) {
139138
// Don't allow the replacement to reduce the feerate of the mempool.
@@ -161,7 +160,7 @@ std::optional<std::string> PaysForRBF(CAmount original_fees,
161160
CAmount replacement_fees,
162161
size_t replacement_vsize,
163162
CFeeRate relay_fee,
164-
const uint256& txid)
163+
const Txid& txid)
165164
{
166165
// Rule #3: The replacement fees must be greater than or equal to fees of the
167166
// transactions it replaces, otherwise the bandwidth used by those conflicting transactions

src/policy/rbf.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ std::optional<std::string> HasNoNewUnconfirmed(const CTransaction& tx, const CTx
9090
*/
9191
std::optional<std::string> EntriesAndTxidsDisjoint(const CTxMemPool::setEntries& ancestors,
9292
const std::set<Txid>& direct_conflicts,
93-
const uint256& txid);
93+
const Txid& txid);
9494

9595
/** Check that the feerate of the replacement transaction(s) is higher than the feerate of each
9696
* of the transactions in iters_conflicting.
9797
* @param[in] iters_conflicting The set of mempool entries.
9898
* @returns error message if fees insufficient, otherwise std::nullopt.
9999
*/
100100
std::optional<std::string> PaysMoreThanConflicts(const CTxMemPool::setEntries& iters_conflicting,
101-
CFeeRate replacement_feerate, const uint256& txid);
101+
CFeeRate replacement_feerate, const Txid& txid);
102102

103103
/** The replacement transaction must pay more fees than the original transactions. The additional
104104
* fees must pay for the replacement's bandwidth at or above the incremental relay feerate.
@@ -113,7 +113,7 @@ std::optional<std::string> PaysForRBF(CAmount original_fees,
113113
CAmount replacement_fees,
114114
size_t replacement_vsize,
115115
CFeeRate relay_fee,
116-
const uint256& txid);
116+
const Txid& txid);
117117

118118
/**
119119
* The replacement transaction must improve the feerate diagram of the mempool.

src/test/fuzz/policy_estimator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ FUZZ_TARGET(policy_estimator, .init = initialize_policy_estimator)
8585
block_policy_estimator.processBlock(txs, current_height);
8686
},
8787
[&] {
88-
(void)block_policy_estimator.removeTx(ConsumeUInt256(fuzzed_data_provider));
88+
(void)block_policy_estimator.removeTx(Txid::FromUint256(ConsumeUInt256(fuzzed_data_provider)));
8989
},
9090
[&] {
9191
block_policy_estimator.FlushUnconfirmed();

src/test/rbf_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ BOOST_FIXTURE_TEST_CASE(rbf_helper_functions, TestChain100Setup)
196196
entry5_low, entry6_low_prioritised, entry7_high, entry8_high};
197197
CTxMemPool::setEntries empty_set;
198198

199-
const auto unused_txid{GetRandHash()};
199+
const auto unused_txid = Txid::FromUint256(GetRandHash());
200200

201201
// Tests for PaysMoreThanConflicts
202202
// These tests use feerate, not absolute fee.

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ bool MemPoolAccept::ReplacementChecks(Workspace& ws)
10881088
AssertLockHeld(m_pool.cs);
10891089

10901090
const CTransaction& tx = *ws.m_ptx;
1091-
const uint256& hash = ws.m_hash;
1091+
const Txid& hash = ws.m_hash;
10921092
TxValidationState& state = ws.m_state;
10931093

10941094
CFeeRate newFeeRate(ws.m_modified_fees, ws.m_vsize);

0 commit comments

Comments
 (0)