Repository: bitcoin/bitcoin
File: src/wallet/coinselection.h (C/C++)

Code before:
     *
     * @param[in] change_cost The 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.
     * @param[in] target The amount targeted by the coin selection algorithm.
     * @param[in] use_effective_value Whether to use the input's effective value (when true) or the real value (when false).
     * @return The waste
     */
    [[nodiscard]] CAmount GetSelectionWaste(CAmount change_cost, CAmount target, bool use_effective_value = true);

public:
    explicit SelectionResult(const CAmount target, SelectionAlgorithm algo)
        : m_target(target), m_algo(algo) {}

    SelectionResult() = delete;

    /** Get the sum of the input values */
    [[nodiscard]] CAmount GetSelectedValue() const;

    [[nodiscard]] CAmount GetSelectedEffectiveValue() const;

    [[nodiscard]] CAmount GetTotalBumpFees() const;

    void Clear();

    void AddInput(const OutputGroup& group);
    void AddInputs(const std::set<std::shared_ptr<COutput>>& inputs, bool subtract_fee_outputs);

    /** How much individual inputs overestimated the bump fees for shared ancestries */
    void SetBumpFeeDiscount(const CAmount discount);

    /** Calculates and stores the waste for this selection via GetSelectionWaste */
    void ComputeAndSetWaste(const CAmount min_viable_change, const CAmount change_cost, const CAmount change_fee);
    [[nodiscard]] CAmount GetWaste() const;

    /** Tracks that algorithm was able to exhaustively search the entire combination space before hitting limit of tries */
    void SetAlgoCompleted(bool algo_completed);

    /** Get m_algo_completed */
    bool GetAlgoCompleted() const;

    /** Record the number of selections that were evaluated */
    void SetSelectionsEvaluated(size_t attempts);

    /** Get selections_evaluated */
    size_t GetSelectionsEvaluated() const ;

    /**
     * Combines the @param[in] other selection result into 'this' selection result.
     *
     * Important note:

Review comment (suggestion):
From the commit message in e95b9159380f2de7f9a6e7a202cc171ad285ee6c you mention we can have change_cost of 0 and also a change output, so this is no longer the case?
```suggestion
    * @param[in] change_cost       The cost of creating change and spending it in the future.
     *                              Only used if there is change.
```

Code after:
    /** Get the sum of the input values */
    [[nodiscard]] CAmount GetSelectedValue() const;

    [[nodiscard]] CAmount GetSelectedEffectiveValue() const;

    [[nodiscard]] CAmount GetTotalBumpFees() const;

    void Clear();

    void AddInput(const OutputGroup& group);
    void AddInputs(const std::set<std::shared_ptr<COutput>>& inputs, bool subtract_fee_outputs);

    /** How much individual inputs overestimated the bump fees for shared ancestries */
    void SetBumpFeeDiscount(const CAmount discount);

    /** Calculates and stores 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) - bump_fee_group_discount
     * If no change, waste = excess + inputs * (effective_feerate - long_term_feerate) - bump_fee_group_discount
     * where excess = selected_effective_value - target
     * change_cost = effective_feerate * change_output_size + long_term_feerate * change_spend_size
     *
     * @param[in] min_viable_change The minimum amount necessary to make a change output economic
     * @param[in] change_cost       The cost of creating a change output and spending it in the future. Only
     *                              used if there is change, in which case it must be non-negative.
     * @param[in] change_fee        The fee for creating a change output
     */
    void RecalculateWaste(const CAmount min_viable_change, const CAmount change_cost, const CAmount change_fee);
    [[nodiscard]] CAmount GetWaste() const;

    /** Tracks that algorithm was able to exhaustively search the entire combination space before hitting limit of tries */
    void SetAlgoCompleted(bool algo_completed);

    /** Get m_algo_completed */
    bool GetAlgoCompleted() const;

    /** Record the number of selections that were evaluated */
    void SetSelectionsEvaluated(size_t attempts);

    /** Get selections_evaluated */
    size_t GetSelectionsEvaluated() const ;

    /**
     * Combines the @param[in] other selection result into 'this' selection result.
     *
     * Important note:
     * There must be no shared 'COutput' among the two selection results being combined.
     */
    void Merge(const SelectionResult& other);

    /** Get m_selected_inputs */