Skip to content

Commit 01aab17

Browse files
committed
f dont assume v1 for already closed
1 parent f41f16b commit 01aab17

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lightning/src/ln/channelmanager.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -10631,19 +10631,19 @@ where
1063110631
let mut pending_background_events = Vec::new();
1063210632
macro_rules! handle_in_flight_updates {
1063310633
($counterparty_node_id: expr, $chan_in_flight_upds: expr, $funding_txo: expr,
10634-
$channel_id: expr, $monitor: expr, $peer_state: expr, $logger: expr, $channel_info_log: expr
10634+
$monitor: expr, $peer_state: expr, $logger: expr, $channel_info_log: expr
1063510635
) => { {
1063610636
let mut max_in_flight_update_id = 0;
1063710637
$chan_in_flight_upds.retain(|upd| upd.update_id > $monitor.get_latest_update_id());
1063810638
for update in $chan_in_flight_upds.iter() {
1063910639
log_trace!($logger, "Replaying ChannelMonitorUpdate {} for {}channel {}",
10640-
update.update_id, $channel_info_log, &$channel_id);
10640+
update.update_id, $channel_info_log, &$monitor.channel_id());
1064110641
max_in_flight_update_id = cmp::max(max_in_flight_update_id, update.update_id);
1064210642
pending_background_events.push(
1064310643
BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
1064410644
counterparty_node_id: $counterparty_node_id,
1064510645
funding_txo: $funding_txo,
10646-
channel_id: $channel_id,
10646+
channel_id: $monitor.channel_id(),
1064710647
update: update.clone(),
1064810648
});
1064910649
}
@@ -10654,7 +10654,7 @@ where
1065410654
pending_background_events.push(
1065510655
BackgroundEvent::MonitorUpdatesComplete {
1065610656
counterparty_node_id: $counterparty_node_id,
10657-
channel_id: $channel_id,
10657+
channel_id: $monitor.channel_id(),
1065810658
});
1065910659
}
1066010660
if $peer_state.in_flight_monitor_updates.insert($funding_txo, $chan_in_flight_upds).is_some() {
@@ -10675,15 +10675,14 @@ where
1067510675
// Channels that were persisted have to be funded, otherwise they should have been
1067610676
// discarded.
1067710677
let funding_txo = chan.context.get_funding_txo().ok_or(DecodeError::InvalidValue)?;
10678-
let channel_id = chan.context.channel_id();
1067910678
let monitor = args.channel_monitors.get(&funding_txo)
1068010679
.expect("We already checked for monitor presence when loading channels");
1068110680
let mut max_in_flight_update_id = monitor.get_latest_update_id();
1068210681
if let Some(in_flight_upds) = &mut in_flight_monitor_updates {
1068310682
if let Some(mut chan_in_flight_upds) = in_flight_upds.remove(&(*counterparty_id, funding_txo)) {
1068410683
max_in_flight_update_id = cmp::max(max_in_flight_update_id,
1068510684
handle_in_flight_updates!(*counterparty_id, chan_in_flight_upds,
10686-
funding_txo, channel_id, monitor, peer_state, logger, ""));
10685+
funding_txo, monitor, peer_state, logger, ""));
1068710686
}
1068810687
}
1068910688
if chan.get_latest_unblocked_monitor_update_id() > max_in_flight_update_id {
@@ -10709,8 +10708,8 @@ where
1070910708

1071010709
if let Some(in_flight_upds) = in_flight_monitor_updates {
1071110710
for ((counterparty_id, funding_txo), mut chan_in_flight_updates) in in_flight_upds {
10712-
let channel_id = funding_txo_to_channel_id.get(&funding_txo).copied().unwrap_or(ChannelId::v1_from_funding_outpoint(funding_txo));
10713-
let logger = WithContext::from(&args.logger, Some(counterparty_id), Some(channel_id));
10711+
let channel_id = funding_txo_to_channel_id.get(&funding_txo).copied();
10712+
let logger = WithContext::from(&args.logger, Some(counterparty_id), channel_id);
1071410713
if let Some(monitor) = args.channel_monitors.get(&funding_txo) {
1071510714
// Now that we've removed all the in-flight monitor updates for channels that are
1071610715
// still open, we need to replay any monitor updates that are for closed channels,
@@ -10720,10 +10719,11 @@ where
1072010719
});
1072110720
let mut peer_state = peer_state_mutex.lock().unwrap();
1072210721
handle_in_flight_updates!(counterparty_id, chan_in_flight_updates,
10723-
funding_txo, channel_id, monitor, peer_state, logger, "closed ");
10722+
funding_txo, monitor, peer_state, logger, "closed ");
1072410723
} else {
1072510724
log_error!(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!");
10726-
log_error!(logger, " The ChannelMonitor for channel {} is missing.", &channel_id);
10725+
log_error!(logger, " The ChannelMonitor for channel {} is missing.", if let Some(channel_id) =
10726+
channel_id { channel_id.to_string() } else { format!("with outpoint {}", funding_txo) } );
1072710727
log_error!(logger, " The chain::Watch API *requires* that monitors are persisted durably before returning,");
1072810728
log_error!(logger, " client applications must ensure that ChannelMonitor data is always available and the latest to avoid funds loss!");
1072910729
log_error!(logger, " Without the latest ChannelMonitor we cannot continue without risking funds.");

0 commit comments

Comments
 (0)