Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
coin_selection.cpp File Reference
#include <bench/bench.h>
#include <consensus/amount.h>
#include <interfaces/chain.h>
#include <node/context.h>
#include <outputtype.h>
#include <policy/feerate.h>
#include <policy/policy.h>
#include <primitives/transaction.h>
#include <random.h>
#include <sync.h>
#include <util/result.h>
#include <wallet/coinselection.h>
#include <wallet/spend.h>
#include <wallet/test/util.h>
#include <wallet/transaction.h>
#include <wallet/wallet.h>
#include <cassert>
#include <map>
#include <memory>
#include <set>
#include <utility>
#include <vector>
Include dependency graph for coin_selection.cpp:

Go to the source code of this file.

Classes

struct  NodeContext
struct  COutput
 A UTXO under consideration for use in funding a new transaction. More...
class  CWallet
 A CWallet maintains a set of transactions and balances, and provides the ability to create new transactions. More...
class  CWalletTx
 A transaction with a bunch of additional info that only the owner cares about. More...
struct  CoinEligibilityFilter
 Parameters for filtering which OutputGroups we may use in coin selection. More...
struct  CoinSelectionParams
 Parameters for one iteration of Coin Selection. More...
struct  OutputGroup
 A group of UTXOs paid to the same output script. More...
struct  TxStateInactive

Functions

static void addCoin (const CAmount &nValue, const CWallet &wallet, std::vector< std::unique_ptr< CWalletTx > > &wtxs)
static void CoinSelection (benchmark::Bench &bench)
static void add_coin (const CAmount &nValue, int nInput, std::vector< OutputGroup > &set)
static CAmount make_hard_case (int utxos, std::vector< OutputGroup > &utxo_pool)
static void BnBExhaustion (benchmark::Bench &bench)
 BENCHMARK (CoinSelection)
 BENCHMARK (BnBExhaustion)
util::Result< SelectionResult > AttemptSelection (interfaces::Chain &chain, const CAmount &nTargetValue, OutputGroupTypeMap &groups, const CoinSelectionParams &coin_selection_params, bool allow_mixed_output_types)
 Attempt to find a valid input set that preserves privacy by not mixing OutputTypes.
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase (MockableData records)
util::Result< SelectionResult > SelectCoinsBnB (std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, const CAmount &cost_of_change, int max_selection_weight)

Variables

static constexpr CAmount CHANGE_LOWER
 lower bound for randomly-chosen target change amount

Function Documentation

◆ add_coin()

void add_coin ( const CAmount & nValue,
int nInput,
std::vector< OutputGroup > & set )
static

Definition at line 103 of file coin_selection.cpp.

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

◆ addCoin()

void addCoin ( const CAmount & nValue,
const CWallet & wallet,
std::vector< std::unique_ptr< CWalletTx > > & wtxs )
static

Definition at line 42 of file coin_selection.cpp.

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

◆ AttemptSelection()

util::Result< SelectionResult > wallet::AttemptSelection ( interfaces::Chain & chain,
const CAmount & nTargetValue,
OutputGroupTypeMap & groups,
const CoinSelectionParams & coin_selection_params,
bool allow_mixed_output_types )

Attempt to find a valid input set that preserves privacy by not mixing OutputTypes.

ChooseSelectionResult() will be called on each OutputType individually and the best the solution (according to the waste metric) will be chosen. If a valid input cannot be found from any single OutputType, fallback to running ChooseSelectionResult() over all available coins.

Parameters
[in]chainThe chain interface to get information on bump fees for unconfirmed UTXOs
[in]nTargetValueThe target value
[in]groupsThe grouped outputs mapped by coin eligibility filters
[in]coin_selection_paramsParameters for the coin selection
[in]allow_mixed_output_typesRelax restriction that SelectionResults must be of the same OutputType returns If successful, a SelectionResult containing the input set If failed, returns (1) an empty error message if the target was not reached (general "Insufficient funds") or (2) a specific error message if there was something particularly wrong (e.g. a selection result that surpassed the tx max weight size).

Definition at line 702 of file spend.cpp.

Here is the caller graph for this function:

◆ BENCHMARK() [1/2]

BENCHMARK ( BnBExhaustion )
Here is the call graph for this function:

◆ BENCHMARK() [2/2]

BENCHMARK ( CoinSelection )
Here is the call graph for this function:

◆ BnBExhaustion()

void BnBExhaustion ( benchmark::Bench & bench)
static

Definition at line 125 of file coin_selection.cpp.

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

◆ CoinSelection()

void CoinSelection ( benchmark::Bench & bench)
static

Definition at line 59 of file coin_selection.cpp.

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

◆ CreateMockableWalletDatabase()

std::unique_ptr< WalletDatabase > wallet::CreateMockableWalletDatabase ( MockableData records = {})

Definition at line 211 of file util.cpp.

Here is the caller graph for this function:

◆ make_hard_case()

CAmount make_hard_case ( int utxos,
std::vector< OutputGroup > & utxo_pool )
static

Definition at line 113 of file coin_selection.cpp.

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

◆ SelectCoinsBnB()

util::Result< SelectionResult > wallet::SelectCoinsBnB ( std::vector< OutputGroup > & utxo_pool,
const CAmount & selection_target,
const CAmount & cost_of_change,
int max_selection_weight )

Definition at line 93 of file coinselection.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ CHANGE_LOWER

CAmount wallet::CHANGE_LOWER
staticconstexpr

lower bound for randomly-chosen target change amount

Definition at line 23 of file coinselection.h.