Skip to content

Commit 9c1c7c4

Browse files
committed
Limit minimum output size to the dust limit when RBF-bumping
1 parent 423f1b1 commit 9c1c7c4

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

lightning/src/chain/onchaintx.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
380380
let new_timer = Some(cached_request.get_height_timer(cur_height));
381381
if cached_request.is_malleable() {
382382
let predicted_weight = cached_request.package_weight(&self.destination_script);
383-
if let Some((output_value, new_feerate)) = cached_request.compute_package_output(predicted_weight, fee_estimator, logger) {
383+
if let Some((output_value, new_feerate)) =
384+
cached_request.compute_package_output(predicted_weight, self.destination_script.dust_value().as_sat(), fee_estimator, logger) {
384385
assert!(new_feerate != 0);
385386

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

lightning/src/chain/package.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -636,26 +636,25 @@ impl PackageTemplate {
636636
}
637637
current_height + LOW_FREQUENCY_BUMP_INTERVAL
638638
}
639-
/// Returns value in satoshis to be included as package outgoing output amount and feerate with which package finalization should be done.
640-
pub(crate) fn compute_package_output<F: Deref, L: Deref>(&self, predicted_weight: usize, fee_estimator: &F, logger: &L) -> Option<(u64, u64)>
639+
640+
/// Returns value in satoshis to be included as package outgoing output amount and feerate
641+
/// which was used to generate the value. Will not return less than `dust_limit_sats` for the
642+
/// value.
643+
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)>
641644
where F::Target: FeeEstimator,
642645
L::Target: Logger,
643646
{
644647
debug_assert!(self.malleability == PackageMalleability::Malleable, "The package output is fixed for non-malleable packages");
645648
let input_amounts = self.package_amount();
649+
assert!(dust_limit_sats as i64 > 0, "Output script must be broadcastable/have a 'real' dust limit.");
646650
// If old feerate is 0, first iteration of this claim, use normal fee calculation
647651
if self.feerate_previous != 0 {
648652
if let Some((new_fee, feerate)) = feerate_bump(predicted_weight, input_amounts, self.feerate_previous, fee_estimator, logger) {
649-
// If new computed fee is superior at the whole claimable amount burn all in fees
650-
if new_fee > input_amounts {
651-
return Some((0, feerate));
652-
} else {
653-
return Some((input_amounts - new_fee, feerate));
654-
}
653+
return Some((cmp::max(input_amounts as i64 - new_fee as i64, dust_limit_sats as i64) as u64, feerate));
655654
}
656655
} else {
657656
if let Some((new_fee, feerate)) = compute_fee_from_spent_amounts(input_amounts, predicted_weight, fee_estimator, logger) {
658-
return Some((input_amounts - new_fee, feerate));
657+
return Some((cmp::max(input_amounts as i64 - new_fee as i64, dust_limit_sats as i64) as u64, feerate));
659658
}
660659
}
661660
None

0 commit comments

Comments
 (0)