Skip to content

Commit c650306

Browse files
committed
fix: CoinSelector::implied_fee
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.
1 parent 4d0ae4c commit c650306

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/coin_selector.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,18 @@ impl<'a> CoinSelector<'a> {
229229

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

236239
if let Some(replace) = target.fee.replace {
237-
implied_fee =
238-
replace.min_fee_to_do_replacement(self.weight(target.outputs, drain_weights));
240+
implied_fee = Ord::max(
241+
implied_fee,
242+
replace.min_fee_to_do_replacement(self.weight(target.outputs, drain_weights)),
243+
);
239244
}
240245

241246
implied_fee

0 commit comments

Comments
 (0)