mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Merge bitcoin/bitcoin#27501: mempool / rpc: add getprioritisedtransactions, delete a mapDeltas entry when delta==0
67b7fecacd[mempool] clear mapDeltas entry if prioritisetransaction sets delta to 0 (glozow)c1061acb9d[functional test] prioritisation is not removed during replacement and expiry (glozow)0e5874f0b0[functional test] getprioritisedtransactions RPC (glozow)99f8046829[rpc] add getprioritisedtransactions (glozow)9e9ca36c80[mempool] add GetPrioritisedTransactions (glozow) Pull request description: Add an RPC to get prioritised transactions (also tells you whether the tx is in mempool or not), helping users clean up `mapDeltas` manually. When `CTxMemPool::PrioritiseTransaction` sets a delta to 0, remove the entry from `mapDeltas`. Motivation / Background - `mapDeltas` entries are never removed from mapDeltas except when the tx is mined in a block or conflicted. - Mostly it is a feature to allow `prioritisetransaction` for a tx that isn't in the mempool {yet, anymore}. A user can may resbumit a tx and it retains its priority, or mark a tx as "definitely accept" before it is seen. - Since #8448, `mapDeltas` is persisted to mempool.dat and loaded on restart. This is also good, otherwise we lose prioritisation on restart. - Note the removal due to block/conflict is only done when `removeForBlock` is called, i.e. when the block is received. If you load a mempool.dat containing `mapDeltas` with transactions that were mined already (e.g. the file was saved prior to the last few blocks), you don't delete them. - Related: #4818 and #6464. - There is no way to query the node for not-in-mempool `mapDeltas`. If you add a priority and forget what the value was, the only way to get that information is to inspect mempool.dat. - Calling `prioritisetransaction` with an inverse value does not remove it from `mapDeltas`, it just sets the value to 0. It disappears on a restart (`LoadMempool` checks if delta is 0), but that might not happen for a while. Added together, if a user calls `prioritisetransaction` very regularly and not all those transactions get mined/conflicted, `mapDeltas` might keep lots of entries of delta=0 around. A user should clean up the not-in-mempool prioritisations, but that's currently difficult without keeping track of what those txids/amounts are. ACKs for top commit: achow101: ACK67b7fecacdtheStack: Code-review ACK67b7fecacdinstagibbs: code review ACK67b7fecacdajtowns: ACK67b7fecacdcode review only, some nits Tree-SHA512: 9df48b622ef27f33db1a2748f682bb3f16abe8172fcb7ac3c1a3e1654121ffb9b31aeaad5570c4162261f7e2ff5b5912ddc61a1b8beac0e9f346a86f5952260a
This commit is contained in:
@@ -480,6 +480,40 @@ static RPCHelpMan prioritisetransaction()
|
||||
};
|
||||
}
|
||||
|
||||
static RPCHelpMan getprioritisedtransactions()
|
||||
{
|
||||
return RPCHelpMan{"getprioritisedtransactions",
|
||||
"Returns a map of all user-created (see prioritisetransaction) fee deltas by txid, and whether the tx is present in mempool.",
|
||||
{},
|
||||
RPCResult{
|
||||
RPCResult::Type::OBJ_DYN, "prioritisation-map", "prioritisation keyed by txid",
|
||||
{
|
||||
{RPCResult::Type::OBJ, "txid", "", {
|
||||
{RPCResult::Type::NUM, "fee_delta", "transaction fee delta in satoshis"},
|
||||
{RPCResult::Type::BOOL, "in_mempool", "whether this transaction is currently in mempool"},
|
||||
}}
|
||||
},
|
||||
},
|
||||
RPCExamples{
|
||||
HelpExampleCli("getprioritisedtransactions", "")
|
||||
+ HelpExampleRpc("getprioritisedtransactions", "")
|
||||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
CTxMemPool& mempool = EnsureMemPool(node);
|
||||
UniValue rpc_result{UniValue::VOBJ};
|
||||
for (const auto& delta_info : mempool.GetPrioritisedTransactions()) {
|
||||
UniValue result_inner{UniValue::VOBJ};
|
||||
result_inner.pushKV("fee_delta", delta_info.delta);
|
||||
result_inner.pushKV("in_mempool", delta_info.in_mempool);
|
||||
rpc_result.pushKV(delta_info.txid.GetHex(), result_inner);
|
||||
}
|
||||
return rpc_result;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// NOTE: Assumes a conclusive result; if result is inconclusive, it must be handled by caller
|
||||
static UniValue BIP22ValidationResult(const BlockValidationState& state)
|
||||
@@ -1048,6 +1082,7 @@ void RegisterMiningRPCCommands(CRPCTable& t)
|
||||
{"mining", &getnetworkhashps},
|
||||
{"mining", &getmininginfo},
|
||||
{"mining", &prioritisetransaction},
|
||||
{"mining", &getprioritisedtransactions},
|
||||
{"mining", &getblocktemplate},
|
||||
{"mining", &submitblock},
|
||||
{"mining", &submitheader},
|
||||
|
||||
Reference in New Issue
Block a user