Skip to content

Commit 131cd25

Browse files
committed
Check pending funding in send_update_fee
If there are any pending splices when an sending an update_fee message, the new fee rate must be validated against each pending FundingScope. Otherwise, it may be invalid once the splice is locked.
1 parent 2a76bfe commit 131cd25

File tree

1 file changed

+41
-23
lines changed

1 file changed

+41
-23
lines changed

lightning/src/ln/channel.rs

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6737,29 +6737,10 @@ impl<SP: Deref> FundedChannel<SP> where
67376737
panic!("Cannot update fee while peer is disconnected/we're awaiting a monitor update (ChannelManager should have caught this)");
67386738
}
67396739

6740-
// Before proposing a feerate update, check that we can actually afford the new fee.
6741-
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
6742-
let htlc_stats = self.context.get_pending_htlc_stats(&self.funding, Some(feerate_per_kw), dust_exposure_limiting_feerate);
6743-
let commitment_data = self.context.build_commitment_transaction(
6744-
&self.funding, self.holder_commitment_point.transaction_number(),
6745-
&self.holder_commitment_point.current_point(), true, true, logger,
6746-
);
6747-
let buffer_fee_msat = commit_tx_fee_sat(feerate_per_kw, commitment_data.tx.nondust_htlcs().len() + htlc_stats.on_holder_tx_outbound_holding_cell_htlcs_count as usize + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, self.funding.get_channel_type()) * 1000;
6748-
let holder_balance_msat = commitment_data.stats.local_balance_before_fee_anchors_msat - htlc_stats.outbound_holding_cell_msat;
6749-
if holder_balance_msat < buffer_fee_msat + commitment_data.stats.total_anchors_sat * 1000 + self.funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
6750-
//TODO: auto-close after a number of failures?
6751-
log_debug!(logger, "Cannot afford to send new feerate at {}", feerate_per_kw);
6752-
return None;
6753-
}
6754-
6755-
// Note, we evaluate pending htlc "preemptive" trimmed-to-dust threshold at the proposed `feerate_per_kw`.
6756-
let max_dust_htlc_exposure_msat = self.context.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
6757-
if htlc_stats.on_holder_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
6758-
log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
6759-
return None;
6760-
}
6761-
if htlc_stats.on_counterparty_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
6762-
log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
6740+
let can_send_update_fee = core::iter::once(&self.funding)
6741+
.chain(self.pending_funding.iter())
6742+
.all(|funding| self.can_send_update_fee(funding, feerate_per_kw, fee_estimator, logger));
6743+
if !can_send_update_fee {
67636744
return None;
67646745
}
67656746

@@ -6784,6 +6765,43 @@ impl<SP: Deref> FundedChannel<SP> where
67846765
})
67856766
}
67866767

6768+
fn can_send_update_fee<F: Deref, L: Deref>(
6769+
&self, funding: &FundingScope, feerate_per_kw: u32,
6770+
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
6771+
) -> bool
6772+
where
6773+
F::Target: FeeEstimator,
6774+
L::Target: Logger,
6775+
{
6776+
// Before proposing a feerate update, check that we can actually afford the new fee.
6777+
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
6778+
let htlc_stats = self.context.get_pending_htlc_stats(funding, Some(feerate_per_kw), dust_exposure_limiting_feerate);
6779+
let commitment_data = self.context.build_commitment_transaction(
6780+
funding, self.holder_commitment_point.transaction_number(),
6781+
&self.holder_commitment_point.current_point(), true, true, logger,
6782+
);
6783+
let buffer_fee_msat = commit_tx_fee_sat(feerate_per_kw, commitment_data.tx.nondust_htlcs().len() + htlc_stats.on_holder_tx_outbound_holding_cell_htlcs_count as usize + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, funding.get_channel_type()) * 1000;
6784+
let holder_balance_msat = commitment_data.stats.local_balance_before_fee_anchors_msat - htlc_stats.outbound_holding_cell_msat;
6785+
if holder_balance_msat < buffer_fee_msat + commitment_data.stats.total_anchors_sat * 1000 + funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
6786+
//TODO: auto-close after a number of failures?
6787+
log_debug!(logger, "Cannot afford to send new feerate at {}", feerate_per_kw);
6788+
return false;
6789+
}
6790+
6791+
// Note, we evaluate pending htlc "preemptive" trimmed-to-dust threshold at the proposed `feerate_per_kw`.
6792+
let max_dust_htlc_exposure_msat = self.context.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
6793+
if htlc_stats.on_holder_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
6794+
log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
6795+
return false;
6796+
}
6797+
if htlc_stats.on_counterparty_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
6798+
log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
6799+
return false;
6800+
}
6801+
6802+
return true;
6803+
}
6804+
67876805
/// Removes any uncommitted inbound HTLCs and resets the state of uncommitted outbound HTLC
67886806
/// updates, to be used on peer disconnection. After this, update_*_htlc messages need to be
67896807
/// resent.

0 commit comments

Comments
 (0)