Bitcoin Core  22.99.0
P2P Digital Currency
Enumerations | Functions | Variables
rbf.h File Reference
#include <txmempool.h>
Include dependency graph for rbf.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  RBFTransactionState { RBFTransactionState::UNKNOWN, RBFTransactionState::REPLACEABLE_BIP125, RBFTransactionState::FINAL }
 The rbf state of unconfirmed transactions. More...
 

Functions

RBFTransactionState IsRBFOptIn (const CTransaction &tx, const CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
 Determine whether an unconfirmed transaction is signaling opt-in to RBF according to BIP 125 This involves checking sequence numbers of the transaction, as well as the sequence numbers of all in-mempool ancestors. More...
 
RBFTransactionState IsRBFOptInEmptyMempool (const CTransaction &tx)
 
std::optional< std::string > GetEntriesForConflicts (const CTransaction &tx, CTxMemPool &pool, const CTxMemPool::setEntries &iters_conflicting, CTxMemPool::setEntries &all_conflicts) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
 Get all descendants of iters_conflicting. More...
 
std::optional< std::string > HasNoNewUnconfirmed (const CTransaction &tx, const CTxMemPool &pool, const CTxMemPool::setEntries &iters_conflicting) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
 BIP125 Rule #2: "The replacement transaction may only include an unconfirmed input if that input was included in one of the original transactions. More...
 
std::optional< std::string > EntriesAndTxidsDisjoint (const CTxMemPool::setEntries &ancestors, const std::set< uint256 > &direct_conflicts, const uint256 &txid)
 Check the intersection between two sets of transactions (a set of mempool entries and a set of txids) to make sure they are disjoint. More...
 
std::optional< std::string > PaysMoreThanConflicts (const CTxMemPool::setEntries &iters_conflicting, CFeeRate replacement_feerate, const uint256 &txid)
 Check that the feerate of the replacement transaction(s) is higher than the feerate of each of the transactions in iters_conflicting. More...
 
std::optional< std::string > PaysForRBF (CAmount original_fees, CAmount replacement_fees, size_t replacement_vsize, const uint256 &txid)
 Enforce BIP125 Rule #3 "The replacement transaction pays an absolute fee of at least the sum paid by the original transactions. More...
 

Variables

static constexpr uint32_t MAX_BIP125_REPLACEMENT_CANDIDATES {100}
 Maximum number of transactions that can be replaced by BIP125 RBF (Rule #5). More...
 

Enumeration Type Documentation

◆ RBFTransactionState

enum RBFTransactionState
strong

The rbf state of unconfirmed transactions.

Enumerator
UNKNOWN 

Unconfirmed tx that does not signal rbf and is not in the mempool.

REPLACEABLE_BIP125 

Either this tx or a mempool ancestor signals rbf.

FINAL 

Neither this tx nor a mempool ancestor signals rbf.

Definition at line 15 of file rbf.h.

Function Documentation

◆ EntriesAndTxidsDisjoint()

std::optional<std::string> EntriesAndTxidsDisjoint ( const CTxMemPool::setEntries ancestors,
const std::set< uint256 > &  direct_conflicts,
const uint256 txid 
)

Check the intersection between two sets of transactions (a set of mempool entries and a set of txids) to make sure they are disjoint.

Parameters
[in]ancestorsSet of mempool entries corresponding to ancestors of the replacement transactions.
[in]direct_conflictsSet of txids corresponding to the mempool conflicts (candidates to be replaced).
[in]txidTransaction ID, included in the error message if violation occurs.
Returns
error message if the sets intersect, std::nullopt if they are disjoint.

Definition at line 109 of file rbf.cpp.

Here is the call graph for this function:

◆ GetEntriesForConflicts()

std::optional<std::string> GetEntriesForConflicts ( const CTransaction tx,
CTxMemPool pool,
const CTxMemPool::setEntries iters_conflicting,
CTxMemPool::setEntries all_conflicts 
)

Get all descendants of iters_conflicting.

Also enforce BIP125 Rule #5, "The number of original transactions to be replaced and their descendant transactions which will be evicted from the mempool must not exceed a total of 100 transactions." Quit as early as possible. There cannot be more than MAX_BIP125_REPLACEMENT_CANDIDATES potential entries.

Parameters
[in]iters_conflictingThe set of iterators to mempool entries.
[out]all_conflictsPopulated with all the mempool entries that would be replaced, which includes descendants of iters_conflicting. Not cleared at the start; any existing mempool entries will remain in the set.
Returns
an error message if Rule #5 is broken, otherwise a std::nullopt.

Definition at line 50 of file rbf.cpp.

Here is the call graph for this function:

◆ HasNoNewUnconfirmed()

std::optional<std::string> HasNoNewUnconfirmed ( const CTransaction tx,
const CTxMemPool pool,
const CTxMemPool::setEntries iters_conflicting 
)

BIP125 Rule #2: "The replacement transaction may only include an unconfirmed input if that input was included in one of the original transactions.

"

Returns
error message if Rule #2 is broken, otherwise std::nullopt.

Definition at line 77 of file rbf.cpp.

Here is the call graph for this function:

◆ IsRBFOptIn()

RBFTransactionState IsRBFOptIn ( const CTransaction tx,
const CTxMemPool pool 
)

Determine whether an unconfirmed transaction is signaling opt-in to RBF according to BIP 125 This involves checking sequence numbers of the transaction, as well as the sequence numbers of all in-mempool ancestors.

Parameters
txThe unconfirmed transaction
poolThe mempool, which may contain the tx
Returns
The rbf state

Definition at line 12 of file rbf.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRBFOptInEmptyMempool()

RBFTransactionState IsRBFOptInEmptyMempool ( const CTransaction tx)

Definition at line 44 of file rbf.cpp.

Here is the call graph for this function:

◆ PaysForRBF()

std::optional<std::string> PaysForRBF ( CAmount  original_fees,
CAmount  replacement_fees,
size_t  replacement_vsize,
const uint256 txid 
)

Enforce BIP125 Rule #3 "The replacement transaction pays an absolute fee of at least the sum paid by the original transactions.

" Enforce BIP125 Rule #4 "The replacement transaction must also pay for its own bandwidth at or above the rate set by the node's minimum relay fee setting."

Parameters
[in]original_feesTotal modified fees of original transaction(s).
[in]replacement_feesTotal modified fees of replacement transaction(s).
[in]replacement_vsizeTotal virtual size of replacement transaction(s).
[in]txidTransaction ID, included in the error message if violation occurs.
Returns
error string if fees are insufficient, otherwise std::nullopt.

Definition at line 150 of file rbf.cpp.

Here is the call graph for this function:

◆ PaysMoreThanConflicts()

std::optional<std::string> PaysMoreThanConflicts ( const CTxMemPool::setEntries iters_conflicting,
CFeeRate  replacement_feerate,
const uint256 txid 
)

Check that the feerate of the replacement transaction(s) is higher than the feerate of each of the transactions in iters_conflicting.

Parameters
[in]iters_conflictingThe set of mempool entries.
Returns
error message if fees insufficient, otherwise std::nullopt.

Definition at line 124 of file rbf.cpp.

Here is the call graph for this function:

Variable Documentation

◆ MAX_BIP125_REPLACEMENT_CANDIDATES

constexpr uint32_t MAX_BIP125_REPLACEMENT_CANDIDATES {100}
staticconstexpr

Maximum number of transactions that can be replaced by BIP125 RBF (Rule #5).

This includes all mempool conflicts and their descendants.

Definition at line 12 of file rbf.h.