Skip to content

fix(peer_store): upsert peer address when re-adding known peer - #1175

Open
vincenzopalazzo wants to merge 1 commit into
lightningdevkit:mainfrom
vincenzopalazzo:fix/peer-store-upsert-address
Open

vincenzopalazzo wants to merge 1 commit into
lightningdevkit:mainfrom
vincenzopalazzo:fix/peer-store-upsert-address

Conversation

@vincenzopalazzo

@vincenzopalazzo vincenzopalazzo commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Supersedes #1002 and #1115. Addresses the peer-store side of #700; the
liquidity-source side is tracked in #1147.

Rebased onto the persist-first peer store path from #1234. The previous
PeerStore persist rewrite is dropped.

upsert_peer replaces a stored address through update_peers.
Node::connect and open_channel call it only when the peer was not
already connected, so an address we never dialed cannot overwrite a
working one. An already-connected peer keeps add_peer. The LSPS2
receive path stays add_peer.

@ldk-reviews-bot

ldk-reviews-bot commented Oct 16, 2026 •

Copy link
Copy Markdown

👋 Thanks for assigning @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-reviews-bot
ldk-reviews-bot requested a review from tnull October 16, 2026 21:19

@ajaysehwal ajaysehwal left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Potential bug: an unverified address can overwrite a working peer address

connect_peer_if_necessary returns Ok(()) without dialing when the peer is already connected, so the subsequent upsert_peer can persist an address we never connected to. For example, if a peer is connected at good:9735, calling node.connect(X, "typo:9735", true) succeeds and replaces the working address. After a restart, the reconnect loop uses the typo and fails to reconnect. The same issue applies to open_channel_inner.

Could we only upsert when we actually dialed the requested address? Comparing with PeerDetails::socket_address won't work because, for inbound peers, it's the ephemeral source address rather than the listening address. A test covering an already-connected peer with a different requested address would help prevent this regression.

Comment thread src/peer_store.rs Resolved
@tnull

tnull commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Please rebase this onto #1234.

Comment thread src/peer_store.rs Resolved
Node::connect(..., persist=true) and open_channel kept the first stored
address, so a later working address was never used for reconnect (lightningdevkit#700).

upsert_peer replaces the address through the persist-first update_peers
path from lightningdevkit#1234. connect and open_channel call it only when this call
dialed the requested address. An already-connected peer keeps add_peer,
so an unverified address cannot overwrite a working one.

The LSPS2 receive path stays add_peer (lightningdevkit#1147).

Co-authored-by: Bartok <259807879+Bartok9@users.noreply.github.com>
Assisted-by: goose (AI)
@vincenzopalazzo
vincenzopalazzo force-pushed the fix/peer-store-upsert-address branch from 1b28e63 to 358673c Compare November 19, 2026 09:58
@vincenzopalazzo

Copy link
Copy Markdown
Member Author

Sorry for delay, this should be ready for another pass!

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.

4 participants