mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
Calculate descendant information for mempool RPC output on-the-fly
This is in preparation for removing the cached descendant state from the mempool.
This commit is contained in:
@@ -291,13 +291,14 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
|
||||
AssertLockHeld(pool.cs);
|
||||
|
||||
auto [ancestor_count, ancestor_size, ancestor_fees] = pool.CalculateAncestorData(e);
|
||||
auto [descendant_count, descendant_size, descendant_fees] = pool.CalculateDescendantData(e);
|
||||
|
||||
info.pushKV("vsize", (int)e.GetTxSize());
|
||||
info.pushKV("weight", (int)e.GetTxWeight());
|
||||
info.pushKV("time", count_seconds(e.GetTime()));
|
||||
info.pushKV("height", (int)e.GetHeight());
|
||||
info.pushKV("descendantcount", e.GetCountWithDescendants());
|
||||
info.pushKV("descendantsize", e.GetSizeWithDescendants());
|
||||
info.pushKV("descendantcount", descendant_count);
|
||||
info.pushKV("descendantsize", descendant_size);
|
||||
info.pushKV("ancestorcount", ancestor_count);
|
||||
info.pushKV("ancestorsize", ancestor_size);
|
||||
info.pushKV("wtxid", e.GetTx().GetWitnessHash().ToString());
|
||||
@@ -306,7 +307,7 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
|
||||
fees.pushKV("base", ValueFromAmount(e.GetFee()));
|
||||
fees.pushKV("modified", ValueFromAmount(e.GetModifiedFee()));
|
||||
fees.pushKV("ancestor", ValueFromAmount(ancestor_fees));
|
||||
fees.pushKV("descendant", ValueFromAmount(e.GetModFeesWithDescendants()));
|
||||
fees.pushKV("descendant", ValueFromAmount(descendant_fees));
|
||||
info.pushKV("fees", std::move(fees));
|
||||
|
||||
const CTransaction& tx = e.GetTx();
|
||||
|
||||
@@ -1217,6 +1217,21 @@ std::tuple<size_t, size_t, CAmount> CTxMemPool::CalculateAncestorData(const CTxM
|
||||
return {ancestor_count, ancestor_size, ancestor_fees};
|
||||
}
|
||||
|
||||
std::tuple<size_t, size_t, CAmount> CTxMemPool::CalculateDescendantData(const CTxMemPoolEntry& entry) const
|
||||
{
|
||||
auto descendants = m_txgraph->GetDescendants(entry, TxGraph::Level::MAIN);
|
||||
size_t descendant_count = descendants.size();
|
||||
size_t descendant_size = 0;
|
||||
CAmount descendant_fees = 0;
|
||||
|
||||
for (auto tx: descendants) {
|
||||
const CTxMemPoolEntry &desc = static_cast<const CTxMemPoolEntry&>(*tx);
|
||||
descendant_size += desc.GetTxSize();
|
||||
descendant_fees += desc.GetModifiedFee();
|
||||
}
|
||||
return {descendant_count, descendant_size, descendant_fees};
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -287,6 +287,7 @@ public:
|
||||
uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
std::tuple<size_t, size_t, CAmount> CalculateAncestorData(const CTxMemPoolEntry& entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
std::tuple<size_t, size_t, CAmount> CalculateDescendantData(const CTxMemPoolEntry& entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
private:
|
||||
typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
|
||||
|
||||
Reference in New Issue
Block a user