mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge #20944: rpc: Return total fee in getmempoolinfo
fa362064e383163a2585ffbc71ac1ea3bcc92663 rpc: Return total fee in mempool (MarcoFalke)
Pull request description:
This avoids having to loop over the whole mempool to query each entry's fee
ACKs for top commit:
achow101:
ACK fa362064e383163a2585ffbc71ac1ea3bcc92663
glozow:
ACK fa362064e3
🧸
jnewbery:
ACK fa362064e383163a2585ffbc71ac1ea3bcc92663
Tree-SHA512: e2fa1664df39c9e187f9229fc35764ccf436f6f75889c5a206d34fff473fc21efbf2bb143f4ca7895c27659218c22884d0ec4195e7a536a5a96973fc9dd82d08
This commit is contained in:
parent
03d743466b
commit
63885189ae
@ -112,12 +112,7 @@ $ curl localhost:19998/rest/getutxos/checkmempool/b2cdfd7b89def827ff8af7cd9bff76
|
||||
|
||||
Returns various information about the TX mempool.
|
||||
Only supports JSON as output format.
|
||||
* loaded : (boolean) if the mempool is fully loaded
|
||||
* size : (numeric) the number of transactions in the TX mempool
|
||||
* bytes : (numeric) size of the TX mempool in bytes
|
||||
* usage : (numeric) total TX mempool memory usage
|
||||
* maxmempool : (numeric) maximum memory usage for the mempool in bytes
|
||||
* mempoolminfee : (numeric) minimum feerate (DASH per KB) for tx to be accepted
|
||||
Refer to the `getmempoolinfo` RPC for documentation of the fields.
|
||||
|
||||
`GET /rest/mempool/contents.json`
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <node/coinstats.h>
|
||||
#include <node/context.h>
|
||||
#include <node/utxo_snapshot.h>
|
||||
#include <policy/feerate.h>
|
||||
#include <policy/fees.h>
|
||||
#include <policy/policy.h>
|
||||
#include <primitives/transaction.h>
|
||||
@ -1916,6 +1917,7 @@ UniValue MempoolInfoToJSON(const CTxMemPool& pool, llmq::CInstantSendManager& is
|
||||
ret.pushKV("size", (int64_t)pool.size());
|
||||
ret.pushKV("bytes", (int64_t)pool.GetTotalTxSize());
|
||||
ret.pushKV("usage", (int64_t)pool.DynamicMemoryUsage());
|
||||
ret.pushKV("total_fee", ValueFromAmount(pool.GetTotalFee()));
|
||||
size_t maxmempool = gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
|
||||
ret.pushKV("maxmempool", (int64_t) maxmempool);
|
||||
ret.pushKV("mempoolminfee", ValueFromAmount(std::max(pool.GetMinFee(maxmempool), ::minRelayTxFee).GetFeePerK()));
|
||||
@ -1937,6 +1939,7 @@ static UniValue getmempoolinfo(const JSONRPCRequest& request)
|
||||
{RPCResult::Type::NUM, "size", "Current tx count"},
|
||||
{RPCResult::Type::NUM, "bytes", "Sum of all virtual transaction sizes as defined in BIP 141. Differs from actual serialized size because witness data is discounted"},
|
||||
{RPCResult::Type::NUM, "usage", "Total memory usage for the mempool"},
|
||||
{RPCResult::Type::STR_AMOUNT, "total_fee", "Total fees for the mempool in " + CURRENCY_UNIT + ", ignoring modified fees through prioritizetransaction"},
|
||||
{RPCResult::Type::NUM, "maxmempool", "Maximum memory usage for the mempool"},
|
||||
{RPCResult::Type::STR_AMOUNT, "mempoolminfee", "Minimum fee rate in " + CURRENCY_UNIT + "/kB for tx to be accepted. Is the maximum of minrelaytxfee and minimum mempool fee"},
|
||||
{RPCResult::Type::STR_AMOUNT, "minrelaytxfee", "Current minimum relay fee for transactions"},
|
||||
|
@ -8,16 +8,16 @@
|
||||
#include <consensus/consensus.h>
|
||||
#include <consensus/tx_verify.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <validation.h>
|
||||
#include <policy/policy.h>
|
||||
#include <hash.h>
|
||||
#include <policy/fees.h>
|
||||
#include <policy/policy.h>
|
||||
#include <policy/settings.h>
|
||||
#include <reverse_iterator.h>
|
||||
#include <util/check.h>
|
||||
#include <util/system.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <util/system.h>
|
||||
#include <util/time.h>
|
||||
#include <hash.h>
|
||||
#include <validation.h>
|
||||
#include <validationinterface.h>
|
||||
|
||||
#include <evo/specialtx.h>
|
||||
@ -400,7 +400,10 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
|
||||
|
||||
nTransactionsUpdated++;
|
||||
totalTxSize += entry.GetTxSize();
|
||||
if (minerPolicyEstimator) {minerPolicyEstimator->processTransaction(entry, validFeeEstimate);}
|
||||
m_total_fee += entry.GetFee();
|
||||
if (minerPolicyEstimator) {
|
||||
minerPolicyEstimator->processTransaction(entry, validFeeEstimate);
|
||||
}
|
||||
|
||||
vTxHashes.emplace_back(entry.GetTx().GetHash(), newit);
|
||||
newit->vTxHashesIdx = vTxHashes.size() - 1;
|
||||
@ -645,6 +648,7 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
|
||||
}
|
||||
|
||||
totalTxSize -= it->GetTxSize();
|
||||
m_total_fee -= it->GetFee();
|
||||
cachedInnerUsage -= it->DynamicMemoryUsage();
|
||||
cachedInnerUsage -= memusage::DynamicUsage(mapLinks[it].parents) + memusage::DynamicUsage(mapLinks[it].children);
|
||||
mapLinks.erase(it);
|
||||
@ -990,6 +994,7 @@ void CTxMemPool::_clear()
|
||||
mapProTxAddresses.clear();
|
||||
mapProTxPubKeyIDs.clear();
|
||||
totalTxSize = 0;
|
||||
m_total_fee = 0;
|
||||
cachedInnerUsage = 0;
|
||||
lastRollingFeeUpdate = GetTime();
|
||||
blockSinceLastRollingFeeBump = false;
|
||||
@ -1023,6 +1028,7 @@ void CTxMemPool::check(CChainState& active_chainstate) const
|
||||
LogPrint(BCLog::MEMPOOL, "Checking mempool with %u transactions and %u inputs\n", (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size());
|
||||
|
||||
uint64_t checkTotal = 0;
|
||||
CAmount check_total_fee{0};
|
||||
uint64_t innerUsage = 0;
|
||||
|
||||
CCoinsViewCache& active_coins_tip = active_chainstate.CoinsTip();
|
||||
@ -1035,6 +1041,7 @@ void CTxMemPool::check(CChainState& active_chainstate) const
|
||||
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
|
||||
unsigned int i = 0;
|
||||
checkTotal += it->GetTxSize();
|
||||
check_total_fee += it->GetFee();
|
||||
innerUsage += it->DynamicMemoryUsage();
|
||||
const CTransaction& tx = it->GetTx();
|
||||
txlinksMap::const_iterator linksiter = mapLinks.find(it);
|
||||
@ -1127,6 +1134,7 @@ void CTxMemPool::check(CChainState& active_chainstate) const
|
||||
}
|
||||
|
||||
assert(totalTxSize == checkTotal);
|
||||
assert(m_total_fee == check_total_fee);
|
||||
assert(innerUsage == cachedInnerUsage);
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,10 @@
|
||||
#include <indirectmap.h>
|
||||
#include <policy/feerate.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <sync.h>
|
||||
#include <random.h>
|
||||
#include <netaddress.h>
|
||||
#include <pubkey.h>
|
||||
#include <sync.h>
|
||||
#include <util/epochguard.h>
|
||||
#include <util/hasher.h>
|
||||
|
||||
@ -447,8 +447,9 @@ private:
|
||||
std::atomic<unsigned int> nTransactionsUpdated{0}; //!< Used by getblocktemplate to trigger CreateNewBlock() invocation
|
||||
CBlockPolicyEstimator* minerPolicyEstimator;
|
||||
|
||||
uint64_t totalTxSize; //!< sum of all mempool tx' byte sizes
|
||||
uint64_t cachedInnerUsage; //!< sum of dynamic memory usage of all the map elements (NOT the maps themselves)
|
||||
uint64_t totalTxSize GUARDED_BY(cs); //!< sum of all mempool tx' byte sizes
|
||||
CAmount m_total_fee GUARDED_BY(cs); //!< sum of all mempool tx's fees (NOT modified fee)
|
||||
uint64_t cachedInnerUsage GUARDED_BY(cs); //!< sum of dynamic memory usage of all the map elements (NOT the maps themselves)
|
||||
|
||||
mutable int64_t lastRollingFeeUpdate;
|
||||
mutable bool blockSinceLastRollingFeeBump;
|
||||
@ -728,6 +729,12 @@ public:
|
||||
return totalTxSize;
|
||||
}
|
||||
|
||||
CAmount GetTotalFee() const EXCLUSIVE_LOCKS_REQUIRED(cs)
|
||||
{
|
||||
AssertLockHeld(cs);
|
||||
return m_total_fee;
|
||||
}
|
||||
|
||||
bool exists(const uint256& hash) const
|
||||
{
|
||||
LOCK(cs);
|
||||
|
@ -67,6 +67,8 @@ class MempoolPersistTest(BitcoinTestFramework):
|
||||
assert_equal(len(self.nodes[0].getrawmempool()), 5)
|
||||
assert_equal(len(self.nodes[1].getrawmempool()), 5)
|
||||
|
||||
total_fee_old = self.nodes[0].getmempoolinfo()['total_fee']
|
||||
|
||||
self.log.debug("Prioritize a transaction on node0")
|
||||
fees = self.nodes[0].getmempoolentry(txid=last_txid)['fees']
|
||||
assert_equal(fees['base'], fees['modified'])
|
||||
@ -74,6 +76,10 @@ class MempoolPersistTest(BitcoinTestFramework):
|
||||
fees = self.nodes[0].getmempoolentry(txid=last_txid)['fees']
|
||||
assert_equal(fees['base'] + Decimal('0.00001000'), fees['modified'])
|
||||
|
||||
self.log.info('Check the total base fee is unchanged after prioritisetransaction')
|
||||
assert_equal(total_fee_old, self.nodes[0].getmempoolinfo()['total_fee'])
|
||||
assert_equal(total_fee_old, sum(v['fees']['base'] for k, v in self.nodes[0].getrawmempool(verbose=True).items()))
|
||||
|
||||
tx_creation_time = self.nodes[0].getmempoolentry(txid=last_txid)['time']
|
||||
assert_greater_than_or_equal(tx_creation_time, tx_creation_time_lower)
|
||||
assert_greater_than_or_equal(tx_creation_time_higher, tx_creation_time)
|
||||
|
Loading…
Reference in New Issue
Block a user