Skip to content

Commit 69e4f74

Browse files
evanlinjinclaude
andcommitted
refactor(metrics): inline single-use changeless_max_excess
It had one caller (`ub_changeless_input_weight`); fold it in and keep the union-of-two-regions reasoning as a comment at the call site. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9e038df commit 69e4f74

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

src/metrics/changeless_waste.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,6 @@ impl ChangelessWaste {
8585
self.drain_weights.dust_threshold(self.dust_relay_feerate)
8686
}
8787

88-
/// The largest `excess_with_drain_weight` for which a selection is still changeless.
89-
///
90-
/// A selection is changeless (see [`drain_value`]) when its excess is `<= drain_spend_cost` OR
91-
/// `< dust_threshold`. The union of those two regions is `excess <= max(drain_spend_cost,
92-
/// dust_threshold - 1)`, so this is the inclusive upper edge of the changeless region.
93-
///
94-
/// [`drain_value`]: Self::drain_value
95-
fn changeless_max_excess(&self) -> i64 {
96-
(self.drain_spend_cost() as i64).max(self.dust_threshold() as i64 - 1)
97-
}
98-
9988
/// Whether every selection reachable down this branch (the current one and any superset of it)
10089
/// would have a change output — so no changeless solution exists here and the branch can be
10190
/// pruned.
@@ -131,9 +120,9 @@ impl ChangelessWaste {
131120
///
132121
/// Construct `D_all = cs ∪ all unselected`. If `D_all` itself is changeless, the UB is
133122
/// `D_all.input_weight`. Otherwise we must exclude enough excess-contributing
134-
/// (positive-`effective_value`) candidates to drop `excess_with_drain_weight` down to
135-
/// [`changeless_max_excess`]. To MAXIMIZE the remaining `input_weight` we MINIMIZE the excluded
136-
/// weight, sorting positive-`ev` candidates by `ev / weight` descending and removing
123+
/// (positive-`effective_value`) candidates to drop `excess_with_drain_weight` down to the
124+
/// largest still-changeless excess. To MAXIMIZE the remaining `input_weight` we MINIMIZE the
125+
/// excluded weight, sorting positive-`ev` candidates by `ev / weight` descending and removing
137126
/// fractionally until the required `delta` is met.
138127
///
139128
/// The LP relaxation gives a value `>=` any integer solution's excluded weight, so
@@ -142,13 +131,18 @@ impl ChangelessWaste {
142131
/// subtract from a subset — so the additive subtraction is safe in the UB direction.
143132
///
144133
/// [`bound`]: BnbMetric::bound
145-
/// [`changeless_max_excess`]: Self::changeless_max_excess
146134
fn ub_changeless_input_weight(&self, cs: &CoinSelector<'_>, target: Target) -> f32 {
147135
let mut d_all = cs.clone();
148136
d_all.select_all();
149137
let d_all_iw = d_all.input_weight() as f32;
150138

151-
let delta = self.excess_with_drain_weight(&d_all, target) - self.changeless_max_excess();
139+
// The largest `excess_with_drain_weight` for which a selection is still changeless: it is
140+
// changeless (see `drain_value`) when its excess is `<= drain_spend_cost` OR `<
141+
// dust_threshold`, and the union of those two regions is `excess <= max(drain_spend_cost,
142+
// dust_threshold - 1)`.
143+
let changeless_max_excess =
144+
(self.drain_spend_cost() as i64).max(self.dust_threshold() as i64 - 1);
145+
let delta = self.excess_with_drain_weight(&d_all, target) - changeless_max_excess;
152146
if delta <= 0 {
153147
return d_all_iw;
154148
}

0 commit comments

Comments
 (0)