mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-13 11:35:20 +01:00
[refactor] Add helper for iterating through mempool entries
Instead of reaching into the mapTx data structure, use a helper method that provides the required vector of CTxMemPoolEntry pointers.
This commit is contained in:
parent
d9007f51a7
commit
453b4813eb
5 changed files with 18 additions and 4 deletions
|
@ -176,4 +176,6 @@ public:
|
|||
mutable Epoch::Marker m_epoch_marker; //!< epoch when last touched, useful for graph algorithms
|
||||
};
|
||||
|
||||
using CTxMemPoolEntryRef = CTxMemPoolEntry::CTxMemPoolEntryRef;
|
||||
|
||||
#endif // BITCOIN_KERNEL_MEMPOOL_ENTRY_H
|
||||
|
|
|
@ -806,7 +806,7 @@ public:
|
|||
{
|
||||
if (!m_node.mempool) return;
|
||||
LOCK2(::cs_main, m_node.mempool->cs);
|
||||
for (const CTxMemPoolEntry& entry : m_node.mempool->mapTx) {
|
||||
for (const CTxMemPoolEntry& entry : m_node.mempool->entryAll()) {
|
||||
notifications.transactionAddedToMempool(entry.GetSharedTx());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -344,14 +344,13 @@ UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose, bool include_mempoo
|
|||
}
|
||||
LOCK(pool.cs);
|
||||
UniValue o(UniValue::VOBJ);
|
||||
for (const CTxMemPoolEntry& e : pool.mapTx) {
|
||||
const uint256& hash = e.GetTx().GetHash();
|
||||
for (const CTxMemPoolEntry& e : pool.entryAll()) {
|
||||
UniValue info(UniValue::VOBJ);
|
||||
entryToJSON(pool, info, e);
|
||||
// Mempool has unique entries so there is no advantage in using
|
||||
// UniValue::pushKV, which checks if the key already exists in O(N).
|
||||
// UniValue::pushKVEnd is used instead which currently is O(1).
|
||||
o.pushKVEnd(hash.ToString(), info);
|
||||
o.pushKVEnd(e.GetTx().GetHash().ToString(), info);
|
||||
}
|
||||
return o;
|
||||
} else {
|
||||
|
|
|
@ -836,6 +836,18 @@ static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator
|
|||
return TxMempoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
|
||||
}
|
||||
|
||||
std::vector<CTxMemPoolEntryRef> CTxMemPool::entryAll() const
|
||||
{
|
||||
AssertLockHeld(cs);
|
||||
|
||||
std::vector<CTxMemPoolEntryRef> ret;
|
||||
ret.reserve(mapTx.size());
|
||||
for (const auto& it : GetSortedDepthAndScore()) {
|
||||
ret.emplace_back(*it);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<TxMempoolInfo> CTxMemPool::infoAll() const
|
||||
{
|
||||
LOCK(cs);
|
||||
|
|
|
@ -695,6 +695,7 @@ public:
|
|||
/** Returns info for a transaction if its entry_sequence < last_sequence */
|
||||
TxMempoolInfo info_for_relay(const GenTxid& gtxid, uint64_t last_sequence) const;
|
||||
|
||||
std::vector<CTxMemPoolEntryRef> entryAll() const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
std::vector<TxMempoolInfo> infoAll() const;
|
||||
|
||||
size_t DynamicMemoryUsage() const;
|
||||
|
|
Loading…
Add table
Reference in a new issue