5 #ifndef BITCOIN_WALLET_COINSELECTION_H 6 #define BITCOIN_WALLET_COINSELECTION_H 28 std::optional<CAmount>
fee;
232 void Insert(
const COutput& output,
size_t ancestors,
size_t descendants,
bool positive_only);
349 std::optional<SelectionResult>
SelectCoinsBnB(std::vector<OutputGroup>& utxo_pool,
const CAmount& selection_target,
const CAmount& cost_of_change);
361 std::optional<SelectionResult>
KnapsackSolver(std::vector<OutputGroup>& groups,
const CAmount& nTargetValue,
365 #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.
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 GetSelectionWaste(const std::set< COutput > &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...
CAmount GetEffectiveValue() const
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)
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.
static constexpr CAmount CHANGE_LOWER
lower bound for randomly-chosen target change amount
void Insert(const COutput &output, size_t ancestors, size_t descendants, bool positive_only)
CoinSelectionParams(FastRandomContext &rng_fast)
CoinEligibilityFilter(int conf_mine, int conf_theirs, uint64_t max_ancestors)
bool spendable
Whether we have the private keys to spend this output.
bool operator<(SelectionResult other) const
std::optional< SelectionResult > SelectCoinsBnB(std::vector< OutputGroup > &utxo_pool, const CAmount &selection_target, const CAmount &cost_of_change)
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...
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)
bool safe
Whether this output is considered safe to spend.
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.
std::set< COutput > m_selected_inputs
Set of inputs selected by the algorithm to use in the transaction.
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.
CAmount GetSelectedEffectiveValue() const
std::optional< CAmount > fee
The fee required to spend this output at the transaction's target feerate.
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...
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.
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.
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...
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)...
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.
const std::set< COutput > & GetInputSet() const
Get m_selected_inputs.
Parameters for filtering which OutputGroups we may use in coin selection.
const int conf_mine
Minimum number of confirmations for outputs that we sent to ourselves.
std::optional< SelectionResult > SelectCoinsSRD(const std::vector< OutputGroup > &utxo_pool, CAmount target_value, FastRandomContext &rng)
Select coins by Single Random Draw.
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)
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.
CAmount GetSelectedValue() const
Get the sum of the input values.
CAmount long_term_fee
The fee to spend these UTXOs at the long term feerate.
bool operator<(const COutput &rhs) const
std::vector< COutput > GetShuffledInputVector() const
Get the vector of COutputs that will be used to fill in a CTransaction's vin.
static constexpr CAmount CHANGE_UPPER
upper bound for randomly-chosen target change amount
std::optional< SelectionResult > KnapsackSolver(std::vector< OutputGroup > &groups, const CAmount &nTargetValue, CAmount change_target, FastRandomContext &rng)
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.
A UTXO under consideration for use in funding a new transaction.
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.
CFeeRate m_effective_feerate
The target feerate of the transaction we're trying to build.
CAmount m_change_fee
Cost of creating the change output.
void Merge(const SelectionResult &other)
CAmount m_target
The target the algorithm selected for.
std::vector< COutput > m_outputs
The list of UTXOs contained in this output group.