Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2016-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_POLICY_RBF_H6#define BITCOIN_POLICY_RBF_H8#include <consensus/amount.h>9#include <primitives/transaction.h>10#include <sync.h>11#include <txmempool.h>12#include <util/feefrac.h>14#include <compare>15#include <cstddef>16#include <cstdint>17#include <optional>18#include <set>19#include <string>21class CFeeRate;22class uint256;24/** Maximum number of unique clusters that can be affected by an RBF (Rule #5);25* see GetEntriesForConflicts() */26inline constexpr uint32_t MAX_REPLACEMENT_CANDIDATES{100};28/** The rbf state of unconfirmed transactions */29enum class RBFTransactionState {30/** Unconfirmed tx that does not signal rbf and is not in the mempool */31UNKNOWN,32/** Either this tx or a mempool ancestor signals rbf */33REPLACEABLE_BIP125,34/** Neither this tx nor a mempool ancestor signals rbf */35FINAL,36};38enum class DiagramCheckError {39/** Unable to calculate due to topology or other reason */40UNCALCULABLE,41/** New diagram wasn't strictly superior */42FAILURE,43};45/**46* Determine whether an unconfirmed transaction is signaling opt-in to RBF47* according to BIP 12548* This involves checking sequence numbers of the transaction, as well49* as the sequence numbers of all in-mempool ancestors.50*51* @param tx The unconfirmed transaction52* @param pool The mempool, which may contain the tx53*54* @return The rbf state55*/56RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool) EXCLUSIVE_LOCKS_REQUIRED(pool.cs);57RBFTransactionState IsRBFOptInEmptyMempool(const CTransaction& tx);59/** Get all descendants of iters_conflicting. Checks that there are no more than60* MAX_REPLACEMENT_CANDIDATES distinct clusters affected.61*62* @param[in] iters_conflicting The set of iterators to mempool entries.63* @param[out] all_conflicts Populated with all the mempool entries that would be replaced,64* which includes iters_conflicting and all entries' descendants.65* Not cleared at the start; any existing mempool entries will66* remain in the set.67* @returns an error message if the number of affected clusters would exceed MAX_REPLACEMENT_CANDIDATES, std::nullopt otherwise68*/69std::optional<std::string> GetEntriesForConflicts(const CTransaction& tx, CTxMemPool& pool,70const CTxMemPool::setEntries& iters_conflicting,71CTxMemPool::setEntries& all_conflicts)72EXCLUSIVE_LOCKS_REQUIRED(pool.cs);74/** Check the intersection between two sets of transactions (a set of mempool entries and a set of75* txids) to make sure they are disjoint.76* @param[in] ancestors Set of mempool entries corresponding to ancestors of the77* replacement transactions.78* @param[in] direct_conflicts Set of txids corresponding to the mempool conflicts79* (candidates to be replaced).80* @param[in] txid Transaction ID, included in the error message if violation occurs.81* @returns error message if the sets intersect, std::nullopt if they are disjoint.82*/83std::optional<std::string> EntriesAndTxidsDisjoint(const CTxMemPool::setEntries& ancestors,84const std::set<Txid>& direct_conflicts,85const Txid& txid);87/** The replacement transaction must pay more fees than the original transactions. The additional88* fees must pay for the replacement's bandwidth at or above the incremental relay feerate.89* @param[in] original_fees Total modified fees of original transaction(s).90* @param[in] replacement_fees Total modified fees of replacement transaction(s).91* @param[in] replacement_vsize Total virtual size of replacement transaction(s).92* @param[in] relay_fee The node's minimum feerate for transaction relay.93* @param[in] txid Transaction ID, included in the error message if violation occurs.94* @returns error string if fees are insufficient, otherwise std::nullopt.95*/96std::optional<std::string> PaysForRBF(CAmount original_fees,97CAmount replacement_fees,98size_t replacement_vsize,99CFeeRate relay_fee,100const Txid& txid);102/**103* The replacement transaction must improve the feerate diagram of the mempool.104* @param[in] changeset The changeset containing proposed additions/removals105* @returns error type and string if mempool diagram doesn't improve, otherwise std::nullopt.106*/107std::optional<std::pair<DiagramCheckError, std::string>> ImprovesFeerateDiagram(CTxMemPool::ChangeSet& changeset);109#endif // BITCOIN_POLICY_RBF_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.