Skip to content

Commit 8387cd6

Browse files
committed
f always drop outbound channels on peer_connected
1 parent 2fb7bba commit 8387cd6

File tree

2 files changed

+13
-30
lines changed

2 files changed

+13
-30
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7114,35 +7114,25 @@ where
71147114
log_debug!(self.logger, "Generating channel_reestablish events for {}", log_pubkey!(counterparty_node_id));
71157115

71167116
let per_peer_state = self.per_peer_state.read().unwrap();
7117-
for (_cp_id, peer_state_mutex) in per_peer_state.iter() {
7117+
if let Some(peer_state_mutex) = per_peer_state.get(counterparty_node_id) {
71187118
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
71197119
let peer_state = &mut *peer_state_lock;
71207120
let pending_msg_events = &mut peer_state.pending_msg_events;
71217121
peer_state.outbound_v1_channel_by_id.retain(|_, chan| {
7122-
if chan.context.get_counterparty_node_id() == *counterparty_node_id {
7123-
// If we created this (outbound) channel while we were disconnected from the
7124-
// peer we probably failed to send the open_channel message, which is now
7125-
// lost. We can't have had anything pending related to this channel, so we just
7126-
// drop it.
7127-
chan.context.have_received_message()
7128-
} else { true }
7122+
// We shouldn't have any pending outbound channels upon reconnect. If one exists,
7123+
// then we probably tried to open a channel while the peer was disconnected and they
7124+
// wouldn't have received the corresponding channel open message. We can just force-close
7125+
// these channels and drop them.
7126+
log_error!(self.logger, "Force-closing channel {}", log_bytes!(chan.context.channel_id()));
7127+
self.issue_channel_close_events(&chan.context, ClosureReason::HolderForceClosed);
7128+
self.finish_force_close_channel(chan.context.force_shutdown(false));
7129+
false
71297130
});
71307131
peer_state.channel_by_id.iter_mut().for_each(|(_, chan)| {
7131-
if chan.context.get_counterparty_node_id() == *counterparty_node_id {
7132-
pending_msg_events.push(events::MessageSendEvent::SendChannelReestablish {
7133-
node_id: chan.context.get_counterparty_node_id(),
7134-
msg: chan.get_channel_reestablish(&self.logger),
7135-
});
7136-
} else {
7137-
if let Some(msg) = chan.get_signed_channel_announcement(&self.node_signer, self.genesis_hash.clone(), self.best_block.read().unwrap().height(), &self.default_configuration) {
7138-
if let Ok(update_msg) = self.get_channel_update_for_broadcast(chan) {
7139-
pending_msg_events.push(events::MessageSendEvent::SendChannelAnnouncement {
7140-
node_id: *counterparty_node_id,
7141-
msg, update_msg,
7142-
});
7143-
}
7144-
}
7145-
}
7132+
pending_msg_events.push(events::MessageSendEvent::SendChannelReestablish {
7133+
node_id: chan.context.get_counterparty_node_id(),
7134+
msg: chan.get_channel_reestablish(&self.logger),
7135+
});
71467136
});
71477137
}
71487138
//TODO: Also re-broadcast announcement_signatures

lightning/src/ln/functional_test_utils.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,13 +2816,6 @@ macro_rules! get_chan_reestablish_msgs {
28162816
panic!("Unexpected event")
28172817
}
28182818
}
2819-
for chan in $src_node.node.list_channels() {
2820-
if chan.is_public && chan.counterparty.node_id != $dst_node.node.get_our_node_id() {
2821-
if let Some(scid) = chan.short_channel_id {
2822-
assert!(announcements.remove(&scid));
2823-
}
2824-
}
2825-
}
28262819
assert!(announcements.is_empty());
28272820
res
28282821
}

0 commit comments

Comments
 (0)