Bitcoin Core  27.99.0
P2P Digital Currency
Public Member Functions | Private Member Functions | Private Attributes | List of all members
wallet::SelectionResult Struct Reference

#include <coinselection.h>

Public Member Functions

 SelectionResult (const CAmount target, SelectionAlgorithm algo)
 
 SelectionResult ()=delete
 
CAmount GetSelectedValue () const
 Get the sum of the input values. More...
 
CAmount GetSelectedEffectiveValue () const
 
CAmount GetTotalBumpFees () const
 
void Clear ()
 
void AddInput (const OutputGroup &group)
 
void AddInputs (const std::set< std::shared_ptr< COutput >> &inputs, bool subtract_fee_outputs)
 
void SetBumpFeeDiscount (const CAmount discount)
 How much individual inputs overestimated the bump fees for shared ancestries. More...
 
void ComputeAndSetWaste (const CAmount min_viable_change, const CAmount change_cost, const CAmount change_fee)
 Calculates and stores the waste for this selection via GetSelectionWaste. More...
 
CAmount GetWaste () const
 
void SetAlgoCompleted (bool algo_completed)
 Tracks that algorithm was able to exhaustively search the entire combination space before hitting limit of tries. More...
 
bool GetAlgoCompleted () const
 Get m_algo_completed. More...
 
void SetSelectionsEvaluated (size_t attempts)
 Record the number of selections that were evaluated. More...
 
size_t GetSelectionsEvaluated () const
 Get selections_evaluated. More...
 
void Merge (const SelectionResult &other)
 Combines the. More...
 
const std::set< std::shared_ptr< COutput > > & GetInputSet () const
 Get m_selected_inputs. More...
 
std::vector< std::shared_ptr< COutput > > GetShuffledInputVector () const
 Get the vector of COutputs that will be used to fill in a CTransaction's vin. More...
 
bool operator< (SelectionResult other) const
 
CAmount GetChange (const CAmount min_viable_change, const CAmount change_fee) const
 Get the amount for the change output after paying needed fees. More...
 
CAmount GetTarget () const
 
SelectionAlgorithm GetAlgo () const
 
int GetWeight () const
 

Private Member Functions

template<typename T >
void InsertInputs (const T &inputs)
 
CAmount GetSelectionWaste (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. More...
 

Private Attributes

std::set< std::shared_ptr< COutput > > m_selected_inputs
 Set of inputs selected by the algorithm to use in the transaction. More...
 
CAmount m_target
 The target the algorithm selected for. More...
 
SelectionAlgorithm m_algo
 The algorithm used to produce this result. More...
 
bool m_use_effective {false}
 Whether the input values for calculations should be the effective value (true) or normal value (false) More...
 
std::optional< CAmountm_waste
 The computed waste. More...
 
bool m_algo_completed {true}
 False if algorithm was cut short by hitting limit of attempts and solution is non-optimal. More...
 
size_t m_selections_evaluated
 The count of selections that were evaluated by this coin selection attempt. More...
 
int m_weight {0}
 Total weight of the selected inputs. More...
 
CAmount bump_fee_group_discount {0}
 How much individual inputs overestimated the bump fees for the shared ancestry. More...
 

Detailed Description

Definition at line 320 of file coinselection.h.

Constructor & Destructor Documentation

◆ SelectionResult() [1/2]

wallet::SelectionResult::SelectionResult ( const CAmount  target,
SelectionAlgorithm  algo 
)
inlineexplicit

Definition at line 370 of file coinselection.h.

◆ SelectionResult() [2/2]

wallet::SelectionResult::SelectionResult ( )
delete

Member Function Documentation

◆ AddInput()

void wallet::SelectionResult::AddInput ( const OutputGroup group)

Definition at line 901 of file coinselection.cpp.

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

◆ AddInputs()

void wallet::SelectionResult::AddInputs ( const std::set< std::shared_ptr< COutput >> &  inputs,
bool  subtract_fee_outputs 
)

Definition at line 910 of file coinselection.cpp.

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

◆ Clear()

void wallet::SelectionResult::Clear ( )

Definition at line 894 of file coinselection.cpp.

Here is the caller graph for this function:

◆ ComputeAndSetWaste()

void wallet::SelectionResult::ComputeAndSetWaste ( const CAmount  min_viable_change,
const CAmount  change_cost,
const CAmount  change_fee 
)

Calculates and stores the waste for this selection via GetSelectionWaste.

Definition at line 843 of file coinselection.cpp.

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

◆ GetAlgo()

SelectionAlgorithm wallet::SelectionResult::GetAlgo ( ) const
inline

Definition at line 442 of file coinselection.h.

Here is the caller graph for this function:

◆ GetAlgoCompleted()

bool wallet::SelectionResult::GetAlgoCompleted ( ) const

Get m_algo_completed.

Definition at line 859 of file coinselection.cpp.

◆ GetChange()

CAmount wallet::SelectionResult::GetChange ( const CAmount  min_viable_change,
const CAmount  change_fee 
) const

Get the amount for the change output after paying needed fees.

The change amount is not 100% precise due to discrepancies in fee calculation. The final change amount (if any) should be corrected after calculating the final tx fees. When there is a discrepancy, most of the time the final change would be slightly bigger than estimated.

Following are the possible factors of discrepancy:

  • non-input fees always include segwit flags
  • input fee estimation always include segwit stack size
  • input fees are rounded individually and not collectively, which leads to small rounding errors
  • input counter size is always assumed to be 1vbyte
Parameters
[in]min_viable_changeMinimum amount for change output, if change would be less then we forgo change
[in]change_feeFees to include change output in the tx
Returns
Amount for change output, 0 when there is no change.

Definition at line 974 of file coinselection.cpp.

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

◆ GetInputSet()

const std::set< std::shared_ptr< COutput > > & wallet::SelectionResult::GetInputSet ( ) const

Get m_selected_inputs.

Definition at line 935 of file coinselection.cpp.

Here is the caller graph for this function:

◆ GetSelectedEffectiveValue()

CAmount wallet::SelectionResult::GetSelectedEffectiveValue ( ) const

Definition at line 884 of file coinselection.cpp.

Here is the caller graph for this function:

◆ GetSelectedValue()

CAmount wallet::SelectionResult::GetSelectedValue ( ) const

Get the sum of the input values.

Definition at line 879 of file coinselection.cpp.

Here is the caller graph for this function:

◆ GetSelectionsEvaluated()

size_t wallet::SelectionResult::GetSelectionsEvaluated ( ) const

Get selections_evaluated.

Definition at line 869 of file coinselection.cpp.

◆ GetSelectionWaste()

CAmount wallet::SelectionResult::GetSelectionWaste ( CAmount  change_cost,
CAmount  target,
bool  use_effective_value = true 
)
private

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]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 795 of file coinselection.cpp.

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

◆ GetShuffledInputVector()

std::vector< std::shared_ptr< COutput > > wallet::SelectionResult::GetShuffledInputVector ( ) const

Get the vector of COutputs that will be used to fill in a CTransaction's vin.

Definition at line 940 of file coinselection.cpp.

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

◆ GetTarget()

CAmount wallet::SelectionResult::GetTarget ( ) const
inline

Definition at line 440 of file coinselection.h.

Here is the caller graph for this function:

◆ GetTotalBumpFees()

CAmount wallet::SelectionResult::GetTotalBumpFees ( ) const

Definition at line 889 of file coinselection.cpp.

◆ GetWaste()

CAmount wallet::SelectionResult::GetWaste ( ) const

Definition at line 874 of file coinselection.cpp.

Here is the caller graph for this function:

◆ GetWeight()

int wallet::SelectionResult::GetWeight ( ) const
inline

Definition at line 444 of file coinselection.h.

Here is the caller graph for this function:

◆ InsertInputs()

template<typename T >
void wallet::SelectionResult::InsertInputs ( const T &  inputs)
inlineprivate

Definition at line 343 of file coinselection.h.

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

◆ Merge()

void wallet::SelectionResult::Merge ( const SelectionResult other)

Combines the.

Parameters
[in]otherselection result into 'this' selection result.

Important note: There must be no shared 'COutput' among the two selection results being combined.

Definition at line 921 of file coinselection.cpp.

Here is the call graph for this function:

◆ operator<()

bool wallet::SelectionResult::operator< ( SelectionResult  other) const

Definition at line 947 of file coinselection.cpp.

◆ SetAlgoCompleted()

void wallet::SelectionResult::SetAlgoCompleted ( bool  algo_completed)

Tracks that algorithm was able to exhaustively search the entire combination space before hitting limit of tries.

Definition at line 854 of file coinselection.cpp.

Here is the caller graph for this function:

◆ SetBumpFeeDiscount()

void wallet::SelectionResult::SetBumpFeeDiscount ( const CAmount  discount)

How much individual inputs overestimated the bump fees for shared ancestries.

Definition at line 835 of file coinselection.cpp.

Here is the call graph for this function:

◆ SetSelectionsEvaluated()

void wallet::SelectionResult::SetSelectionsEvaluated ( size_t  attempts)

Record the number of selections that were evaluated.

Definition at line 864 of file coinselection.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ bump_fee_group_discount

CAmount wallet::SelectionResult::bump_fee_group_discount {0}
private

How much individual inputs overestimated the bump fees for the shared ancestry.

Definition at line 340 of file coinselection.h.

◆ m_algo

SelectionAlgorithm wallet::SelectionResult::m_algo
private

The algorithm used to produce this result.

Definition at line 328 of file coinselection.h.

◆ m_algo_completed

bool wallet::SelectionResult::m_algo_completed {true}
private

False if algorithm was cut short by hitting limit of attempts and solution is non-optimal.

Definition at line 334 of file coinselection.h.

◆ m_selected_inputs

std::set<std::shared_ptr<COutput> > wallet::SelectionResult::m_selected_inputs
private

Set of inputs selected by the algorithm to use in the transaction.

Definition at line 324 of file coinselection.h.

◆ m_selections_evaluated

size_t wallet::SelectionResult::m_selections_evaluated
private

The count of selections that were evaluated by this coin selection attempt.

Definition at line 336 of file coinselection.h.

◆ m_target

CAmount wallet::SelectionResult::m_target
private

The target the algorithm selected for.

Equal to the recipient amount plus non-input fees

Definition at line 326 of file coinselection.h.

◆ m_use_effective

bool wallet::SelectionResult::m_use_effective {false}
private

Whether the input values for calculations should be the effective value (true) or normal value (false)

Definition at line 330 of file coinselection.h.

◆ m_waste

std::optional<CAmount> wallet::SelectionResult::m_waste
private

The computed waste.

Definition at line 332 of file coinselection.h.

◆ m_weight

int wallet::SelectionResult::m_weight {0}
private

Total weight of the selected inputs.

Definition at line 338 of file coinselection.h.


The documentation for this struct was generated from the following files: