Skip to content

Commit 30d9ca1

Browse files
committed
Limit minimum output size to the dust limit when RBF-bumping
1 parent bee9a1e commit 30d9ca1

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

lightning/src/chain/onchaintx.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
354354
let new_timer = Some(cached_request.get_height_timer(cur_height));
355355
if cached_request.is_malleable() {
356356
let predicted_weight = cached_request.package_weight(&self.destination_script);
357-
if let Some((output_value, new_feerate)) = cached_request.compute_package_output(predicted_weight, fee_estimator, logger) {
357+
if let Some((output_value, new_feerate)) =
358+
cached_request.compute_package_output(predicted_weight, self.destination_script.dust_value().as_sat(), fee_estimator, logger) {
358359
assert!(new_feerate != 0);
359360

360361
let transaction = cached_request.finalize_package(self, output_value, self.destination_script.clone(), logger).unwrap();

lightning/src/chain/package.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,11 @@ impl PackageTemplate {
634634
}
635635
current_height + LOW_FREQUENCY_BUMP_INTERVAL
636636
}
637-
/// Returns value in satoshis to be included as package outgoing output amount and feerate with which package finalization should be done.
638-
pub(crate) fn compute_package_output<F: Deref, L: Deref>(&self, predicted_weight: usize, fee_estimator: &F, logger: &L) -> Option<(u64, u64)>
637+
638+
/// Returns value in satoshis to be included as package outgoing output amount and feerate
639+
/// which was used to generate the value. Will not return less than `dust_limit_sats` for the
640+
/// value.
641+
pub(crate) fn compute_package_output<F: Deref, L: Deref>(&self, predicted_weight: usize, dust_limit_sats: u64, fee_estimator: &F, logger: &L) -> Option<(u64, u64)>
639642
where F::Target: FeeEstimator,
640643
L::Target: Logger,
641644
{
@@ -644,16 +647,11 @@ impl PackageTemplate {
644647
// If old feerate is 0, first iteration of this claim, use normal fee calculation
645648
if self.feerate_previous != 0 {
646649
if let Some((new_fee, feerate)) = feerate_bump(predicted_weight, input_amounts, self.feerate_previous, fee_estimator, logger) {
647-
// If new computed fee is superior at the whole claimable amount burn all in fees
648-
if new_fee > input_amounts {
649-
return Some((0, feerate));
650-
} else {
651-
return Some((input_amounts - new_fee, feerate));
652-
}
650+
return Some((cmp::max(input_amounts as i64 - new_fee as i64, dust_limit_sats as i64) as u64, feerate));
653651
}
654652
} else {
655653
if let Some((new_fee, feerate)) = compute_fee_from_spent_amounts(input_amounts, predicted_weight, fee_estimator, logger) {
656-
return Some((input_amounts - new_fee, feerate));
654+
return Some((cmp::max(input_amounts as i64 - new_fee as i64, dust_limit_sats as i64) as u64, feerate));
657655
}
658656
}
659657
None

0 commit comments

Comments
 (0)