5 #ifndef BITCOIN_WALLET_COINSELECTION_H 6 #define BITCOIN_WALLET_COINSELECTION_H 34 std::optional<CAmount>
fee;
264 void Insert(
const std::shared_ptr<COutput>& output,
size_t ancestors,
size_t descendants);
344 throw std::runtime_error(
STR_INTERNAL_BUG(
"Shared UTXOs among selection results"));
380 void AddInputs(
const std::set<std::shared_ptr<COutput>>& inputs,
bool subtract_fee_outputs);
398 const std::set<std::shared_ptr<COutput>>&
GetInputSet()
const;
450 #endif // BITCOIN_WALLET_COINSELECTION_H
COutput(const COutPoint &outpoint, const CTxOut &txout, int depth, int input_bytes, bool spendable, bool solvable, bool safe, int64_t time, bool from_me, const CAmount fees)
bool m_subtract_fee_outputs
Indicate that we are subtracting the fee from outputs.
util::Result< SelectionResult > SelectCoinsSRD(const std::vector< OutputGroup > &utxo_pool, CAmount target_value, CAmount change_fee, FastRandomContext &rng, int max_weight)
Select coins by Single Random Draw.
COutPoint outpoint
The outpoint identifying this UTXO.
bool solvable
Whether we know how to spend this output, ignoring the lack of keys.
const bool m_include_partial_groups
When avoid_reuse=true and there are full groups (OUTPUT_GROUP_MAX_ENTRIES), whether or not to use any...
FastRandomContext & rng_fast
Randomness to use in the context of coin selection.
CAmount m_value
The total value of the UTXOs in sum.
COutput(const COutPoint &outpoint, const CTxOut &txout, int depth, int input_bytes, bool spendable, bool solvable, bool safe, int64_t time, bool from_me, const std::optional< CFeeRate > feerate=std::nullopt)
CAmount min_viable_change
Minimum amount for creating a change output.
CAmount GetEffectiveValue() const
std::map< OutputType, Groups > groups_by_type
Stores several 'Groups' whose were mapped by output type.
CAmount fee
The fee to spend these UTXOs at the effective feerate.
const uint64_t max_descendants
Maximum number of descendants that a single UTXO in the OutputGroup may have.
size_t m_ancestors
The aggregated count of unconfirmed ancestors of all UTXOs in this group.
void AddInput(const OutputGroup &group)
util::Result< SelectionResult > SelectCoinsBnB(std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, const CAmount &cost_of_change, int max_weight)
const uint64_t max_ancestors
Maximum number of unconfirmed ancestors aggregated across all UTXOs in an OutputGroup.
int64_t time
The time of the transaction containing this output as determined by CWalletTx::nTimeSmart.
void AddInputs(const std::set< std::shared_ptr< COutput >> &inputs, bool subtract_fee_outputs)
int m_weight
Total weight of the UTXOs in this group.
static constexpr CAmount CHANGE_LOWER
lower bound for randomly-chosen target change amount
CoinSelectionParams(FastRandomContext &rng_fast)
void ApplyBumpFee(CAmount bump_fee)
CoinEligibilityFilter(int conf_mine, int conf_theirs, uint64_t max_ancestors)
bool spendable
Whether we have the private keys to spend this output.
void insert(Tdst &dst, const Tsrc &src)
Simplification of std insertion.
bool operator<(SelectionResult other) const
bool m_use_effective
Whether the input values for calculations should be the effective value (true) or normal value (false...
CAmount GetChange(const CAmount min_viable_change, const CAmount change_fee) const
Get the amount for the change output after paying needed fees.
CoinEligibilityFilter(int conf_mine, int conf_theirs, uint64_t max_ancestors, uint64_t max_descendants, bool include_partial)
CAmount effective_value
The value of the UTXOs after deducting the cost of spending them at the effective feerate...
void Push(const OutputGroup &group, OutputType type, bool insert_positive, bool insert_mixed)
CTxOut txout
The output itself.
CAmount GetTarget() const
CoinSelectionParams(FastRandomContext &rng_fast, size_t change_output_size, size_t change_spend_size, CAmount min_change_target, CFeeRate effective_feerate, CFeeRate long_term_feerate, CFeeRate discard_feerate, size_t tx_noinputs_size, bool avoid_partial)
int64_t CAmount
Amount in satoshis (Can be negative)
CAmount bump_fee_group_discount
How much individual inputs overestimated the bump fees for the shared ancestry.
bool safe
Whether this output is considered safe to spend.
bool operator<(const CoinEligibilityFilter &other) const
CFeeRate m_effective_feerate
The targeted feerate of the transaction being built.
std::string ToString() const
CAmount long_term_fee
The fee required to spend this output at the consolidation feerate.
CAmount GetTotalBumpFees() const
bool EligibleForSpending(const CoinEligibilityFilter &eligibility_filter) const
CoinEligibilityFilter(int conf_mine, int conf_theirs, uint64_t max_ancestors, uint64_t max_descendants)
CAmount m_min_change_target
Mininmum change to target in Knapsack solver: select coins to cover the payment and at least this val...
size_t m_descendants
The maximum count of descendants of a single UTXO in this output group.
bool from_me
Whether the transaction containing this output is sent from the owning wallet.
std::vector< OutputGroup > positive_group
CAmount GetSelectedEffectiveValue() const
std::optional< CAmount > fee
The fee required to spend this output at the transaction's target feerate and to bump its unconfirmed...
std::set< std::shared_ptr< COutput > > m_selected_inputs
Set of inputs selected by the algorithm to use in the transaction.
SelectionAlgorithm GetAlgo() const
std::optional< CAmount > m_waste
The computed waste.
int depth
Depth in block chain.
CFeeRate m_long_term_feerate
The feerate estimate used to estimate an upper bound on what should be sufficient to spend the change...
const std::set< std::shared_ptr< COutput > > & GetInputSet() const
Get m_selected_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...
CFeeRate m_long_term_feerate
The feerate for spending a created change output eventually (i.e.
CFeeRate m_discard_feerate
If the cost to spend a change output at the discard feerate exceeds its value, drop it to fees...
CAmount m_cost_of_change
Cost of creating the change output + cost of spending the change output in the future.
util::Result< SelectionResult > KnapsackSolver(std::vector< OutputGroup > &groups, const CAmount &nTargetValue, CAmount change_target, FastRandomContext &rng, int max_weight)
bool HasEffectiveValue() const
CAmount GetSelectionAmount() const
SelectionAlgorithm m_algo
The algorithm used to produce this result.
An output of a transaction.
A group of UTXOs paid to the same output script.
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.
void InsertInputs(const T &inputs)
An outpoint - a combination of a transaction hash and an index n into its vout.
bool m_avoid_partial_spends
When true, always spend all (up to OUTPUT_GROUP_MAX_ENTRIES) or none of the outputs associated with t...
int m_weight
Total weight of the selected inputs.
Parameters for one iteration of Coin Selection.
size_t tx_noinputs_size
Size of the transaction before coin selection, consisting of the header and recipient output(s)...
std::vector< std::shared_ptr< COutput > > m_outputs
The list of UTXOs contained in this output group.
bool m_subtract_fee_outputs
Indicate that we are subtracting the fee from outputs.
size_t change_output_size
Size of a change output in bytes, determined by the output type.
Parameters for filtering which OutputGroups we may use in coin selection.
bool m_include_unsafe_inputs
When true, allow unsafe coins to be selected during Coin Selection.
std::vector< OutputGroup > mixed_group
const int conf_mine
Minimum number of confirmations for outputs that we sent to ourselves.
int input_bytes
Pre-computed estimated size of this output as a fully-signed input in a transaction.
SelectionResult(const CAmount target, SelectionAlgorithm algo)
int m_depth
The minimum number of confirmations the UTXOs in the group have.
OutputGroup(const CoinSelectionParams ¶ms)
CoinEligibilityFilter()=delete
std::string GetAlgorithmName(const SelectionAlgorithm algo)
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
size_t change_spend_size
Size of the input to spend a change output in virtual bytes.
void Insert(const std::shared_ptr< COutput > &output, size_t ancestors, size_t descendants)
CAmount GetSelectedValue() const
Get the sum of the input values.
#define STR_INTERNAL_BUG(msg)
CAmount long_term_fee
The fee to spend these UTXOs at the long term feerate.
bool operator<(const COutput &rhs) const
static constexpr CAmount CHANGE_UPPER
upper bound for randomly-chosen target change amount
bool m_from_me
Whether the UTXOs were sent by the wallet to itself.
std::optional< CAmount > effective_value
The output's value minus fees required to spend it and bump its unconfirmed ancestors to the target f...
A UTXO under consideration for use in funding a new transaction.
std::vector< std::shared_ptr< COutput > > GetShuffledInputVector() const
Get the vector of COutputs that will be used to fill in a CTransaction's vin.
CAmount GenerateChangeTarget(const CAmount payment_value, const CAmount change_fee, FastRandomContext &rng)
Choose a random change target for each transaction to make it harder to fingerprint the Core wallet b...
const int conf_theirs
Minimum number of confirmations for outputs received from a different wallet.
void SetBumpFeeDiscount(const CAmount discount)
How much individual inputs overestimated the bump fees for shared ancestries.
CAmount ancestor_bump_fees
The fee necessary to bump this UTXO's ancestor transactions to the target feerate.
CAmount m_change_fee
Cost of creating the change output.
void Merge(const SelectionResult &other)
Combines the.
CAmount m_target
The target the algorithm selected for.
std::map< CoinEligibilityFilter, OutputGroupTypeMap > FilteredOutputGroups