1 suggestion
Optional improvements
[suggestion] · Cleared-selection test leaves effective value unchecked
The test catches a missing reset but would accept a fee-only workaround that leaves the cleared selection's effective value nonzero; no current production caller clears a discounted selection.
Location: src/wallet/test/coinselector_tests.cpp:881 (head).
Details and suggested fix
The fixture sets a discount of 30 before calling Clear(). The existing GetTotalBumpFees() == 0 assertion catches removal of the reset, but clamping that getter at zero would also pass while GetSelectedEffectiveValue() still returns 30. Add BOOST_CHECK_EQUAL(selection.GetSelectedEffectiveValue(), 0); alongside the new assertion to check that clearing removes the input-dependent credit as well as the negative-fee symptom. The current implementation satisfies both checks.
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
The discount was introduced as an end-of-selection correction: reduce fees by the difference between individual bump-fee estimates and the collective estimate. Its field documentation describes an overestimate caused by shared ancestry, and its setter states that overlapping ancestry can only lower fees.
This establishes the discount as accounting for a particular selected input set, rather than a persistent fee credit independent of those inputs. It documents when the correction should be applied, but does not specify what Clear() must do afterward.
Ralph's inferences
The inspected call order supports a two-stage lifecycle: construct or replace candidate input sets inside the solvers, then apply the shared-ancestor correction to completed candidates before comparing their waste. This explains why existing solver reuse did not require a post-discount clearing contract.
In the pinned base, KnapsackSolver clears and repopulates its local result while searching. ChooseSelectionResult applies the discount only after the solvers return. This supports the existing usage pattern, not an assertion that clearing after discounting was intentionally forbidden.
Clear() appears to be a candidate-reset operation rather than reconstruction of the entire SelectionResult: it removes inputs and resets derived waste and weight while retaining the selection target and algorithm. No inspected declaration documents a precondition that the discount must still be zero, and the evidence does not establish that preserving a discount across clearing was deliberate.
The lifecycle question is therefore only partly answered historically: pre-discount clearing and reuse are demonstrated, while post-discount clearing is unspecified in the inspected record. The current change adds discount reset to that candidate-reset operation; historical silence does not establish either an intentional restriction or an intentional carry-over contract.