Skip to content

Commit 7e3e4df

Browse files
committed
f remove completed during init
1 parent 092415d commit 7e3e4df

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8427,25 +8427,37 @@ where
84278427
}
84288428

84298429
if let Some(in_flight_upds) = in_flight_monitor_updates {
8430-
for ((counterparty_id, funding_txo), chan_in_flight_updates) in in_flight_upds {
8431-
// Now that we've removed all the in-flight monitor updates for channels that are
8432-
// still open, we need to replay any monitor updates that are for closed channels,
8433-
// creating the neccessary peer_state entries as we go.
8434-
let peer_state_mutex = per_peer_state.entry(counterparty_id).or_insert_with(|| {
8435-
Mutex::new(peer_state_from_chans(HashMap::new()))
8436-
});
8437-
let mut peer_state = peer_state_mutex.lock().unwrap();
8438-
for update in chan_in_flight_updates.iter() {
8439-
log_trace!(args.logger, "Replaying ChannelMonitorUpdate {} for closed channel {}",
8440-
update.update_id, log_bytes!(funding_txo.to_channel_id()));
8441-
pending_background_events.push(
8442-
BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
8443-
counterparty_node_id: counterparty_id,
8444-
funding_txo, update: update.clone(),
8445-
});
8446-
}
8447-
if peer_state.in_flight_monitor_updates.insert(funding_txo, chan_in_flight_updates).is_some() {
8448-
log_error!(args.logger, "Duplicate in-flight monitor update set for the same channel!");
8430+
for ((counterparty_id, funding_txo), mut chan_in_flight_updates) in in_flight_upds {
8431+
if let Some(monitor) = args.channel_monitors.get(&funding_txo) {
8432+
// Now that we've removed all the in-flight monitor updates for channels that are
8433+
// still open, we need to replay any monitor updates that are for closed channels,
8434+
// creating the neccessary peer_state entries as we go.
8435+
let peer_state_mutex = per_peer_state.entry(counterparty_id).or_insert_with(|| {
8436+
Mutex::new(peer_state_from_chans(HashMap::new()))
8437+
});
8438+
let mut peer_state = peer_state_mutex.lock().unwrap();
8439+
chan_in_flight_updates.retain(|upd| upd.update_id > monitor.get_latest_update_id());
8440+
for update in chan_in_flight_updates.iter() {
8441+
log_trace!(args.logger, "Replaying ChannelMonitorUpdate {} for closed channel {}",
8442+
update.update_id, log_bytes!(funding_txo.to_channel_id()));
8443+
pending_background_events.push(
8444+
BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
8445+
counterparty_node_id: counterparty_id,
8446+
funding_txo, update: update.clone(),
8447+
});
8448+
}
8449+
if peer_state.in_flight_monitor_updates.insert(funding_txo, chan_in_flight_updates).is_some() {
8450+
log_error!(args.logger, "Duplicate in-flight monitor update set for the same channel!");
8451+
return Err(DecodeError::InvalidValue);
8452+
}
8453+
} else {
8454+
log_error!(args.logger, "A ChannelMonitor is missing even though we have in-flight updates for it! This indicates a potentially-critical violation of the chain::Watch API!");
8455+
log_error!(args.logger, " The ChannelMonitor for channel {} is missing.",
8456+
log_bytes!(funding_txo.to_channel_id()));
8457+
log_error!(args.logger, " The chain::Watch API *requires* that monitors are persisted durably before returning,");
8458+
log_error!(args.logger, " client applications must ensure that ChannelMonitor data is always available and the latest to avoid funds loss!");
8459+
log_error!(args.logger, " Without the latest ChannelMonitor we cannot continue without risking funds.");
8460+
log_error!(args.logger, " Please ensure the chain::Watch API requirements are met and file a bug report at https://github.com/lightningdevkit/rust-lightning");
84498461
return Err(DecodeError::InvalidValue);
84508462
}
84518463
}

0 commit comments

Comments
 (0)