Bitcoin Core  22.99.0
P2P Digital Currency
Functions | Variables
coinselection.cpp File Reference
#include <wallet/coinselection.h>
#include <policy/feerate.h>
#include <util/system.h>
#include <util/moneystr.h>
#include <optional>
Include dependency graph for coinselection.cpp:

Go to the source code of this file.

Functions

bool SelectCoinsBnB (std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, const CAmount &cost_of_change, std::set< CInputCoin > &out_set, CAmount &value_ret)
 
static void ApproximateBestSubset (const std::vector< OutputGroup > &groups, const CAmount &nTotalLower, const CAmount &nTargetValue, std::vector< char > &vfBest, CAmount &nBest, int iterations=1000)
 
bool KnapsackSolver (const CAmount &nTargetValue, std::vector< OutputGroup > &groups, std::set< CInputCoin > &setCoinsRet, CAmount &nValueRet)
 
CAmount GetSelectionWaste (const std::set< CInputCoin > &inputs, CAmount change_cost, CAmount target, bool use_effective_value)
 Compute the waste for this result given the cost of change and the opportunity cost of spending these inputs now vs in the future. More...
 

Variables

struct {
descending
 
static const size_t TOTAL_TRIES = 100000
 

Function Documentation

◆ ApproximateBestSubset()

static void ApproximateBestSubset ( const std::vector< OutputGroup > &  groups,
const CAmount nTotalLower,
const CAmount nTargetValue,
std::vector< char > &  vfBest,
CAmount nBest,
int  iterations = 1000 
)
static

Definition at line 171 of file coinselection.cpp.

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

◆ GetSelectionWaste()

CAmount GetSelectionWaste ( const std::set< CInputCoin > &  inputs,
CAmount  change_cost,
CAmount  target,
bool  use_effective_value = true 
)

Compute the waste for this result given the cost of change and the opportunity cost of spending these inputs now vs in the future.

If change exists, waste = change_cost + inputs * (effective_feerate - long_term_feerate) If no change, waste = excess + inputs * (effective_feerate - long_term_feerate) where excess = selected_effective_value - target change_cost = effective_feerate * change_output_size + long_term_feerate * change_spend_size

Parameters
[in]inputsThe selected inputs
[in]change_costThe cost of creating change and spending it in the future. Only used if there is change, in which case it must be positive. Must be 0 if there is no change.
[in]targetThe amount targeted by the coin selection algorithm.
[in]use_effective_valueWhether to use the input's effective value (when true) or the real value (when false).
Returns
The waste

Definition at line 345 of file coinselection.cpp.

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

◆ KnapsackSolver()

bool KnapsackSolver ( const CAmount nTargetValue,
std::vector< OutputGroup > &  groups,
std::set< CInputCoin > &  setCoinsRet,
CAmount nValueRet 
)

Definition at line 217 of file coinselection.cpp.

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

◆ SelectCoinsBnB()

bool SelectCoinsBnB ( std::vector< OutputGroup > &  utxo_pool,
const CAmount selection_target,
const CAmount cost_of_change,
std::set< CInputCoin > &  out_set,
CAmount value_ret 
)

Definition at line 64 of file coinselection.cpp.

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

Variable Documentation

◆ descending

struct { ... } descending

◆ TOTAL_TRIES

const size_t TOTAL_TRIES = 100000
static

Definition at line 62 of file coinselection.cpp.