Skip to content

Commit 5ef98b9

Browse files
author
Antoine Riard
committed
Add auto-close if inbound feerate update don't complete
1 parent 0a42051 commit 5ef98b9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lightning/src/ln/channel.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2735,15 +2735,17 @@ impl<Signer: Sign> Channel<Signer> {
27352735
}
27362736

27372737
/// Trigger the autoclose timer if it's in the starting position
2738-
fn maybe_trigger_autoclose_timer(&mut self) {
2738+
pub fn maybe_trigger_autoclose_timer(&mut self) -> bool {
27392739
// Start an auto-close timer, if the channel feerate doesn't increase before its
27402740
// expiration (i.e this outbound feerate update has been committed on both sides),
27412741
// the channel will be marked as unsafe and force-closed.
27422742
// If a timer is already pending, no-op, as a higher-feerate `update_fee` will
27432743
// implicitly override a lower-feerate `update_fee` part of the same update sequence.
27442744
if self.autoclose_timer == 0 {
27452745
self.autoclose_timer = 1;
2746+
return true;
27462747
}
2748+
return false;
27472749
}
27482750

27492751
/// Handles receiving a remote's revoke_and_ack. Note that we may return a new
@@ -2913,6 +2915,7 @@ impl<Signer: Sign> Channel<Signer> {
29132915
require_commitment = true;
29142916
self.feerate_per_kw = feerate;
29152917
self.pending_update_fee = None;
2918+
self.autoclose_timer = 0;
29162919
},
29172920
}
29182921
}
@@ -4714,6 +4717,7 @@ impl<Signer: Sign> Channel<Signer> {
47144717
log_trace!(logger, " ...promoting inbound AwaitingRemoteRevokeToAnnounce fee update {} to Committed", feerate);
47154718
self.feerate_per_kw = feerate;
47164719
self.pending_update_fee = None;
4720+
self.autoclose_timer = 0;
47174721
}
47184722
}
47194723
self.resend_order = RAACommitmentOrder::RevokeAndACKFirst;

lightning/src/ln/channelmanager.rs

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

26122612
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>) {
2613-
if !chan.is_outbound() { return (true, NotifyOption::SkipPersist, Ok(())); }
26142613
// If the feerate has decreased by less than half, don't bother
26152614
if new_feerate <= chan.get_feerate() && new_feerate * 2 > chan.get_feerate() {
26162615
log_trace!(self.logger, "Channel {} does not qualify for a feerate change from {} to {}.",
26172616
log_bytes!(chan_id[..]), chan.get_feerate(), new_feerate);
26182617
return (true, NotifyOption::SkipPersist, Ok(()));
26192618
}
2619+
if !chan.is_outbound() {
2620+
if chan.maybe_trigger_autoclose_timer() {
2621+
return (true, NotifyOption::DoPersist, Ok(()));
2622+
} else {
2623+
return (true, NotifyOption::SkipPersist, Ok(()));
2624+
}
2625+
}
26202626
if !chan.is_live() {
26212627
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).",
26222628
log_bytes!(chan_id[..]), chan.get_feerate(), new_feerate);

0 commit comments

Comments
 (0)