2 suggestions
Optional improvements
[suggestion] · Preset-only selections trigger a redundant APS retry
When preset inputs cover the target, the grouped pass selects the same inputs but still reports APS as used, leaving the partial spend unchanged; this behavior also exists on the base branch.
Location: src/wallet/spend.cpp:1255 (head).
Details and suggested fix
When inputs are preselected, automatic inputs are allowed, and the preset inputs cover the target, SelectCoins returns a MANUAL result before automatic selection or grouping, regardless of m_avoid_partial_spends. The new check can still mark the result as a partial spend if another available UTXO has the same scriptPubKey. The grouped pass then makes the same manual selection at the same fee, so use_aps is true and the tracepoint and log report APS as used even though the sibling UTXO remains unspent. This can occur, for example, with fundrawtransaction using add_inputs or with bumpfee. The USDT test asserts this outcome. Leave has_partial_spend false when result.GetAlgo() == SelectionAlgorithm::MANUAL; Merge retains the automatic algorithm when coins were added, so this excludes only preset-only selections. The USDT test that checks the APS change position would then need a scenario where the grouped pass actually selects a different changeless input set.
[suggestion] · Partial-spend counting adds overhead when the retry cannot use it
The wallet builds and discards a per-UTXO map on several paths where the APS retry is disabled; the resulting cost is unmeasured.
Location: src/wallet/spend.cpp:1255 (head).
Details and suggested fix
Whenever m_allow_other_inputs is set, the counting block inserts available and preset UTXOs into a std::map keyed by copied CScript values while cs_wallet is held. The flag is read only by the CreateTransaction retry condition, which also requires wallet.m_max_aps_fee > -1 and !coin_control.m_avoid_partial_spends. The map is therefore built and discarded during the grouped retry, for wallets started with -avoidpartialspends, for sendtoaddress with avoid_reuse, and when -maxapsfee=-1. Add !coin_control.m_avoid_partial_spends && wallet.m_max_aps_fee > -1 to the guard so the flag remains available wherever it is read. On the path that reads it, seed the map from result.GetInputSet() and scan available and preset coins only to increment existing entries. Only selected scripts can satisfy counts.second > 0, so this preserves the predicate with fewer entries.