Skip to content

Commit 6e2d744

Browse files
TheBlueMatttnull
authored andcommitted
Merge pull request lightningdevkit#1429 from TheBlueMatt/2022-04-drop-no-conn-possible
2 parents d166044 + e39d63c commit 6e2d744

File tree

4 files changed

+32
-46
lines changed

4 files changed

+32
-46
lines changed

lightning/src/ln/channelmanager.rs

+11-29
Original file line numberDiff line numberDiff line change
@@ -5698,39 +5698,21 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
56985698
let channel_state = &mut *channel_state_lock;
56995699
let pending_msg_events = &mut channel_state.pending_msg_events;
57005700
let short_to_id = &mut channel_state.short_to_id;
5701-
if no_connection_possible {
5702-
log_debug!(self.logger, "Failing all channels with {} due to no_connection_possible", log_pubkey!(counterparty_node_id));
5703-
channel_state.by_id.retain(|_, chan| {
5704-
if chan.get_counterparty_node_id() == *counterparty_node_id {
5701+
log_debug!(self.logger, "Marking channels with {} disconnected and generating channel_updates. We believe we {} make future connections to this peer.",
5702+
log_pubkey!(counterparty_node_id), if no_connection_possible { "cannot" } else { "can" });
5703+
channel_state.by_id.retain(|_, chan| {
5704+
if chan.get_counterparty_node_id() == *counterparty_node_id {
5705+
chan.remove_uncommitted_htlcs_and_mark_paused(&self.logger);
5706+
if chan.is_shutdown() {
57055707
update_maps_on_chan_removal!(self, short_to_id, chan);
5706-
failed_channels.push(chan.force_shutdown(true));
5707-
if let Ok(update) = self.get_channel_update_for_broadcast(&chan) {
5708-
pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
5709-
msg: update
5710-
});
5711-
}
57125708
self.issue_channel_close_events(chan, ClosureReason::DisconnectedPeer);
5713-
false
5709+
return false;
57145710
} else {
5715-
true
5716-
}
5717-
});
5718-
} else {
5719-
log_debug!(self.logger, "Marking channels with {} disconnected and generating channel_updates", log_pubkey!(counterparty_node_id));
5720-
channel_state.by_id.retain(|_, chan| {
5721-
if chan.get_counterparty_node_id() == *counterparty_node_id {
5722-
chan.remove_uncommitted_htlcs_and_mark_paused(&self.logger);
5723-
if chan.is_shutdown() {
5724-
update_maps_on_chan_removal!(self, short_to_id, chan);
5725-
self.issue_channel_close_events(chan, ClosureReason::DisconnectedPeer);
5726-
return false;
5727-
} else {
5728-
no_channels_remain = false;
5729-
}
5711+
no_channels_remain = false;
57305712
}
5731-
true
5732-
})
5733-
}
5713+
}
5714+
true
5715+
});
57345716
pending_msg_events.retain(|msg| {
57355717
match msg {
57365718
&events::MessageSendEvent::SendAcceptChannel { ref node_id, .. } => node_id != counterparty_node_id,

lightning/src/ln/functional_tests.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -2178,9 +2178,9 @@ fn channel_monitor_network_test() {
21782178
send_payment(&nodes[0], &vec!(&nodes[1], &nodes[2], &nodes[3], &nodes[4])[..], 8000000);
21792179

21802180
// Simple case with no pending HTLCs:
2181-
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), true);
2181+
nodes[1].node.force_close_channel(&chan_1.2).unwrap();
21822182
check_added_monitors!(nodes[1], 1);
2183-
check_closed_broadcast!(nodes[1], false);
2183+
check_closed_broadcast!(nodes[1], true);
21842184
{
21852185
let mut node_txn = test_txn_broadcast(&nodes[1], &chan_1, None, HTLCType::NONE);
21862186
assert_eq!(node_txn.len(), 1);
@@ -2192,15 +2192,15 @@ fn channel_monitor_network_test() {
21922192
assert_eq!(nodes[0].node.list_channels().len(), 0);
21932193
assert_eq!(nodes[1].node.list_channels().len(), 1);
21942194
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
2195-
check_closed_event!(nodes[1], 1, ClosureReason::DisconnectedPeer);
2195+
check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed);
21962196

21972197
// One pending HTLC is discarded by the force-close:
21982198
let payment_preimage_1 = route_payment(&nodes[1], &vec!(&nodes[2], &nodes[3])[..], 3000000).0;
21992199

22002200
// Simple case of one pending HTLC to HTLC-Timeout (note that the HTLC-Timeout is not
22012201
// broadcasted until we reach the timelock time).
2202-
nodes[1].node.peer_disconnected(&nodes[2].node.get_our_node_id(), true);
2203-
check_closed_broadcast!(nodes[1], false);
2202+
nodes[1].node.force_close_channel(&chan_2.2).unwrap();
2203+
check_closed_broadcast!(nodes[1], true);
22042204
check_added_monitors!(nodes[1], 1);
22052205
{
22062206
let mut node_txn = test_txn_broadcast(&nodes[1], &chan_2, None, HTLCType::NONE);
@@ -2213,7 +2213,7 @@ fn channel_monitor_network_test() {
22132213
check_closed_broadcast!(nodes[2], true);
22142214
assert_eq!(nodes[1].node.list_channels().len(), 0);
22152215
assert_eq!(nodes[2].node.list_channels().len(), 1);
2216-
check_closed_event!(nodes[1], 1, ClosureReason::DisconnectedPeer);
2216+
check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed);
22172217
check_closed_event!(nodes[2], 1, ClosureReason::CommitmentTxConfirmed);
22182218

22192219
macro_rules! claim_funds {
@@ -2238,9 +2238,9 @@ fn channel_monitor_network_test() {
22382238

22392239
// nodes[3] gets the preimage, but nodes[2] already disconnected, resulting in a nodes[2]
22402240
// HTLC-Timeout and a nodes[3] claim against it (+ its own announces)
2241-
nodes[2].node.peer_disconnected(&nodes[3].node.get_our_node_id(), true);
2241+
nodes[2].node.force_close_channel(&chan_3.2).unwrap();
22422242
check_added_monitors!(nodes[2], 1);
2243-
check_closed_broadcast!(nodes[2], false);
2243+
check_closed_broadcast!(nodes[2], true);
22442244
let node2_commitment_txid;
22452245
{
22462246
let node_txn = test_txn_broadcast(&nodes[2], &chan_3, None, HTLCType::NONE);
@@ -2257,7 +2257,7 @@ fn channel_monitor_network_test() {
22572257
check_closed_broadcast!(nodes[3], true);
22582258
assert_eq!(nodes[2].node.list_channels().len(), 0);
22592259
assert_eq!(nodes[3].node.list_channels().len(), 1);
2260-
check_closed_event!(nodes[2], 1, ClosureReason::DisconnectedPeer);
2260+
check_closed_event!(nodes[2], 1, ClosureReason::HolderForceClosed);
22612261
check_closed_event!(nodes[3], 1, ClosureReason::CommitmentTxConfirmed);
22622262

22632263
// Drop the ChannelMonitor for the previous channel to avoid it broadcasting transactions and

lightning/src/ln/peer_handler.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,13 @@ pub trait SocketDescriptor : cmp::Eq + hash::Hash + Clone {
258258
/// descriptor.
259259
#[derive(Clone)]
260260
pub struct PeerHandleError {
261-
/// Used to indicate that we probably can't make any future connections to this peer, implying
262-
/// we should go ahead and force-close any channels we have with it.
261+
/// Used to indicate that we probably can't make any future connections to this peer (e.g.
262+
/// because we required features that our peer was missing, or vice versa).
263+
///
264+
/// While LDK's [`ChannelManager`] will not do it automatically, you likely wish to force-close
265+
/// any channels with this peer or check for new versions of LDK.
266+
///
267+
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
263268
pub no_connection_possible: bool,
264269
}
265270
impl fmt::Debug for PeerHandleError {

lightning/src/util/events.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ pub enum ClosureReason {
100100
/// A developer-readable error message which we generated.
101101
err: String,
102102
},
103-
/// The `PeerManager` informed us that we've disconnected from the peer. We close channels
104-
/// if the `PeerManager` informed us that it is unlikely we'll be able to connect to the
105-
/// peer again in the future or if the peer disconnected before we finished negotiating
106-
/// the channel open. The first case may be caused by incompatible features which our
107-
/// counterparty, or we, require.
108-
//TODO: split between PeerUnconnectable/PeerDisconnected ?
103+
/// The peer disconnected prior to funding completing. In this case the spec mandates that we
104+
/// forget the channel entirely - we can attempt again if the peer reconnects.
105+
///
106+
/// In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
107+
/// peer because of mutual incompatibility between us and our channel counterparty.
109108
DisconnectedPeer,
110109
/// Closure generated from `ChannelManager::read` if the ChannelMonitor is newer than
111110
/// the ChannelManager deserialized.

0 commit comments

Comments
 (0)