mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
mempool, refactor: Convert uint256 to Txid
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user