mempool, refactor: Convert uint256 to Txid
What changed, and why it matters
This commit is a straightforward internal code cleanup in Bitcoin Core. It replaces the generic 256-bit hash type (uint256) with more specific transaction ID types (Txid and Wtxid) in the memory pool and related code. There is no change to network rules, consensus logic, or user-visible behavior, and no security vulnerability is introduced or fixed.
No security action required. Treat as a normal maintainability/type-safety refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors the mempool and nearby modules to use the strongly-typed Txid (and Wtxid where appropriate) instead of the generic uint256 for transaction identifiers. This touches function signatures, container key types, and local variables in interfaces/chain.h, net_processing.cpp, node/interfaces.cpp, node/mempool_persist.cpp, node/transaction.{cpp,h}, rest.cpp, txmempool.{cpp,h}, validation.cpp, and several test files. The changes are type-only: for example, std::set
Changed components
src/txmempool.cppsrc/txmempool.hsrc/net_processing.cppsrc/node/interfaces.cppsrc/node/mempool_persist.cppsrc/node/transaction.cppsrc/node/transaction.hsrc/rest.cppsrc/validation.cppsrc/interfaces/chain.htest filesInspect captured patch +65 / −69
diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h
index 56716ec6..82bfdb9f 100644
--- a/src/interfaces/chain.h
+++ b/src/interfaces/chain.h
@@ -211,7 +211,7 @@ public:
virtual bool isInMempool(const Txid& txid) = 0;
//! Check if transaction has descendants in mempool.
- virtual bool hasDescendantsInMempool(const uint256& txid) = 0;
+ virtual bool hasDescendantsInMempool(const Txid& txid) = 0;
//! Transaction is added to memory pool, if the transaction fee is below the
//! amount specified by max_tx_fee, and broadcast to all peers if relay is set to true.
@@ -222,7 +222,7 @@ public:
std::string& err_string) = 0;
//! Calculate mempool ancestor and descendant counts for the given transaction.
- virtual void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize = nullptr, CAmount* ancestorfees = nullptr) = 0;
+ virtual void getTransactionAncestry(const Txid& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize = nullptr, CAmount* ancestorfees = nullptr) = 0;
//! For each outpoint, calculate the fee-bumping cost to spend this outpoint at the specified
// feerate, including bumping its ancestors. For example, if the target feerate is 10sat/vbyte
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index ba919fac..546e14b8 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -1577,13 +1577,13 @@ void PeerManagerImpl::InitializeNode(const CNode& node, ServiceFlags our_service
void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
{
- std::set<uint256> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
+ std::set<Txid> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
for (const auto& txid : unbroadcast_txids) {
CTransactionRef tx = m_mempool.get(txid);
if (tx != nullptr) {
- RelayTransaction(Txid::FromUint256(txid), tx->GetWitnessHash());
+ RelayTransaction(txid, tx->GetWitnessHash());
} else {
m_mempool.RemoveUnbroadcastTx(txid, true);
}
diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp
index 62172930..eeee4159 100644
--- a/src/node/interfaces.cpp
+++ b/src/node/interfaces.cpp
@@ -673,11 +673,11 @@ public:
LOCK(m_node.mempool->cs);
return m_node.mempool->exists(txid);
}
- bool hasDescendantsInMempool(const uint256& txid) override
+ bool hasDescendantsInMempool(const Txid& txid) override
{
if (!m_node.mempool) return false;
LOCK(m_node.mempool->cs);
- const auto entry{m_node.mempool->GetEntry(Txid::FromUint256(txid))};
+ const auto entry{m_node.mempool->GetEntry(txid)};
if (entry == nullptr) return false;
return entry->GetCountWithDescendants() > 1;
}
@@ -692,7 +692,7 @@ public:
// that Chain clients do not need to know about.
return TransactionError::OK == err;
}
- void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize, CAmount* ancestorfees) override
+ void getTransactionAncestry(const Txid& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize, CAmount* ancestorfees) override
{
ancestors = descendants = 0;
if (!m_node.mempool) return;
diff --git a/src/node/mempool_persist.cpp b/src/node/mempool_persist.cpp
index 5b0f80be..19819a3a 100644
--- a/src/node/mempool_persist.cpp
+++ b/src/node/mempool_persist.cpp
@@ -122,7 +122,7 @@ bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active
if (active_chainstate.m_chainman.m_interrupt)
return false;
}
- std::map<uint256, CAmount> mapDeltas;
+ std::map<Txid, CAmount> mapDeltas;
file >> mapDeltas;
if (opts.apply_fee_delta_priority) {
@@ -131,7 +131,7 @@ bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active
}
}
- std::set<uint256> unbroadcast_txids;
+ std::set<Txid> unbroadcast_txids;
file >> unbroadcast_txids;
if (opts.apply_unbroadcast_set) {
unbroadcast = unbroadcast_txids.size();
@@ -154,9 +154,9 @@ bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path, FopenFn mock
{
auto start = SteadyClock::now();
- std::map<uint256, CAmount> mapDeltas;
+ std::map<Txid, CAmount> mapDeltas;
std::vector<TxMempoolInfo> vinfo;
- std::set<uint256> unbroadcast_txids;
+ std::set<Txid> unbroadcast_txids;
static Mutex dump_mutex;
LOCK(dump_mutex);
diff --git a/src/node/transaction.cpp b/src/node/transaction.cpp
index 9162557b..7bb92872 100644
--- a/src/node/transaction.cpp
+++ b/src/node/transaction.cpp
@@ -123,7 +123,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
return TransactionError::OK;
}
-CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, uint256& hashBlock, const BlockManager& blockman)
+CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const Txid& hash, uint256& hashBlock, const BlockManager& blockman)
{
if (mempool && !block_index) {
CTransactionRef ptx = mempool->get(hash);
diff --git a/src/node/transaction.h b/src/node/transaction.h
index 5f524f4e..2a411581 100644
--- a/src/node/transaction.h
+++ b/src/node/transaction.h
@@ -63,7 +63,7 @@ static const CAmount DEFAULT_MAX_BURN_AMOUNT{0};
* @param[out] hashBlock The block hash, if the tx was found via -txindex or block_index
* @returns The tx if found, otherwise nullptr
*/
-CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, uint256& hashBlock, const BlockManager& blockman);
+CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const Txid& hash, uint256& hashBlock, const BlockManager& blockman);
} // namespace node
#endif // BITCOIN_NODE_TRANSACTION_H
diff --git a/src/rest.cpp b/src/rest.cpp
index e32b4c38..7750bdc8 100644
--- a/src/rest.cpp
+++ b/src/rest.cpp
@@ -817,7 +817,7 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
std::string hashStr;
const RESTResponseFormat rf = ParseDataFormat(hashStr, uri_part);
- auto hash{uint256::FromHex(hashStr)};
+ auto hash{Txid::FromHex(hashStr)};
if (!hash) {
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
}
diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp
index d40a0a94..b3d21096 100644
--- a/src/test/blockencodings_tests.cpp
+++ b/src/test/blockencodings_tests.cpp
@@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest)
AddToMempool(pool, entry.FromTx(block.vtx[2]));
BOOST_CHECK_EQUAL(pool.get(block.vtx[2]->GetHash()).use_count(), SHARED_TX_OFFSET + 0);
- uint256 txhash;
+ Txid txhash;
// Test with pre-forwarding tx 1, but not coinbase
{
@@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest)
AddToMempool(pool, entry.FromTx(block.vtx[1]));
BOOST_CHECK_EQUAL(pool.get(block.vtx[1]->GetHash()).use_count(), SHARED_TX_OFFSET + 0);
- uint256 txhash;
+ Txid txhash;
// Test with pre-forwarding coinbase + tx 2 with tx 1 in mempool
{
diff --git a/src/test/fuzz/package_eval.cpp b/src/test/fuzz/package_eval.cpp
index aa73fcdd..23ea9d1f 100644
--- a/src/test/fuzz/package_eval.cpp
+++ b/src/test/fuzz/package_eval.cpp
@@ -314,7 +314,7 @@ FUZZ_TARGET(ephemeral_package_eval, .init = initialize_tx_pool)
if (tx_pool.exists(txid)) {
const auto tx_info{tx_pool.info(txid)};
if (GetDust(*tx_info.tx, tx_pool.m_opts.dust_relay_feerate).empty()) {
- tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
+ tx_pool.PrioritiseTransaction(txid, delta);
}
}
}
@@ -477,7 +477,7 @@ FUZZ_TARGET(tx_package_eval, .init = initialize_tx_pool)
txs.back()->GetHash() :
PickValue(fuzzed_data_provider, mempool_outpoints).hash;
const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
- tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
+ tx_pool.PrioritiseTransaction(txid, delta);
}
// Remember all added transactions
diff --git a/src/test/fuzz/rbf.cpp b/src/test/fuzz/rbf.cpp
index db8682e2..300f31d4 100644
--- a/src/test/fuzz/rbf.cpp
+++ b/src/test/fuzz/rbf.cpp
@@ -160,7 +160,7 @@ FUZZ_TARGET(package_rbf, .init = initialize_package_rbf)
}
if (fuzzed_data_provider.ConsumeBool()) {
- pool.PrioritiseTransaction(mempool_txs.back().GetHash().ToUint256(), fuzzed_data_provider.ConsumeIntegralInRange<int32_t>(-100000, 100000));
+ pool.PrioritiseTransaction(mempool_txs.back().GetHash(), fuzzed_data_provider.ConsumeIntegralInRange<int32_t>(-100000, 100000));
}
}
diff --git a/src/test/fuzz/tx_pool.cpp b/src/test/fuzz/tx_pool.cpp
index ea65700c..4245d3e1 100644
--- a/src/test/fuzz/tx_pool.cpp
+++ b/src/test/fuzz/tx_pool.cpp
@@ -288,7 +288,7 @@ FUZZ_TARGET(tx_pool_standard, .init = initialize_tx_pool)
tx->GetHash() :
PickValue(fuzzed_data_provider, outpoints_rbf).hash;
const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
- tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
+ tx_pool.PrioritiseTransaction(txid, delta);
}
// Remember all removed and added transactions
@@ -409,7 +409,7 @@ FUZZ_TARGET(tx_pool, .init = initialize_tx_pool)
mut_tx.GetHash() :
PickValue(fuzzed_data_provider, txids);
const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
- tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
+ tx_pool.PrioritiseTransaction(txid, delta);
}
const auto tx = MakeTransactionRef(mut_tx);
diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp
index 9207f1bf..ffdf7a4d 100644
--- a/src/test/miner_tests.cpp
+++ b/src/test/miner_tests.cpp
@@ -596,7 +596,7 @@ void MinerTestingSetup::TestPrioritisedMining(const CScript& scriptPubKey, const
tx.vin[0].scriptSig = CScript() << OP_1;
tx.vout.resize(1);
tx.vout[0].nValue = 5000000000LL; // 0 fee
- uint256 hashFreePrioritisedTx = tx.GetHash();
+ Txid hashFreePrioritisedTx = tx.GetHash();
AddToMempool(tx_mempool, entry.Fee(0).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
tx_mempool.PrioritiseTransaction(hashFreePrioritisedTx, 5 * COIN);
diff --git a/src/test/policyestimator_tests.cpp b/src/test/policyestimator_tests.cpp
index f767cd42..bbdd815f 100644
--- a/src/test/policyestimator_tests.cpp
+++ b/src/test/policyestimator_tests.cpp
@@ -37,7 +37,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
// added to the mempool by their associate fee
// txHashes[j] is populated with transactions either of
// fee = basefee * (j+1)
- std::vector<uint256> txHashes[10];
+ std::vector<Txid> txHashes[10];
// Create a transaction template
CScript garbage;
@@ -77,8 +77,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
/*has_no_mempool_parents=*/true)};
m_node.validation_signals->TransactionAddedToMempool(tx_info, mpool.GetAndIncrementSequence());
}
- uint256 hash = tx.GetHash();
- txHashes[j].push_back(hash);
+ txHashes[j].push_back(tx.GetHash());
}
}
//Create blocks where higher fee txs are included more often
@@ -178,8 +177,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
/*has_no_mempool_parents=*/true)};
m_node.validation_signals->TransactionAddedToMempool(tx_info, mpool.GetAndIncrementSequence());
}
- uint256 hash = tx.GetHash();
- txHashes[j].push_back(hash);
+ txHashes[j].push_back(tx.GetHash());
}
}
{
@@ -242,8 +240,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
/*has_no_mempool_parents=*/true)};
m_node.validation_signals->TransactionAddedToMempool(tx_info, mpool.GetAndIncrementSequence());
}
- uint256 hash = tx.GetHash();
- CTransactionRef ptx = mpool.get(hash);
+ CTransactionRef ptx = mpool.get(tx.GetHash());
if (ptx)
block.push_back(ptx);
diff --git a/src/txmempool.cpp b/src/txmempool.cpp
index d19d0a47..6bb910e3 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -55,7 +55,7 @@ bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp)
}
void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendants,
- const std::set<uint256>& setExclude, std::set<uint256>& descendants_to_remove)
+ const std::set<Txid>& setExclude, std::set<Txid>& descendants_to_remove)
{
CTxMemPoolEntry::Children stageEntries, descendants;
stageEntries = updateIt->GetMemPoolChildrenConst();
@@ -105,7 +105,7 @@ void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendan
mapTx.modify(updateIt, [=](CTxMemPoolEntry& e) { e.UpdateDescendantState(modifySize, modifyFee, modifyCount); });
}
-void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256>& vHashesToUpdate)
+void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<Txid>& vHashesToUpdate)
{
AssertLockHeld(cs);
// For each entry in vHashesToUpdate, store the set of in-mempool, but not
@@ -115,29 +115,29 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256>& vHashes
// Use a set for lookups into vHashesToUpdate (these entries are already
// accounted for in the state of their ancestors)
- std::set<uint256> setAlreadyIncluded(vHashesToUpdate.begin(), vHashesToUpdate.end());
+ std::set<Txid> setAlreadyIncluded(vHashesToUpdate.begin(), vHashesToUpdate.end());
- std::set<uint256> descendants_to_remove;
+ std::set<Txid> descendants_to_remove;
// Iterate in reverse, so that whenever we are looking at a transaction
// we are sure that all in-mempool descendants have already been processed.
// This maximizes the benefit of the descendant cache and guarantees that
// CTxMemPoolEntry::m_children will be updated, an assumption made in
// UpdateForDescendants.
- for (const uint256& hash : vHashesToUpdate | std::views::reverse) {
+ for (const Txid& hash : vHashesToUpdate | std::views::reverse) {
// calculate children from mapNextTx
txiter it = mapTx.find(hash);
if (it == mapTx.end()) {
continue;
}
- auto iter = mapNextTx.lower_bound(COutPoint(Txid::FromUint256(hash), 0));
+ auto iter = mapNextTx.lower_bound(COutPoint(hash, 0));
// First calculate the children, and update CTxMemPoolEntry::m_children to
// include them, and update their CTxMemPoolEntry::m_parents to include this tx.
// we cache the in-mempool children to avoid duplicate updates
{
WITH_FRESH_EPOCH(m_epoch);
for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
- const uint256 &childHash = iter->second->GetHash();
+ const Txid &childHash = iter->second->GetHash();
txiter childIter = mapTx.find(childHash);
assert(childIter != mapTx.end());
// We can skip updating entries we've encountered before or that
@@ -154,7 +154,7 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256>& vHashes
for (const auto& txid : descendants_to_remove) {
// This txid may have been removed already in a prior call to removeRecursive.
// Therefore we ensure it is not yet removed already.
- if (const std::optional<txiter> txiter = GetIter(Txid::FromUint256(txid))) {
+ if (const std::optional<txiter> txiter = GetIter(txid)) {
removeRecursive((*txiter)->GetTx(), MemPoolRemovalReason::SIZELIMIT);
}
}
@@ -780,12 +780,11 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei
for (const auto& input: tx.vin) mempoolDuplicate.SpendCoin(input.prevout);
AddCoins(mempoolDuplicate, tx, std::numeric_limits<int>::max());
}
- for (auto it = mapNextTx.cbegin(); it != mapNextTx.cend(); it++) {
- uint256 hash = it->second->GetHash();
- indexed_transaction_set::const_iterator it2 = mapTx.find(hash);
- const CTransaction& tx = it2->GetTx();
- assert(it2 != mapTx.end());
- assert(&tx == it->second);
+ for (const auto& [_, next_tx] : mapNextTx) {
+ auto it = mapTx.find(next_tx->GetHash());
+ const CTransaction& tx = it->GetTx();
+ assert(it != mapTx.end());
+ assert(&tx == next_tx);
}
assert(totalTxSize == checkTotal);
@@ -876,7 +875,7 @@ const CTxMemPoolEntry* CTxMemPool::GetEntry(const Txid& txid) const
return i == mapTx.end() ? nullptr : &(*i);
}
-CTransactionRef CTxMemPool::get(const uint256& hash) const
+CTransactionRef CTxMemPool::get(const Txid& hash) const
{
LOCK(cs);
indexed_transaction_set::const_iterator i = mapTx.find(hash);
@@ -885,7 +884,7 @@ CTransactionRef CTxMemPool::get(const uint256& hash) const
return i->GetSharedTx();
}
-void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta)
+void CTxMemPool::PrioritiseTransaction(const Txid& hash, const CAmount& nFeeDelta)
{
{
LOCK(cs);
@@ -921,17 +920,17 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
}
}
-void CTxMemPool::ApplyDelta(const uint256& hash, CAmount &nFeeDelta) const
+void CTxMemPool::ApplyDelta(const Txid& hash, CAmount &nFeeDelta) const
{
AssertLockHeld(cs);
- std::map<uint256, CAmount>::const_iterator pos = mapDeltas.find(hash);
+ std::map<Txid, CAmount>::const_iterator pos = mapDeltas.find(hash);
if (pos == mapDeltas.end())
return;
const CAmount &delta = pos->second;
nFeeDelta += delta;
}
-void CTxMemPool::ClearPrioritisation(const uint256& hash)
+void CTxMemPool::ClearPrioritisation(const Txid& hash)
{
AssertLockHeld(cs);
mapDeltas.erase(hash);
@@ -962,7 +961,7 @@ const CTransaction* CTxMemPool::GetConflictTx(const COutPoint& prevout) const
std::optional<CTxMemPool::txiter> CTxMemPool::GetIter(const Txid& txid) const
{
AssertLockHeld(cs);
- auto it = mapTx.find(txid.ToUint256());
+ auto it = mapTx.find(txid);
return it != mapTx.end() ? std::make_optional(it) : std::nullopt;
}
@@ -1048,7 +1047,7 @@ size_t CTxMemPool::DynamicMemoryUsage() const {
return memusage::MallocUsage(sizeof(CTxMemPoolEntry) + 15 * sizeof(void*)) * mapTx.size() + memusage::DynamicUsage(mapNextTx) + memusage::DynamicUsage(mapDeltas) + memusage::DynamicUsage(txns_randomized) + cachedInnerUsage;
}
-void CTxMemPool::RemoveUnbroadcastTx(const uint256& txid, const bool unchecked) {
+void CTxMemPool::RemoveUnbroadcastTx(const Txid& txid, const bool unchecked) {
LOCK(cs);
if (m_unbroadcast_txids.erase(txid))
@@ -1203,7 +1202,7 @@ uint64_t CTxMemPool::CalculateDescendantMaximum(txiter entry) const {
return maximum;
}
-void CTxMemPool::GetTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants, size_t* const ancestorsize, CAmount* const ancestorfees) const {
+void CTxMemPool::GetTransactionAncestry(const Txid& txid, size_t& ancestors, size_t& descendants, size_t* const ancestorsize, CAmount* const ancestorfees) const {
LOCK(cs);
auto it = mapTx.find(txid);
ancestors = descendants = 0;
diff --git a/src/txmempool.h b/src/txmempool.h
index 048ad23f..8b55d9cd 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -57,7 +57,7 @@ bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp) EXCLUSIVE
// extracts a transaction hash from CTxMemPoolEntry or CTransactionRef
struct mempoolentry_txid
{
- typedef uint256 result_type;
+ typedef Txid result_type;
result_type operator() (const CTxMemPoolEntry &entry) const
{
return entry.GetTx().GetHash();
@@ -72,7 +72,7 @@ struct mempoolentry_txid
// extracts a transaction witness-hash from CTxMemPoolEntry or CTransactionRef
struct mempoolentry_wtxid
{
- typedef uint256 result_type;
+ typedef Wtxid result_type;
result_type operator() (const CTxMemPoolEntry &entry) const
{
return entry.GetTx().GetWitnessHash();
@@ -387,7 +387,7 @@ private:
/**
* Track locally submitted transactions to periodically retry initial broadcast.
*/
- std::set<uint256> m_unbroadcast_txids GUARDED_BY(cs);
+ std::set<Txid> m_unbroadcast_txids GUARDED_BY(cs);
/**
@@ -414,7 +414,7 @@ private:
public:
indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
- std::map<uint256, CAmount> mapDeltas GUARDED_BY(cs);
+ std::map<Txid, CAmount> mapDeltas GUARDED_BY(cs);
using Options = kernel::MemPoolOptions;
@@ -459,9 +459,9 @@ public:
bool HasNoInputsOf(const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs);
/** Affect CreateNewBlock prioritisation of transactions */
- void PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta);
- void ApplyDelta(const uint256& hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs);
- void ClearPrioritisation(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs);
+ void PrioritiseTransaction(const Txid& hash, const CAmount& nFeeDelta);
+ void ApplyDelta(const Txid& hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs);
+ void ClearPrioritisation(const Txid& hash) EXCLUSIVE_LOCKS_REQUIRED(cs);
struct delta_info {
/** Whether this transaction is in the mempool. */
@@ -471,7 +471,7 @@ public:
/** The modified fee (base fee + delta) of this entry. Only present if in_mempool=true. */
std::optional<CAmount> modified_fee;
/** The prioritised transaction's txid. */
- const uint256 txid;
+ const Txid txid;
};
/** Return a vector of all entries in mapDeltas with their corresponding delta_info. */
std::vector<delta_info> GetPrioritisedTransactions() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
@@ -506,7 +506,7 @@ public:
* @param[in] vHashesToUpdate The set of txids from the
* disconnected block that have been accepted back into the mempool.
*/
- void UpdateTransactionsFromBlock(const std::vector<uint256>& vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main) LOCKS_EXCLUDED(m_epoch);
+ void UpdateTransactionsFromBlock(const std::vector<Txid>& vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main) LOCKS_EXCLUDED(m_epoch);
/**
* Try to calculate all in-mempool ancestors of entry.
@@ -595,7 +595,7 @@ public:
* When ancestors is non-zero (ie, the transaction itself is in the mempool),
* ancestorsize and ancestorfees will also be set to the appropriate values.
*/
- void GetTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize = nullptr, CAmount* ancestorfees = nullptr) const;
+ void GetTransactionAncestry(const Txid& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize = nullptr, CAmount* ancestorfees = nullptr) const;
/**
* @returns true if an initial attempt to load the persisted mempool was made, regardless of
@@ -641,7 +641,7 @@ public:
const CTxMemPoolEntry* GetEntry(const Txid& txid) const LIFETIMEBOUND EXCLUSIVE_LOCKS_REQUIRED(cs);
- CTransactionRef get(const uint256& hash) const;
+ CTransactionRef get(const Txid& hash) const;
template <TxidOrWtxid T>
TxMempoolInfo info(const T& id) const
@@ -666,26 +666,26 @@ public:
size_t DynamicMemoryUsage() const;
/** Adds a transaction to the unbroadcast set */
- void AddUnbroadcastTx(const uint256& txid)
+ void AddUnbroadcastTx(const Txid& txid)
{
LOCK(cs);
// Sanity check the transaction is in the mempool & insert into
// unbroadcast set.
- if (exists(Txid::FromUint256(txid))) m_unbroadcast_txids.insert(txid);
+ if (exists(txid)) m_unbroadcast_txids.insert(txid);
};
/** Removes a transaction from the unbroadcast set */
- void RemoveUnbroadcastTx(const uint256& txid, const bool unchecked = false);
+ void RemoveUnbroadcastTx(const Txid& txid, const bool unchecked = false);
/** Returns transactions in unbroadcast set */
- std::set<uint256> GetUnbroadcastTxs() const
+ std::set<Txid> GetUnbroadcastTxs() const
{
LOCK(cs);
return m_unbroadcast_txids;
}
/** Returns whether a txid is in the unbroadcast set */
- bool IsUnbroadcastTx(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
+ bool IsUnbroadcastTx(const Txid& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
{
AssertLockHeld(cs);
return m_unbroadcast_txids.count(txid) != 0;
@@ -744,7 +744,7 @@ private:
* removeRecursive them.
*/
void UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendants,
- const std::set<uint256>& setExclude, std::set<uint256>& descendants_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs);
+ const std::set<Txid>& setExclude, std::set<Txid>& descendants_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs);
/** Update ancestors of hash to add/remove it as a descendant transaction. */
void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs);
/** Set ancestor state for an entry */
diff --git a/src/validation.cpp b/src/validation.cpp
index 90e70834..69cc84bb 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -303,7 +303,7 @@ void Chainstate::MaybeUpdateMempoolForReorg(
AssertLockHeld(cs_main);
AssertLockHeld(m_mempool->cs);
- std::vector<uint256> vHashUpdate;
+ std::vector<Txid> vHashUpdate;
{
// disconnectpool is ordered so that the front is the most recently-confirmed
// transaction (the last tx of the block at the tip) in the disconnected chain.
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.