Skip to content

Commit d5dbce3

Browse files
committed
f push channel_update generate down to callsites, always send on reconnect
1 parent b9a624f commit d5dbce3

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -947,11 +947,6 @@ macro_rules! handle_chan_restoration_locked {
947947
node_id: counterparty_node_id,
948948
msg: announcement_sigs,
949949
});
950-
} else if $channel_entry.get().is_usable() {
951-
$channel_state.pending_msg_events.push(events::MessageSendEvent::SendChannelUpdate {
952-
node_id: counterparty_node_id,
953-
msg: $self.get_channel_update_for_unicast($channel_entry.get()).unwrap(),
954-
});
955950
}
956951
$channel_state.short_to_id.insert($channel_entry.get().get_short_channel_id().unwrap(), $channel_entry.get().channel_id());
957952
}
@@ -2791,7 +2786,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
27912786
pub fn channel_monitor_updated(&self, funding_txo: &OutPoint, highest_applied_update_id: u64) {
27922787
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
27932788

2794-
let (mut pending_failures, chan_restoration_res) = {
2789+
let chan_restoration_res;
2790+
let mut pending_failures = {
27952791
let mut channel_lock = self.channel_state.lock().unwrap();
27962792
let channel_state = &mut *channel_lock;
27972793
let mut channel = match channel_state.by_id.entry(funding_txo.to_channel_id()) {
@@ -2803,7 +2799,22 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
28032799
}
28042800

28052801
let (raa, commitment_update, order, pending_forwards, pending_failures, funding_broadcastable, funding_locked) = channel.get_mut().monitor_updating_restored(&self.logger);
2806-
(pending_failures, handle_chan_restoration_locked!(self, channel_lock, channel_state, channel, raa, commitment_update, order, None, pending_forwards, funding_broadcastable, funding_locked))
2802+
let channel_update = if funding_locked.is_some() && channel.get().is_usable() {
2803+
Some(events::MessageSendEvent::SendChannelUpdate {
2804+
node_id: channel.get().get_counterparty_node_id(),
2805+
msg: self.get_channel_update_for_unicast(channel.get()).unwrap(),
2806+
})
2807+
} else { None };
2808+
chan_restoration_res = handle_chan_restoration_locked!(self, channel_lock, channel_state, channel, raa, commitment_update, order, None, pending_forwards, funding_broadcastable, funding_locked);
2809+
if let Some(upd) = channel_update {
2810+
// If we closed the channel due to a failed monitor update in
2811+
// handle_chan_restoration_locked this will send a bogus channel_update immediately
2812+
// after closure, but our direct peer should be fine with that, given they know the
2813+
// channel state as well. Further, we'll broadcast a channel_disabled channel_update
2814+
// in post_handle_chan_restoration below for public channels.
2815+
channel_state.pending_msg_events.push(upd);
2816+
}
2817+
pending_failures
28072818
};
28082819
post_handle_chan_restoration!(self, chan_restoration_res);
28092820
for failure in pending_failures.drain(..) {
@@ -3395,7 +3406,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
33953406
}
33963407

33973408
fn internal_channel_reestablish(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReestablish) -> Result<(), MsgHandleErrInternal> {
3398-
let (htlcs_failed_forward, chan_restoration_res) = {
3409+
let chan_restoration_res;
3410+
let htlcs_failed_forward = {
33993411
let mut channel_state_lock = self.channel_state.lock().unwrap();
34003412
let channel_state = &mut *channel_state_lock;
34013413

@@ -3410,13 +3422,28 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
34103422
// add-HTLCs on disconnect, we may be handed HTLCs to fail backwards here.
34113423
let (funding_locked, revoke_and_ack, commitment_update, monitor_update_opt, order, htlcs_failed_forward, shutdown) =
34123424
try_chan_entry!(self, chan.get_mut().channel_reestablish(msg, &self.logger), channel_state, chan);
3425+
let mut channel_update = None;
34133426
if let Some(msg) = shutdown {
34143427
channel_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
34153428
node_id: counterparty_node_id.clone(),
34163429
msg,
34173430
});
3431+
} else if chan.get().is_usable() {
3432+
channel_update = Some(events::MessageSendEvent::SendChannelUpdate {
3433+
node_id: chan.get().get_counterparty_node_id(),
3434+
msg: self.get_channel_update_for_unicast(chan.get()).unwrap(),
3435+
});
3436+
}
3437+
chan_restoration_res = handle_chan_restoration_locked!(self, channel_state_lock, channel_state, chan, revoke_and_ack, commitment_update, order, monitor_update_opt, Vec::new(), None, funding_locked);
3438+
if let Some(upd) = channel_update {
3439+
// If we closed the channel due to a failed monitor update in
3440+
// handle_chan_restoration_locked this will send a bogus channel_update immediately
3441+
// after closure, but our direct peer should be fine with that, given they know the
3442+
// channel state as well. Further, we'll broadcast a channel_disabled channel_update
3443+
// in post_handle_chan_restoration below for public channels.
3444+
channel_state.pending_msg_events.push(upd);
34183445
}
3419-
(htlcs_failed_forward, handle_chan_restoration_locked!(self, channel_state_lock, channel_state, chan, revoke_and_ack, commitment_update, order, monitor_update_opt, Vec::new(), None, funding_locked))
3446+
htlcs_failed_forward
34203447
},
34213448
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
34223449
}

0 commit comments

Comments
 (0)