@@ -1585,6 +1585,44 @@ where
15851585 } => {
15861586 log_info ! ( self . logger, "Channel {} closed due to: {}" , channel_id, reason) ;
15871587
1588+ // If the counterparty initiated closure of their last remaining channel
1589+ // with us, remove them from the peer store so we stop trying to reconnect.
1590+ //
1591+ // If we initiated the closure, keep them in the peer store so the
1592+ // background reconnection task fires and we can complete the
1593+ // channel_reestablish recovery flow. This matters especially for LND
1594+ // peers, which need us to reconnect to recover from force-closures.
1595+ //
1596+ // We exclude `channel_id` from the remaining-channel check because LDK
1597+ // fires ChannelClosed before removing the channel from its internal list,
1598+ // so list_channels_with_counterparty still includes the closing channel.
1599+ if let Some ( counterparty_node_id) = counterparty_node_id {
1600+ let counterparty_initiated = matches ! (
1601+ reason,
1602+ ClosureReason :: CounterpartyForceClosed { .. }
1603+ | ClosureReason :: CounterpartyInitiatedCooperativeClosure
1604+ ) ;
1605+
1606+ if counterparty_initiated {
1607+ let has_other_channels = self
1608+ . channel_manager
1609+ . list_channels_with_counterparty ( & counterparty_node_id)
1610+ . iter ( )
1611+ . any ( |c| c. channel_id != channel_id) ;
1612+
1613+ if !has_other_channels {
1614+ if let Err ( e) = self . peer_store . remove_peer ( & counterparty_node_id) {
1615+ log_error ! (
1616+ self . logger,
1617+ "Failed to remove peer {} from peer store: {}" ,
1618+ counterparty_node_id,
1619+ e
1620+ ) ;
1621+ }
1622+ }
1623+ }
1624+ }
1625+
15881626 let event = Event :: ChannelClosed {
15891627 channel_id,
15901628 user_channel_id : UserChannelId ( user_channel_id) ,
0 commit comments