Skip to content

Commit b10127c

Browse files
committed
Fallback close_channel_internal to force close unfunded channels
1 parent c93b709 commit b10127c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,18 @@ impl <Signer: ChannelSigner> PeerState<Signer> {
698698
self.outbound_v1_channel_by_id.contains_key(channel_id) ||
699699
self.inbound_v1_channel_by_id.contains_key(channel_id)
700700
}
701+
702+
/// Returns a bool indicating whether the given `channel_id` matches a channel we have with this
703+
/// peer that is in one of our pending (unfunded) channel maps.
704+
///
705+
/// NOTE: Although V1 established channels will always have a `temporary_channel_id` if they're
706+
/// in `(outbound/inbound)_v1_channel_by_id`, we use the more general `channel_id` as V2
707+
/// established channels will have a fixed `channel_id` already after the `accept_channel2`
708+
/// message is sent/received.
709+
fn has_pending_channel(&self, channel_id: &[u8; 32]) -> bool {
710+
self.outbound_v1_channel_by_id.contains_key(channel_id) ||
711+
self.inbound_v1_channel_by_id.contains_key(channel_id)
712+
}
701713
}
702714

703715
/// Stores a PaymentSecret and any other data we may need to validate an inbound payment is
@@ -2387,6 +2399,14 @@ where
23872399

23882400
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
23892401
let peer_state = &mut *peer_state_lock;
2402+
2403+
if peer_state.has_pending_channel(&channel_id) {
2404+
// If the channel was still in an unfunded channel map, then we force-close the channel, ignoring
2405+
// any channel-not-found errors.
2406+
let _ = self.force_close_channel_with_peer(&channel_id, counterparty_node_id, None, false);
2407+
return Ok(());
2408+
}
2409+
23902410
match peer_state.channel_by_id.entry(channel_id.clone()) {
23912411
hash_map::Entry::Occupied(mut chan_entry) => {
23922412
let funding_txo_opt = chan_entry.get().context.get_funding_txo();

0 commit comments

Comments
 (0)