Skip to content

Commit 0866405

Browse files
committed
Fix update_id gap during force_shutdown
When a channel is force-closed, there might be blocked monitor updates not yet applied. But `latest_monitor_update_id` has been incremented and assigned to these updates. This results in a panic when trying to apply the `ChannelForceClosed` update. Use the unblocked update id instead. Resolves: #3857
1 parent 3da69f7 commit 0866405

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lightning/src/ln/channel.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3554,6 +3554,13 @@ where
35543554
self.latest_monitor_update_id
35553555
}
35563556

3557+
pub fn get_latest_unblocked_monitor_update_id(&self) -> u64 {
3558+
if self.blocked_monitor_updates.is_empty() {
3559+
return self.get_latest_monitor_update_id();
3560+
}
3561+
self.blocked_monitor_updates[0].update.update_id - 1
3562+
}
3563+
35573564
pub fn should_announce(&self) -> bool {
35583565
self.config.announce_for_forwarding
35593566
}
@@ -5317,7 +5324,7 @@ where
53175324
// monitor update to the user, even if we return one).
53185325
// See test_duplicate_chan_id and test_pre_lockin_no_chan_closed_update for more.
53195326
if !self.channel_state.is_pre_funded_state() {
5320-
self.latest_monitor_update_id += 1;
5327+
self.latest_monitor_update_id = self.get_latest_unblocked_monitor_update_id() + 1;
53215328
let update = ChannelMonitorUpdate {
53225329
update_id: self.latest_monitor_update_id,
53235330
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed {
@@ -9016,10 +9023,7 @@ where
90169023

90179024
/// Gets the latest [`ChannelMonitorUpdate`] ID which has been released and is in-flight.
90189025
pub fn get_latest_unblocked_monitor_update_id(&self) -> u64 {
9019-
if self.context.blocked_monitor_updates.is_empty() {
9020-
return self.context.get_latest_monitor_update_id();
9021-
}
9022-
self.context.blocked_monitor_updates[0].update.update_id - 1
9026+
self.context.get_latest_unblocked_monitor_update_id()
90239027
}
90249028

90259029
/// Returns the next blocked monitor update, if one exists, and a bool which indicates a

0 commit comments

Comments
 (0)