@@ -698,6 +698,18 @@ impl <Signer: ChannelSigner> PeerState<Signer> {
698
698
self . outbound_v1_channel_by_id . contains_key ( channel_id) ||
699
699
self . inbound_v1_channel_by_id . contains_key ( channel_id)
700
700
}
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
+ }
701
713
}
702
714
703
715
/// Stores a PaymentSecret and any other data we may need to validate an inbound payment is
@@ -2387,6 +2399,14 @@ where
2387
2399
2388
2400
let mut peer_state_lock = peer_state_mutex. lock ( ) . unwrap ( ) ;
2389
2401
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
+
2390
2410
match peer_state. channel_by_id . entry ( channel_id. clone ( ) ) {
2391
2411
hash_map:: Entry :: Occupied ( mut chan_entry) => {
2392
2412
let funding_txo_opt = chan_entry. get ( ) . context . get_funding_txo ( ) ;
0 commit comments