Skip to content

Commit

Permalink
fix: CoinSelector::implied_fee
Browse files Browse the repository at this point in the history
The logic was wrong before because it was making the RBF constraints
take precedence. Instead, we should be taking the maximum between
the fee calculated from the target feerate and the minimum fee that
satisfies the RBF constraints.
  • Loading branch information
evanlinjin committed Mar 31, 2024
1 parent 4d0ae4c commit c650306
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/coin_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,18 @@ impl<'a> CoinSelector<'a> {

/// The fee the current selection and `drain_weight` should pay to satisfy `target_fee`.
///
/// `drain_weight` can be 0 to indicate no draining output
/// This compares the fee calculated from the target feerate with the fee calculated from the
/// [`Replace`] constraints and returns the larger of the two.
///
/// `drain_weight` can be 0 to indicate no draining output.
pub fn implied_fee(&self, target: Target, drain_weights: DrainWeights) -> u64 {
let mut implied_fee = self.implied_fee_from_feerate(target, drain_weights);

if let Some(replace) = target.fee.replace {
implied_fee =
replace.min_fee_to_do_replacement(self.weight(target.outputs, drain_weights));
implied_fee = Ord::max(
implied_fee,
replace.min_fee_to_do_replacement(self.weight(target.outputs, drain_weights)),
);
}

implied_fee
Expand Down

0 comments on commit c650306

Please sign in to comment.