File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1842,9 +1842,15 @@ impl Node {
18421842 }
18431843
18441844 // Check if this was the last open channel, if so, forget the peer.
1845- if open_channels. len ( ) == 1 {
1845+ //For force-closes we keep the peer
1846+ // in the store so the background reconnection task can fire and
1847+ // complete the channel_reestablish recovery flow. This is especially
1848+ // important for LND peers
1849+ // The peer will be removed by the ChannelClosed event handler once
1850+ // the counterparty reconnects and confirms closure.
1851+ if open_channels. len ( ) == 1 && !force {
18461852 self . peer_store . remove_peer ( & counterparty_node_id) ?;
1847- }
1853+ }
18481854 }
18491855
18501856 Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -3019,7 +3019,7 @@ async fn test_peer_removed_on_counterparty_force_close() {
30193019}
30203020
30213021#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
3022- async fn test_peer_not_persisted_on_local_force_close ( ) {
3022+ async fn test_peer_retained_on_local_force_close ( ) {
30233023 // When WE force-close, keep the peer in the store so we can reconnect
30243024 // and complete channel_reestablish recovery. This matters especially
30253025 // for LND counterparties that may not handle force-closure error
@@ -3071,8 +3071,8 @@ async fn test_peer_not_persisted_on_local_force_close() {
30713071
30723072 // A should STILL have B in peer store — kept for channel_reestablish.
30733073 assert ! (
3074- ! node_a. list_peers( ) . iter( ) . any( |p| p. node_id == node_b_id && p. is_persisted) ,
3075- "node_b should not be persisted in node_a peer store after locally-initiated force-close"
3074+ node_a. list_peers( ) . iter( ) . any( |p| p. node_id == node_b_id && p. is_persisted) ,
3075+ "node_b should remain persisted in node_a peer store after locally-initiated force-close"
30763076 ) ;
30773077
30783078 node_a. stop ( ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments