Skip to content

Commit 5c090a2

Browse files
committed
Rename ClosingMonitorUpdate MonitorUpdateRegeneratedOnStartup
This makes much clearer at sites generating such events that they will be lost on restart, to reduce risk of bugs creeping in due to lost monitor updates.
1 parent 135f414 commit 5c090a2

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,11 @@ struct ClaimablePayments {
501501
/// for some reason. They are handled in timer_tick_occurred, so may be processed with
502502
/// quite some time lag.
503503
enum BackgroundEvent {
504-
/// Handle a ChannelMonitorUpdate that closes a channel, broadcasting its current latest holder
505-
/// commitment transaction.
506-
ClosingMonitorUpdate((OutPoint, ChannelMonitorUpdate)),
504+
/// Handle a ChannelMonitorUpdate
505+
///
506+
/// Note that any such events are lost on shutdown, so in general they must be updates which
507+
/// are regenerated on startup.
508+
MonitorUpdateRegeneratedOnStartup((OutPoint, ChannelMonitorUpdate)),
507509
}
508510

509511
#[derive(Debug)]
@@ -3774,7 +3776,7 @@ where
37743776

37753777
for event in background_events.drain(..) {
37763778
match event {
3777-
BackgroundEvent::ClosingMonitorUpdate((funding_txo, update)) => {
3779+
BackgroundEvent::MonitorUpdateRegeneratedOnStartup((funding_txo, update)) => {
37783780
// The channel has already been closed, so no use bothering to care about the
37793781
// monitor updating completing.
37803782
let _ = self.chain_monitor.update_channel(funding_txo, &update);
@@ -5694,7 +5696,7 @@ where
56945696
if let ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast } = update.updates[0] {
56955697
assert!(should_broadcast);
56965698
} else { unreachable!(); }
5697-
self.pending_background_events.lock().unwrap().push(BackgroundEvent::ClosingMonitorUpdate((funding_txo, update)));
5699+
self.pending_background_events.lock().unwrap().push(BackgroundEvent::MonitorUpdateRegeneratedOnStartup((funding_txo, update)));
56985700
}
56995701
self.finish_force_close_channel(failure);
57005702
}
@@ -7449,10 +7451,10 @@ where
74497451
}
74507452

74517453
// LDK versions prior to 0.0.116 wrote the `pending_background_events`
7452-
// `ClosingMonitorUpdate`s here, however there was never a reason to do so - the closing
7453-
// monitor updates were always effectively replayed on startup (either directly by calling
7454-
// `broadcast_latest_holder_commitment_txn` on a `ChannelMonitor` during deserialization
7455-
// or, in 0.0.115, by regenerating the monitor update itself).
7454+
// `MonitorUpdateRegeneratedOnStartup`s here, however there was never a reason to do so -
7455+
// the closing monitor updates were always effectively replayed on startup (either directly
7456+
// by calling `broadcast_latest_holder_commitment_txn` on a `ChannelMonitor` during
7457+
// deserialization or, in 0.0.115, by regenerating the monitor update itself).
74567458
0u64.write(writer)?;
74577459

74587460
// Prior to 0.0.111 we tracked node_announcement serials here, however that now happens in
@@ -7768,7 +7770,7 @@ where
77687770
log_bytes!(channel.channel_id()), monitor.get_latest_update_id(), channel.get_latest_monitor_update_id());
77697771
let (monitor_update, mut new_failed_htlcs) = channel.force_shutdown(true);
77707772
if let Some(monitor_update) = monitor_update {
7771-
pending_background_events.push(BackgroundEvent::ClosingMonitorUpdate(monitor_update));
7773+
pending_background_events.push(BackgroundEvent::MonitorUpdateRegeneratedOnStartup(monitor_update));
77727774
}
77737775
failed_htlcs.append(&mut new_failed_htlcs);
77747776
channel_closures.push_back((events::Event::ChannelClosed {
@@ -7843,7 +7845,7 @@ where
78437845
update_id: CLOSED_CHANNEL_UPDATE_ID,
78447846
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast: true }],
78457847
};
7846-
pending_background_events.push(BackgroundEvent::ClosingMonitorUpdate((*funding_txo, monitor_update)));
7848+
pending_background_events.push(BackgroundEvent::MonitorUpdateRegeneratedOnStartup((*funding_txo, monitor_update)));
78477849
}
78487850
}
78497851

@@ -7900,7 +7902,7 @@ where
79007902
for _ in 0..background_event_count {
79017903
match <u8 as Readable>::read(reader)? {
79027904
0 => {
7903-
// LDK versions prior to 0.0.116 wrote pending `ClosingMonitorUpdate`s here,
7905+
// LDK versions prior to 0.0.116 wrote pending `MonitorUpdateRegeneratedOnStartup`s here,
79047906
// however we really don't (and never did) need them - we regenerate all
79057907
// on-startup monitor updates.
79067908
let _: OutPoint = Readable::read(reader)?;

0 commit comments

Comments
 (0)