[node] interface to get bump fees

pull/26152/head
glozow 3 years ago committed by Murch
parent c24851be94
commit c57889da66
No known key found for this signature in database
GPG Key ID: 7BA035CA5B901713

@ -216,6 +216,43 @@ public:
//! Calculate mempool ancestor and descendant counts for the given transaction.
virtual void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize = nullptr, CAmount* ancestorfees = nullptr) = 0;
//! For each outpoint, calculate the fee-bumping cost to spend this outpoint at the specified
// feerate, including bumping its ancestors. For example, if the target feerate is 10sat/vbyte
// and this outpoint refers to a mempool transaction at 3sat/vbyte, the bump fee includes the
// cost to bump the mempool transaction to 10sat/vbyte (i.e. 7 * mempooltx.vsize). If that
// transaction also has, say, an unconfirmed parent with a feerate of 1sat/vbyte, the bump fee
// includes the cost to bump the parent (i.e. 9 * parentmempooltx.vsize).
//
// If the outpoint comes from an unconfirmed transaction that is already above the target
// feerate or bumped by its descendant(s) already, it does not need to be bumped. Its bump fee
// is 0. Likewise, if any of the transaction's ancestors are already bumped by a transaction
// in our mempool, they are not included in the transaction's bump fee.
//
// Also supported is bump-fee calculation in the case of replacements. If an outpoint
// conflicts with another transaction in the mempool, it is assumed that the goal is to replace
// that transaction. As such, the calculation will exclude the to-be-replaced transaction, but
// will include the fee-bumping cost. If bump fees of descendants of the to-be-replaced
// transaction are requested, the value will be 0. Fee-related RBF rules are not included as
// they are logically distinct.
//
// Any outpoints that are otherwise unavailable from the mempool (e.g. UTXOs from confirmed
// transactions or transactions not yet broadcast by the wallet) are given a bump fee of 0.
//
// If multiple outpoints come from the same transaction (which would be very rare because
// it means that one transaction has multiple change outputs or paid the same wallet using multiple
// outputs in the same transaction) or have shared ancestry, the bump fees are calculated
// independently, i.e. as if only one of them is spent. This may result in double-fee-bumping. This
// caveat can be rectified per use of the sister-function CalculateCombinedBumpFee(…).
virtual std::map<COutPoint, CAmount> CalculateIndividualBumpFees(const std::vector<COutPoint>& outpoints, const CFeeRate& target_feerate) = 0;
//! Calculate the combined bump fee for an input set per the same strategy
// as in CalculateIndividualBumpFees(…).
// Unlike CalculateIndividualBumpFees(…), this does not return individual
// bump fees per outpoint, but a single bump fee for the shared ancestry.
// The combined bump fee may be used to correct overestimation due to
// shared ancestry by multiple UTXOs after coin selection.
virtual std::optional<CAmount> CalculateCombinedBumpFee(const std::vector<COutPoint>& outpoints, const CFeeRate& target_feerate) = 0;
//! Get the node's package limits.
//! Currently only returns the ancestor and descendant count limits, but could be enhanced to
//! return more policy settings.

@ -28,6 +28,7 @@
#include <node/coin.h>
#include <node/context.h>
#include <node/interface_ui.h>
#include <node/mini_miner.h>
#include <node/transaction.h>
#include <policy/feerate.h>
#include <policy/fees.h>
@ -665,6 +666,26 @@ public:
if (!m_node.mempool) return;
m_node.mempool->GetTransactionAncestry(txid, ancestors, descendants, ancestorsize, ancestorfees);
}
std::map<COutPoint, CAmount> CalculateIndividualBumpFees(const std::vector<COutPoint>& outpoints, const CFeeRate& target_feerate) override
{
if (!m_node.mempool) {
std::map<COutPoint, CAmount> bump_fees;
for (const auto& outpoint : outpoints) {
bump_fees.emplace(std::make_pair(outpoint, 0));
}
return bump_fees;
}
return MiniMiner(*m_node.mempool, outpoints).CalculateBumpFees(target_feerate);
}
std::optional<CAmount> CalculateCombinedBumpFee(const std::vector<COutPoint>& outpoints, const CFeeRate& target_feerate) override
{
if (!m_node.mempool) {
return 0;
}
return MiniMiner(*m_node.mempool, outpoints).CalculateTotalBumpFees(target_feerate);
}
void getPackageLimits(unsigned int& limit_ancestor_count, unsigned int& limit_descendant_count) override
{
const CTxMemPool::Limits default_limits{};

Loading…
Cancel
Save