Skip to content

Commit 0c709f8

Browse files
committed
f move check for fee update into channelmanager
The logic of "no feerate change has happened" belongs in channel manager (previously it just didn't work for zero fees). Change channel to just assert that we're not making these calls (but don't panic, since this isn't going to put us at risk of lost funds).
1 parent fb6970e commit 0c709f8

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lightning/src/ln/channel.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4335,10 +4335,6 @@ where
43354335
F::Target: FeeEstimator,
43364336
L::Target: Logger,
43374337
{
4338-
if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
4339-
return false;
4340-
}
4341-
43424338
// Before proposing a feerate update, check that we can actually afford the new fee.
43434339
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
43444340
&fee_estimator, funding.get_channel_type(),
@@ -7727,6 +7723,10 @@ where
77277723
panic!("Cannot update fee while peer is disconnected/we're awaiting a monitor update (ChannelManager should have caught this)");
77287724
}
77297725

7726+
// Sending a fee update for zero fee commitments will trigger a warning and disconnect
7727+
// from our peer, but does not result in a loss of funds so we do not panic here.
7728+
debug_assert!(!self.funding.get_channel_type().supports_anchor_zero_fee_commitments());
7729+
77307730
let can_send_update_fee = core::iter::once(&self.funding)
77317731
.chain(self.pending_funding.iter())
77327732
.all(|funding| self.context.can_send_update_fee(funding, feerate_per_kw, fee_estimator, logger));

lightning/src/ln/channelmanager.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6963,10 +6963,17 @@ where
69636963

69646964
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
69656965

6966-
// If the feerate has decreased by less than half, don't bother
6967-
if new_feerate <= chan.context.get_feerate_sat_per_1000_weight() && new_feerate * 2 > chan.context.get_feerate_sat_per_1000_weight() {
6968-
return NotifyOption::SkipPersistNoEvents;
6966+
let current_feerate = chan.context.get_feerate_sat_per_1000_weight();
6967+
let update_fee_required = match new_feerate.cmp(&current_feerate) {
6968+
cmp::Ordering::Greater => true,
6969+
cmp::Ordering::Equal => false,
6970+
// Only bother with a fee update if feerate has decreased at least half.
6971+
cmp::Ordering::Less => new_feerate * 2 <= current_feerate,
6972+
};
6973+
if !update_fee_required {
6974+
return NotifyOption::SkipPersistNoEvents
69696975
}
6976+
69706977
if !chan.context.is_live() {
69716978
log_trace!(logger, "Channel {} does not qualify for a feerate change from {} to {} as it cannot currently be updated (probably the peer is disconnected).",
69726979
chan_id, chan.context.get_feerate_sat_per_1000_weight(), new_feerate);

0 commit comments

Comments
 (0)