Skip to content

Commit 9a6d79c

Browse files
author
Antoine Riard
committed
Add auto-close if inbound feerate update don't complete
1 parent f44a42e commit 9a6d79c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lightning/src/ln/channel.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ pub(super) struct Channel<Signer: Sign> {
386386
// Auto-close timer, if the channel is outbound, we sent a `update_fee`, and we didn't
387387
// receive a RAA from counterparty committing this state after `AUTOCLOSE_TIMEOUT` periods,
388388
// this channel must be force-closed.
389+
// If the channel is inbound, it has been observed the channel feerate should increase,
390+
// and we didn't receive a RAA from counterparty committing an `update_fee` after
391+
// `AUTOCLOSE_TIMEOUT` periods, this channel must be force-closed.
389392
autoclose_timer: u16,
390393

391394
holder_signer: Signer,
@@ -2722,15 +2725,17 @@ impl<Signer: Sign> Channel<Signer> {
27222725
}
27232726

27242727
/// Trigger the autoclose timer if it's in the starting position
2725-
fn maybe_trigger_autoclose_timer(&mut self) {
2728+
pub fn maybe_trigger_autoclose_timer(&mut self) -> bool {
27262729
// Start an auto-close timer, if the channel feerate doesn't increase before its
27272730
// expiration (i.e this outbound feerate update has been committed on both sides),
27282731
// the channel will be marked as unsafe and force-closed.
27292732
// If a timer is already pending, no-op, as a higher-feerate `update_fee` will
27302733
// implicitly override a lower-feerate `update_fee` part of the same update sequence.
27312734
if self.autoclose_timer == 0 {
27322735
self.autoclose_timer = 1;
2736+
return true;
27332737
}
2738+
return false;
27342739
}
27352740

27362741
/// Handles receiving a remote's revoke_and_ack. Note that we may return a new
@@ -2907,6 +2912,7 @@ impl<Signer: Sign> Channel<Signer> {
29072912
require_commitment = true;
29082913
self.feerate_per_kw = feerate;
29092914
self.pending_update_fee = None;
2915+
self.autoclose_timer = 0;
29102916
},
29112917
}
29122918
}
@@ -4712,6 +4718,7 @@ impl<Signer: Sign> Channel<Signer> {
47124718
log_trace!(logger, " ...promoting inbound AwaitingRemoteRevokeToAnnounce fee update {} to Committed", feerate);
47134719
self.feerate_per_kw = feerate;
47144720
self.pending_update_fee = None;
4721+
self.autoclose_timer = 0;
47154722
}
47164723
}
47174724
self.resend_order = RAACommitmentOrder::RevokeAndACKFirst;

lightning/src/ln/channelmanager.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2819,13 +2819,19 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
28192819
}
28202820

28212821
fn update_channel_fee(&self, short_to_id: &mut HashMap<u64, [u8; 32]>, pending_msg_events: &mut Vec<events::MessageSendEvent>, chan_id: &[u8; 32], chan: &mut Channel<Signer>, new_feerate: u32) -> (bool, NotifyOption, Result<(), MsgHandleErrInternal>) {
2822-
if !chan.is_outbound() { return (true, NotifyOption::SkipPersist, Ok(())); }
28232822
// If the feerate has decreased by less than half, don't bother
28242823
if new_feerate <= chan.get_feerate() && new_feerate * 2 > chan.get_feerate() {
28252824
log_trace!(self.logger, "Channel {} does not qualify for a feerate change from {} to {}.",
28262825
log_bytes!(chan_id[..]), chan.get_feerate(), new_feerate);
28272826
return (true, NotifyOption::SkipPersist, Ok(()));
28282827
}
2828+
if !chan.is_outbound() {
2829+
if chan.maybe_trigger_autoclose_timer() {
2830+
return (true, NotifyOption::DoPersist, Ok(()));
2831+
} else {
2832+
return (true, NotifyOption::SkipPersist, Ok(()));
2833+
}
2834+
}
28292835
if !chan.is_live() {
28302836
log_trace!(self.logger, "Channel {} does not qualify for a feerate change from {} to {} as it cannot currently be updated (probably the peer is disconnected).",
28312837
log_bytes!(chan_id[..]), chan.get_feerate(), new_feerate);

0 commit comments

Comments
 (0)