Skip to content

Commit f1f28a7

Browse files
committed
f remove completed during init
1 parent f52ed23 commit f1f28a7

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
@@ -8359,25 +8359,37 @@ where
83598359
}
83608360

83618361
if let Some(in_flight_upds) = in_flight_monitor_updates {
8362-
for ((counterparty_id, funding_txo), chan_in_flight_updates) in in_flight_upds {
8363-
// Now that we've removed all the in-flight monitor updates for channels that are
8364-
// still open, we need to replay any monitor updates that are for closed channels,
8365-
// creating the neccessary peer_state entries as we go.
8366-
let peer_state_mutex = per_peer_state.entry(counterparty_id).or_insert_with(|| {
8367-
Mutex::new(peer_state_from_chans(HashMap::new()))
8368-
});
8369-
let mut peer_state = peer_state_mutex.lock().unwrap();
8370-
for update in chan_in_flight_updates.iter() {
8371-
log_trace!(args.logger, "Replaying ChannelMonitorUpdate {} for closed channel {}",
8372-
update.update_id, log_bytes!(funding_txo.to_channel_id()));
8373-
pending_background_events.push(
8374-
BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
8375-
counterparty_node_id: counterparty_id,
8376-
funding_txo, update: update.clone(),
8377-
});
8378-
}
8379-
if peer_state.in_flight_monitor_updates.insert(funding_txo, chan_in_flight_updates).is_some() {
8380-
log_error!(args.logger, "Duplicate in-flight monitor update set for the same channel!");
8362+
for ((counterparty_id, funding_txo), mut chan_in_flight_updates) in in_flight_upds {
8363+
if let Some(monitor) = args.channel_monitors.get(&funding_txo) {
8364+
// Now that we've removed all the in-flight monitor updates for channels that are
8365+
// still open, we need to replay any monitor updates that are for closed channels,
8366+
// creating the neccessary peer_state entries as we go.
8367+
let peer_state_mutex = per_peer_state.entry(counterparty_id).or_insert_with(|| {
8368+
Mutex::new(peer_state_from_chans(HashMap::new()))
8369+
});
8370+
let mut peer_state = peer_state_mutex.lock().unwrap();
8371+
chan_in_flight_updates.retain(|upd| upd.update_id > monitor.get_latest_update_id());
8372+
for update in chan_in_flight_updates.iter() {
8373+
log_trace!(args.logger, "Replaying ChannelMonitorUpdate {} for closed channel {}",
8374+
update.update_id, log_bytes!(funding_txo.to_channel_id()));
8375+
pending_background_events.push(
8376+
BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
8377+
counterparty_node_id: counterparty_id,
8378+
funding_txo, update: update.clone(),
8379+
});
8380+
}
8381+
if peer_state.in_flight_monitor_updates.insert(funding_txo, chan_in_flight_updates).is_some() {
8382+
log_error!(args.logger, "Duplicate in-flight monitor update set for the same channel!");
8383+
return Err(DecodeError::InvalidValue);
8384+
}
8385+
} else {
8386+
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!");
8387+
log_error!(args.logger, " The ChannelMonitor for channel {} is missing.",
8388+
log_bytes!(funding_txo.to_channel_id()));
8389+
log_error!(args.logger, " The chain::Watch API *requires* that monitors are persisted durably before returning,");
8390+
log_error!(args.logger, " client applications must ensure that ChannelMonitor data is always available and the latest to avoid funds loss!");
8391+
log_error!(args.logger, " Without the latest ChannelMonitor we cannot continue without risking funds.");
8392+
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");
83818393
return Err(DecodeError::InvalidValue);
83828394
}
83838395
}

0 commit comments

Comments
 (0)