Skip to content

Commit 30eef0c

Browse files
committed
FC outbound chans we sent open_channel for when peer was offline
1 parent ad704c7 commit 30eef0c

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7144,7 +7144,13 @@ where
71447144
// peer we probably failed to send the open_channel message, which is now
71457145
// lost. We can't have had anything pending related to this channel, so we just
71467146
// drop it.
7147-
chan.context.have_received_message()
7147+
let retain = chan.context.have_received_message();
7148+
if !retain {
7149+
log_error!(self.logger, "Force-closing channel {}", log_bytes!(chan.context.channel_id()));
7150+
self.issue_channel_close_events(&chan.context, ClosureReason::HolderForceClosed);
7151+
self.finish_force_close_channel(chan.context.force_shutdown(false));
7152+
}
7153+
retain
71487154
} else { true }
71497155
});
71507156
peer_state.channel_by_id.iter_mut().for_each(|(_, chan)| {
@@ -9394,6 +9400,33 @@ mod tests {
93949400
}
93959401
}
93969402

9403+
#[test]
9404+
fn test_outbound_channels_created_when_disconnected_removed_on_peer_connected() {
9405+
let chanmon_cfgs = create_chanmon_cfgs(2);
9406+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
9407+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
9408+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
9409+
9410+
let temporary_channel_id = nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 1_000_000, 500_000_000, 42, None).unwrap();
9411+
9412+
{
9413+
let per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
9414+
let peer_state_mutex = per_peer_state.get(&nodes[1].node.get_our_node_id()).unwrap();
9415+
let mut peer_state = peer_state_mutex.lock().unwrap();
9416+
peer_state.is_connected = false;
9417+
}
9418+
9419+
let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
9420+
assert_eq!(open_channel.temporary_channel_id, temporary_channel_id);
9421+
9422+
nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init {
9423+
features: nodes[0].node.init_features(), networks: None, remote_network_address: None
9424+
}, true).unwrap();
9425+
9426+
check_closed_event(&nodes[0], 1, ClosureReason::HolderForceClosed, false);
9427+
let chan_closed_events = nodes[1].node.get_and_clear_pending_events();
9428+
}
9429+
93979430
#[test]
93989431
fn test_drop_disconnected_peers_when_removing_channels() {
93999432
let chanmon_cfgs = create_chanmon_cfgs(2);

0 commit comments

Comments
 (0)