mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-31 16:24:48 +02:00
Merge bitcoin/bitcoin#29242: Mempool util: Add RBF diagram checks for single chunks against clusters of size 2
7295986778Unit tests for CalculateFeerateDiagramsForRBF (Greg Sanders)b767e6bd47test: unit test for ImprovesFeerateDiagram (Greg Sanders)7e89b659e1Add fuzz test for FeeFrac (Greg Sanders)4d6528a3d6fuzz: fuzz diagram creation and comparison (Greg Sanders)e9c5aeb11dtest: Add tests for CompareFeerateDiagram and CheckConflictTopology (Greg Sanders)588a98dcccfuzz: Add fuzz target for ImprovesFeerateDiagram (Greg Sanders)2079b80854Implement ImprovesFeerateDiagram (Greg Sanders)66d966dcfaAdd FeeFrac unit tests (Greg Sanders)ce8e22542eAdd FeeFrac utils (Greg Sanders) Pull request description: This is a smaller piece of https://github.com/bitcoin/bitcoin/pull/28984 broken off for easier review. Up to date explanation of diagram checks are here: https://delvingbitcoin.org/t/mempool-incentive-compatibility/553 This infrastructure has two near term applications prior to cluster mempool: 1) Limited Package RBF(https://github.com/bitcoin/bitcoin/pull/28984): We want to allow package RBF only when we know it improves the mempool. This narrowly scoped functionality allows use with v3-like topologies, and will be expanded at some point post-cluster mempool when diagram checks can be done efficiently against bounded cluster sizes. 2) Replacement for single tx RBF(in a cluster size of up to two) against conflicts of up to cluster size two. `ImprovesFeerateDiagram` interface will have to change for this use-case, which is a future direction to solve certain pins and improve mempool incentive compatibility: https://delvingbitcoin.org/t/ephemeral-anchors-and-mev/383#diagram-checks-fix-this-3 And longer-term, this would be the proposed way we would compute incentive compatibility for all conflicts, post-cluster mempool. ACKs for top commit: sipa: utACK7295986778glozow: code review ACK7295986778murchandamus: utACK7295986778ismaelsadeeq: Re-ACK7295986778willcl-ark: crACK7295986778sdaftuar: ACK7295986778Tree-SHA512: 79593e5a087801c06f06cc8b73aa3e7b96ab938d3b90f5d229c4e4bfca887a77b447605c49aa5eb7ddcead85706c534ac5eb6146ae2396af678f4beaaa5bea8e
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
#include <compare>
|
||||
|
||||
RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool)
|
||||
{
|
||||
AssertLockHeld(pool.cs);
|
||||
@@ -181,3 +183,24 @@ std::optional<std::string> PaysForRBF(CAmount original_fees,
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<std::pair<DiagramCheckError, std::string>> ImprovesFeerateDiagram(CTxMemPool& pool,
|
||||
const CTxMemPool::setEntries& direct_conflicts,
|
||||
const CTxMemPool::setEntries& all_conflicts,
|
||||
CAmount replacement_fees,
|
||||
int64_t replacement_vsize)
|
||||
{
|
||||
// Require that the replacement strictly improve the mempool's feerate diagram.
|
||||
std::vector<FeeFrac> old_diagram, new_diagram;
|
||||
|
||||
const auto diagram_results{pool.CalculateFeerateDiagramsForRBF(replacement_fees, replacement_vsize, direct_conflicts, all_conflicts)};
|
||||
|
||||
if (!diagram_results.has_value()) {
|
||||
return std::make_pair(DiagramCheckError::UNCALCULABLE, util::ErrorString(diagram_results).original);
|
||||
}
|
||||
|
||||
if (!std::is_gt(CompareFeerateDiagram(diagram_results.value().second, diagram_results.value().first))) {
|
||||
return std::make_pair(DiagramCheckError::FAILURE, "insufficient feerate: does not improve feerate diagram");
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
#include <primitives/transaction.h>
|
||||
#include <threadsafety.h>
|
||||
#include <txmempool.h>
|
||||
#include <util/feefrac.h>
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
@@ -33,6 +35,13 @@ enum class RBFTransactionState {
|
||||
FINAL,
|
||||
};
|
||||
|
||||
enum class DiagramCheckError {
|
||||
/** Unable to calculate due to topology or other reason */
|
||||
UNCALCULABLE,
|
||||
/** New diagram wasn't strictly superior */
|
||||
FAILURE,
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine whether an unconfirmed transaction is signaling opt-in to RBF
|
||||
* according to BIP 125
|
||||
@@ -106,4 +115,21 @@ std::optional<std::string> PaysForRBF(CAmount original_fees,
|
||||
CFeeRate relay_fee,
|
||||
const uint256& txid);
|
||||
|
||||
/**
|
||||
* The replacement transaction must improve the feerate diagram of the mempool.
|
||||
* @param[in] pool The mempool.
|
||||
* @param[in] direct_conflicts Set of in-mempool txids corresponding to the direct conflicts i.e.
|
||||
* input double-spends with the proposed transaction
|
||||
* @param[in] all_conflicts Set of mempool entries corresponding to all transactions to be evicted
|
||||
* @param[in] replacement_fees Fees of proposed replacement package
|
||||
* @param[in] replacement_vsize Size of proposed replacement package
|
||||
* @returns error type and string if mempool diagram doesn't improve, otherwise std::nullopt.
|
||||
*/
|
||||
std::optional<std::pair<DiagramCheckError, std::string>> ImprovesFeerateDiagram(CTxMemPool& pool,
|
||||
const CTxMemPool::setEntries& direct_conflicts,
|
||||
const CTxMemPool::setEntries& all_conflicts,
|
||||
CAmount replacement_fees,
|
||||
int64_t replacement_vsize)
|
||||
EXCLUSIVE_LOCKS_REQUIRED(pool.cs);
|
||||
|
||||
#endif // BITCOIN_POLICY_RBF_H
|
||||
|
||||
Reference in New Issue
Block a user