sweep: bound wallet input selection #11485
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 414 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.361
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #11485"
general
weight: 0.35
Roasbeef
Change
Bound the wallet inputs used to fund a sweep input set.
When a set needs external fee funding, the sweeper now:
measures each confirmed wallet UTXO's added input weight and considers candidates in exact value-per-weight order;
skips a UTXO if its value cannot pay for its own input weight at the node's relay fee rate;
stops before the estimated child transaction reaches the standard transaction-weight limit; and
attempts the sweep with the available funding when at least one normal input can pay fees, even if the full requested budget is unavailable.
The existing aggregator still limits original sweep inputs to 100. With the currently supported sweep input types, those original inputs remain below the standard-weight limit; wallet inputs added afterward are bounded using the complete child weight estimate.
Retry safety
If mempool acceptance nevertheless returns
ErrTxTooLarge, the publisher now reports a retryableTxFailedevent instead ofTxFatal. The inputs return to the pending pool rather than being dropped permanently. The current fee rate is retained because increasing it does not address a weight rejection.Scope
This PR deliberately does not attempt to optimize the final child or CPFP package fee rate. In particular, when the parent is heavy, a lighter child can cap the package rate below what master's heavier child reaches; that needs its own design pass, since a heavier child can pay more under the same rate cap. The earlier starting-fee and reachable/package-rate gate could reject wallet inputs that collectively fund a valid deadline transaction and did not always guarantee that accepting an input increased the resulting rate. Selection here is limited to deterministic density ordering, the relay self-pay floor, and the standard-weight bound.
There is deliberately no wallet-input count cap: stopping at a fixed count can leave a set short of the budget that the fee bumper targets, where taking more inputs would have funded it. When the weight bound or a short wallet still leaves a set below its budget (as on master today), capping
MaxFeeRateAllowedat what the inputs can pay is left to a follow-up.The relay fee threshold is read from the fee estimator each time a set needs wallet inputs, rather than the value cached at startup, so it follows the backend's current mempool policy.
A larger wallet UTXO selected for a sweep remains locked until the sweep confirms.
Testing
Unit coverage includes:
largest-first ordering for equal input types and value-per-weight ordering across types;
relay self-pay boundaries one satoshi below, equal to, and one satoshi above the marginal relay fee;
anchor CPFP funding with multiple small wallet UTXOs;
topping up a large UTXO when it does not cover the budget;
exact density ordering for a mixed-type pair whose rounded densities tie on opposite sides of the relay threshold, in both wallet orders;
funding a budget from 200 small UTXOs (no count cap) and the standard-weight bound with a wallet of 2,000 small UTXOs;
using the current relay fee rate rather than the one cached at startup;
continuing with partial funding when a normal input exists; and
ErrTxTooLarge.