Skip to content

Commit cad9b73

Browse files
committed
fix peer connection after force_to_close
1 parent bb7d170 commit cad9b73

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff 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(())

tests/integration_tests_rust.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)