Skip to content
Merged
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: 10 additions & 3 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,8 @@ where
/// the highest `update_id` of all the pending in-flight updates (note that any pending updates
/// not yet applied sitting in [`ChannelManager::pending_background_events`] will also be
/// considered as they are also in [`Self::in_flight_monitor_updates`]).
///
/// Note that channels which were closed prior to LDK 0.1 may have a value here of `u64::MAX`.
closed_channel_monitor_update_ids: BTreeMap<ChannelId, u64>,
/// The peer is currently connected (i.e. we've seen a
/// [`BaseMessageHandler::peer_connected`] and no corresponding
Expand Down Expand Up @@ -13262,7 +13264,8 @@ where
.closed_channel_monitor_update_ids
.get_mut(&channel_id)
.expect("Channels originating a payment resolution must have a monitor");
*update_id += 1;
// Note that for channels closed pre-0.1, the latest update_id is `u64::MAX`.
*update_id = update_id.saturating_add(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the current and future caveats described in the commit msg, does this need a log on overflow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure if its really needed. Maybe the commit message isn't clear, but I don't see any issues with this with the current code. I do call out that its possible that other code changes in the future which introduces an issue, but I don't think we really need to log a warning on the assumption that future code might break really ancient channel closes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think the commit message is clear.

For someone looking at this statement though, it must be hard to understand why this is safe. I thought a warning log would both help debug any future issue with this, and at the same time add a bit more documentation. Or maybe move some of the commit message to a code comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added comments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still pretty thin and doesn't explain why it is okay to not increment when at the max already.


let update = ChannelMonitorUpdate {
update_id: *update_id,
Expand Down Expand Up @@ -16523,7 +16526,9 @@ where
should_queue_fc_update = !monitor.no_further_updates_allowed();
let mut latest_update_id = monitor.get_latest_update_id();
if should_queue_fc_update {
latest_update_id += 1;
// Note that for channels closed pre-0.1, the latest update_id is
// `u64::MAX`.
latest_update_id = latest_update_id.saturating_add(1);
}
per_peer_state
.entry(counterparty_node_id)
Expand Down Expand Up @@ -17170,7 +17175,9 @@ where
.closed_channel_monitor_update_ids
.get_mut(channel_id)
.expect("Channels originating a preimage must have a monitor");
*update_id += 1;
// Note that for channels closed pre-0.1, the latest
// update_id is `u64::MAX`.
*update_id = update_id.saturating_add(1);

pending_background_events.push(BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
counterparty_node_id: monitor.get_counterparty_node_id(),
Expand Down