Skip to content

Commit

Permalink
fix: rm Drain::none method
Browse files Browse the repository at this point in the history
We already have const `Drain::NONE` which should be used instead.
  • Loading branch information
evanlinjin committed Mar 29, 2024
1 parent 8eb582b commit 2e26aa5
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/coin_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl<'a> CoinSelector<'a> {

/// Whether the constraints of `Target` have been met.
pub fn is_target_met(&self, target: Target) -> bool {
self.is_target_met_with_drain(target, Drain::none())
self.is_target_met_with_drain(target, Drain::NONE)
}

/// Select all unselected candidates
Expand Down Expand Up @@ -434,7 +434,7 @@ impl<'a> CoinSelector<'a> {
}

/// Figures out whether the current selection should have a change output given the
/// `change_policy`. If it shouldn't then it will return a [`Drain::none`]. The value of the
/// `change_policy`. If it should not, then it will return [`Drain::NONE`]. The value of the
/// `Drain` will be the same as [`drain_value`].
///
/// If [`is_target_met`] returns true for this selection then [`is_target_met_with_drain`] will
Expand Down Expand Up @@ -475,7 +475,7 @@ impl<'a> CoinSelector<'a> {
pub fn select_until_target_met(&mut self, target: Target) -> Result<(), InsufficientFunds> {
self.select_until(|cs| cs.is_target_met(target))
.ok_or_else(|| InsufficientFunds {
missing: self.excess(target, Drain::none()).unsigned_abs(),
missing: self.excess(target, Drain::NONE).unsigned_abs(),
})
}

Expand Down
5 changes: 0 additions & 5 deletions src/drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ impl Drain {
value: 0,
};

/// A drian representing no drain at all.
pub fn none() -> Self {
Self::default()
}

/// is the "none" drain
pub fn is_none(&self) -> bool {
self == &Drain::NONE
Expand Down
2 changes: 1 addition & 1 deletion src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn change_lower_bound(cs: &CoinSelector, target: Target, change_policy: ChangePo

least_excess.drain(target, change_policy)
} else {
Drain::none()
Drain::NONE
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/metrics/lowest_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl BnbMetric for LowestFee {
self.long_term_feerate,
self.target.outputs.n_outputs,
);
let cost_of_no_change = cs.excess(self.target, Drain::none());
let cost_of_no_change = cs.excess(self.target, Drain::NONE);

let best_score_with_change =
Ordf32(current_score.0 - cost_of_no_change as f32 + cost_of_adding_change);
Expand Down Expand Up @@ -131,7 +131,7 @@ impl BnbMetric for LowestFee {
// scale = remaining_value_to_reach_feerate / effective_value_of_resized_input
//
// This should be intutive since we're finding out how to scale the input we're resizing to get the effective value we need.
let rate_excess = cs.rate_excess(self.target, Drain::none()) as f32;
let rate_excess = cs.rate_excess(self.target, Drain::NONE) as f32;
let mut scale = Ordf32(0.0);

if rate_excess < 0.0 {
Expand All @@ -150,7 +150,7 @@ impl BnbMetric for LowestFee {
// We can use the same approach for replacement we just have to use the
// incremental_relay_feerate.
if let Some(replace) = self.target.fee.replace {
let replace_excess = cs.replacement_excess(self.target, Drain::none()) as f32;
let replace_excess = cs.replacement_excess(self.target, Drain::NONE) as f32;
if replace_excess < 0.0 {
let remaining_value_to_reach_feerate = replace_excess.abs();
let effective_value_of_resized_input =
Expand Down
4 changes: 2 additions & 2 deletions tests/bnb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const EXCESS_RATIO: f32 = 1_000_000_f32;

impl BnbMetric for MinExcessThenWeight {
fn score(&mut self, cs: &CoinSelector<'_>) -> Option<Ordf32> {
let excess = cs.excess(self.target, Drain::none());
let excess = cs.excess(self.target, Drain::NONE);
if excess < 0 {
None
} else {
Expand Down Expand Up @@ -135,7 +135,7 @@ fn bnb_finds_solution_if_possible_in_n_iter() {
.expect("found a solution");

assert_eq!(rounds, 193);
let excess = sol.excess(target, Drain::none());
let excess = sol.excess(target, Drain::NONE);
assert_eq!(excess, 1);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/lowest_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ fn adding_another_input_to_remove_change() {
let mut cs = cs.clone();
cs.select(0);
cs.select(2);
cs.excess(target, Drain::none());
cs.excess(target, Drain::NONE);
assert!(cs.is_target_met(target));
cs
};
Expand Down Expand Up @@ -262,7 +262,7 @@ fn adding_another_input_to_remove_change() {
let (score, _) = common::bnb_search(&mut cs, metric, 10).expect("finds solution");
let best_solution_score = metric.score(&best_solution).expect("must be a solution");

assert_eq!(best_solution.drain(target, change_policy), Drain::none());
assert_eq!(best_solution.drain(target, change_policy), Drain::NONE);

assert!(score <= best_solution_score);
assert_eq!(cs.selected_indices(), best_solution.selected_indices());
Expand Down
2 changes: 1 addition & 1 deletion tests/weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn segwit_two_inputs_one_output() {
);
assert_eq!(
(coin_selector
.implied_feerate(target_ouputs, Drain::none())
.implied_feerate(target_ouputs, Drain::NONE)
.unwrap()
.as_sat_vb()
* 10.0)
Expand Down

0 comments on commit 2e26aa5

Please sign in to comment.