← Back to Pull requests

sweep: bound wallet input selection #11485

Closed
unknown closed this pull request without merging on Nov 10, 2026 06:08 UTC
View on GitHub
unknown unknown commented on Nov 04, 2026 05:22 UTC
Author

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 retryable TxFailed event instead of TxFatal. 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 MaxFeeRateAllowed at 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

  • retrying a transaction rejected with ErrTxTooLarge.
  • go test ./sweep -count=1
    make lint-native
    

    Diff: 414 lines (+310 / -104) across 5 files Reviewer: Roasbeef Review duration: 8685m
    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
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 49.9% (MEDIUM) · Higher = larger blast radius
    49.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.6% · Safe to merge
    21.6%