Skip to content

Fix update_id gap during force_shutdown #3858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3440,6 +3440,13 @@ where
self.latest_monitor_update_id
}

pub fn get_latest_unblocked_monitor_update_id(&self) -> u64 {
if self.blocked_monitor_updates.is_empty() {
return self.get_latest_monitor_update_id();
}
self.blocked_monitor_updates[0].update.update_id - 1
}

pub fn should_announce(&self) -> bool {
self.config.announce_for_forwarding
}
Expand Down Expand Up @@ -5220,7 +5227,7 @@ where
// monitor update to the user, even if we return one).
// See test_duplicate_chan_id and test_pre_lockin_no_chan_closed_update for more.
if !self.channel_state.is_pre_funded_state() {
self.latest_monitor_update_id += 1;
self.latest_monitor_update_id = self.get_latest_unblocked_monitor_update_id() + 1;
Some((self.get_counterparty_node_id(), funding_txo, self.channel_id(), ChannelMonitorUpdate {
update_id: self.latest_monitor_update_id,
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast }],
Expand Down Expand Up @@ -8582,10 +8589,8 @@ where
}

/// Gets the latest [`ChannelMonitorUpdate`] ID which has been released and is in-flight.
#[rustfmt::skip]
pub fn get_latest_unblocked_monitor_update_id(&self) -> u64 {
if self.context.blocked_monitor_updates.is_empty() { return self.context.get_latest_monitor_update_id(); }
self.context.blocked_monitor_updates[0].update.update_id - 1
self.context.get_latest_unblocked_monitor_update_id()
}

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