Skip to content

Comments

fix: upsert peer address on connect#53

Merged
ovitrif merged 1 commit intobase/v0.7.0-rc.18from
fix/peer-address-upsert
Feb 21, 2026
Merged

fix: upsert peer address on connect#53
ovitrif merged 1 commit intobase/v0.7.0-rc.18from
fix/peer-address-upsert

Conversation

@ben-kaufman
Copy link

@ben-kaufman ben-kaufman commented Feb 21, 2026

This PR:

  1. Fixes PeerStore::add_peer silently ignoring address updates for already-known peers, causing the reconnection loop to use stale IPs indefinitely after an LSP node migration
  2. Reorders Node::connect to persist the peer address before attempting the connection, so the updated address is saved even when the connection races with an in-flight reconnection attempt at the old address
  3. Bumps version to v0.7.0-rc.26 with regenerated bindings

When an LSP node's IP changes (e.g., LND4 moving from 34.65.186.40 to 34.65.153.174), nodes that previously connected would keep retrying the old cached address forever. The root cause was two-fold: add_peer returned early for known peers without checking the address, and connect only persisted after a successful connection — meaning a racing reconnection loop could prevent the new address from ever being saved.

See upstream issue #700.

QA Notes

Testing

  • cargo test --lib peer_store — runs the 3 unit tests (existing + 2 new: peer_address_updated_on_readd, peer_same_address_skips_persist)
  • cargo test peer_address_persisted_on_connect_failure — integration test validating persist-before-connect and upsert across restart (requires BITCOIND_EXE)
  • cargo clippy clean
  • Bindings regenerated and included

Integration

Release

Made with Cursor

PeerStore::add_peer previously returned early if a peer already existed,
silently discarding address updates. When an LSP node's IP changed, the
reconnection loop would indefinitely retry the stale cached address.

This commit:
1. Changes add_peer to upsert: if the peer exists but the address
   differs, update and re-persist it.
2. Reorders Node::connect to persist the peer *before* attempting the
   connection, so the new address is saved even if the connection
   races with an in-flight reconnection attempt at the old address.
3. Adds unit tests for the upsert logic and an integration test for
   persist-on-failed-connect.

See upstream issue lightningdevkit#700.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 👏🏻

}

#[test]
fn peer_address_updated_on_readd() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo in last word readd

@ovitrif ovitrif merged commit e7a08bf into base/v0.7.0-rc.18 Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants