RPC: Restore "startingpriority" and "currentpriority" in mempool entries

This commit is contained in:
Luke Dashjr 2018-03-11 03:08:02 +00:00
parent 93015303eb
commit 30e24fa24e
4 changed files with 43 additions and 11 deletions

View File

@ -9,6 +9,7 @@
#include <test/util/setup_common.h>
#include <txmempool.h>
#include <util/chaintype.h>
#include <validation.h>
#include <univalue.h>
@ -21,7 +22,8 @@ static void AddTx(const CTransactionRef& tx, const CAmount& fee, CTxMemPool& poo
static void RpcMempool(benchmark::Bench& bench)
{
const auto testing_setup = MakeNoLogFileContext<const ChainTestingSetup>(ChainType::MAIN);
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN);
auto& chainman = *testing_setup->m_node.chainman;
CTxMemPool& pool = *Assert(testing_setup->m_node.mempool);
LOCK2(cs_main, pool.cs);
@ -38,7 +40,7 @@ static void RpcMempool(benchmark::Bench& bench)
}
bench.run([&] {
(void)MempoolToJSON(pool, /*verbose=*/true);
(void)MempoolToJSON(chainman, pool, /*verbose=*/true);
});
}

View File

@ -683,7 +683,10 @@ static bool rest_mempool(const std::any& context, HTTPRequest* req, const std::s
if (verbose && mempool_sequence) {
return RESTERR(req, HTTP_BAD_REQUEST, "Verbose results cannot contain mempool sequence values. (hint: set \"verbose=false\")");
}
str_json = MempoolToJSON(*mempool, verbose, mempool_sequence).write() + "\n";
ChainstateManager* maybe_chainman = GetChainman(context, req);
if (!maybe_chainman) return false;
ChainstateManager& chainman = *maybe_chainman;
str_json = MempoolToJSON(chainman, *mempool, verbose, mempool_sequence).write() + "\n";
} else if (param == "info/with_fee_histogram") {
str_json = MempoolInfoToJSON(*mempool, MempoolInfoToJSON_const_histogram_floors).write() + "\n";
} else {

View File

@ -300,6 +300,8 @@ static std::vector<RPCResult> MempoolEntryDescription()
RPCResult{RPCResult::Type::NUM, "weight", "transaction weight as defined in BIP 141."},
RPCResult{RPCResult::Type::NUM_TIME, "time", "local time transaction entered pool in seconds since 1 Jan 1970 GMT"},
RPCResult{RPCResult::Type::NUM, "height", "block height when transaction entered pool"},
RPCResult{RPCResult::Type::NUM, "startingpriority", "Priority when transaction entered pool"},
RPCResult{RPCResult::Type::NUM, "currentpriority", "Transaction priority now"},
RPCResult{RPCResult::Type::NUM, "descendantcount", "number of in-mempool descendant transactions (including this one)"},
RPCResult{RPCResult::Type::NUM, "descendantsize", "virtual transaction size of in-mempool descendants (including this one)"},
RPCResult{RPCResult::Type::NUM, "ancestorcount", "number of in-mempool ancestor transactions (including this one)"},
@ -321,7 +323,7 @@ static std::vector<RPCResult> MempoolEntryDescription()
};
}
static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPoolEntry& e) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPoolEntry& e, const int next_block_height) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
{
AssertLockHeld(pool.cs);
@ -329,6 +331,8 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
info.pushKV("weight", (int)e.GetTxWeight());
info.pushKV("time", count_seconds(e.GetTime()));
info.pushKV("height", (int)e.GetHeight());
info.pushKV("startingpriority", e.GetStartingPriority());
info.pushKV("currentpriority", e.GetPriority(next_block_height));
info.pushKV("descendantcount", e.GetCountWithDescendants());
info.pushKV("descendantsize", e.GetSizeWithDescendants());
info.pushKV("ancestorcount", e.GetCountWithAncestors());
@ -380,17 +384,22 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
info.pushKV("unbroadcast", pool.IsUnbroadcastTx(tx.GetHash()));
}
UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose, bool include_mempool_sequence)
UniValue MempoolToJSON(ChainstateManager &chainman, const CTxMemPool& pool, bool verbose, bool include_mempool_sequence)
{
if (verbose) {
if (include_mempool_sequence) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Verbose results cannot contain mempool sequence values.");
}
LOCK(::cs_main);
const CChain& active_chain = chainman.ActiveChain();
const int next_block_height = active_chain.Height() + 1;
LOCK(pool.cs);
// TODO: Release cs_main after mempool.cs acquired
UniValue o(UniValue::VOBJ);
for (const CTxMemPoolEntry& e : pool.entryAll()) {
UniValue info(UniValue::VOBJ);
entryToJSON(pool, info, e);
entryToJSON(pool, info, e, next_block_height);
// 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).
@ -465,7 +474,9 @@ static RPCHelpMan getrawmempool()
include_mempool_sequence = request.params[1].get_bool();
}
return MempoolToJSON(EnsureAnyMemPool(request.context), fVerbose, include_mempool_sequence);
NodeContext& node = EnsureAnyNodeContext(request.context);
ChainstateManager& chainman = EnsureChainman(node);
return MempoolToJSON(chainman, EnsureAnyMemPool(request.context), fVerbose, include_mempool_sequence);
},
};
}
@ -501,7 +512,12 @@ static RPCHelpMan getmempoolancestors()
uint256 hash = ParseHashV(request.params[0], "parameter 1");
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
ChainstateManager& chainman = EnsureAnyChainman(request.context);
LOCK(::cs_main);
const CChain& active_chain = chainman.ActiveChain();
const int next_block_height = active_chain.Height() + 1;
LOCK(mempool.cs);
// TODO: Release cs_main after mempool.cs acquired
CTxMemPool::txiter it = mempool.mapTx.find(hash);
if (it == mempool.mapTx.end()) {
@ -522,7 +538,7 @@ static RPCHelpMan getmempoolancestors()
const CTxMemPoolEntry &e = *ancestorIt;
const uint256& _hash = e.GetTx().GetHash();
UniValue info(UniValue::VOBJ);
entryToJSON(mempool, info, e);
entryToJSON(mempool, info, e, next_block_height);
o.pushKV(_hash.ToString(), info);
}
return o;
@ -562,7 +578,12 @@ static RPCHelpMan getmempooldescendants()
uint256 hash = ParseHashV(request.params[0], "parameter 1");
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
ChainstateManager& chainman = EnsureAnyChainman(request.context);
LOCK(::cs_main);
const CChain& active_chain = chainman.ActiveChain();
const int next_block_height = active_chain.Height() + 1;
LOCK(mempool.cs);
// TODO: Release cs_main after mempool.cs acquired
CTxMemPool::txiter it = mempool.mapTx.find(hash);
if (it == mempool.mapTx.end()) {
@ -587,7 +608,7 @@ static RPCHelpMan getmempooldescendants()
const CTxMemPoolEntry &e = *descendantIt;
const uint256& _hash = e.GetTx().GetHash();
UniValue info(UniValue::VOBJ);
entryToJSON(mempool, info, e);
entryToJSON(mempool, info, e, next_block_height);
o.pushKV(_hash.ToString(), info);
}
return o;
@ -614,7 +635,12 @@ static RPCHelpMan getmempoolentry()
uint256 hash = ParseHashV(request.params[0], "parameter 1");
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
ChainstateManager& chainman = EnsureAnyChainman(request.context);
LOCK(::cs_main);
const CChain& active_chain = chainman.ActiveChain();
const int next_block_height = active_chain.Height() + 1;
LOCK(mempool.cs);
// TODO: Release cs_main after mempool.cs acquired
CTxMemPool::txiter it = mempool.mapTx.find(hash);
if (it == mempool.mapTx.end()) {
@ -623,7 +649,7 @@ static RPCHelpMan getmempoolentry()
const CTxMemPoolEntry &e = *it;
UniValue info(UniValue::VOBJ);
entryToJSON(mempool, info, e);
entryToJSON(mempool, info, e, next_block_height);
return info;
},
};

View File

@ -10,6 +10,7 @@
#include <optional>
#include <vector>
class ChainstateManager;
class CTxMemPool;
class UniValue;
@ -28,6 +29,6 @@ static const MempoolHistogramFeeRates MempoolInfoToJSON_const_histogram_floors{
UniValue MempoolInfoToJSON(const CTxMemPool& pool, const std::optional<MempoolHistogramFeeRates>& histogram_floors);
/** Mempool to JSON */
UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose = false, bool include_mempool_sequence = false);
UniValue MempoolToJSON(ChainstateManager& chainman, const CTxMemPool& pool, bool verbose = false, bool include_mempool_sequence = false);
#endif // BITCOIN_RPC_MEMPOOL_H