Skip to content

Commit 0813413

Browse files
committed
Correctly handle new ChannelMonitorUpdates to old post-FC chans
In 0.1 (1481216) we started setting `ChannelMonitorUpdate::update_id` to a non-`u64::MAX` value for updates generated after a channel has been closed. This is great, but in 71a364c we then started calculating the next `update_id` by incrementing the last `update_id` we saw when we started and were looking at the `ChannelMonitor`. However, the last-applied `update_id` may well be `u64::MAX` for old `ChannelMonitor`s which were closed prior to 0.1. In that case the increment would overflow. Here we fix this naively by simply replacing the increment with a `saturating_add`. While its possible this will result in a `ChannelMonitorUpdate` being tracked as in-flight (only for the `ReleasePaymentComplete` updates added in 71a364c) at the same `update_id` as other updates already in-flight and handling post-`ChannelMonitorUpdate` actions too early, this should only apply to releasing payment complete updates, which have no post-`ChannelMonitorUpdate` action. Its also possible that this leads to a regression in the future, where we have some new post-closure update that does have a post-`ChannelMonitorUpdate` action and we run it too early, but by then presumably its fairly rare to have a `ChannelMonitor` for a channel closed pre-0.1 that still needs multiple updates.
1 parent 54ed941 commit 0813413

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13262,7 +13262,7 @@ where
1326213262
.closed_channel_monitor_update_ids
1326313263
.get_mut(&channel_id)
1326413264
.expect("Channels originating a payment resolution must have a monitor");
13265-
*update_id += 1;
13265+
*update_id = update_id.saturating_add(1);
1326613266

1326713267
let update = ChannelMonitorUpdate {
1326813268
update_id: *update_id,
@@ -16523,7 +16523,7 @@ where
1652316523
should_queue_fc_update = !monitor.no_further_updates_allowed();
1652416524
let mut latest_update_id = monitor.get_latest_update_id();
1652516525
if should_queue_fc_update {
16526-
latest_update_id += 1;
16526+
latest_update_id = latest_update_id.saturating_add(1);
1652716527
}
1652816528
per_peer_state
1652916529
.entry(counterparty_node_id)
@@ -17170,7 +17170,7 @@ where
1717017170
.closed_channel_monitor_update_ids
1717117171
.get_mut(channel_id)
1717217172
.expect("Channels originating a preimage must have a monitor");
17173-
*update_id += 1;
17173+
*update_id = update_id.saturating_add(1);
1717417174

1717517175
pending_background_events.push(BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
1717617176
counterparty_node_id: monitor.get_counterparty_node_id(),

0 commit comments

Comments
 (0)