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.

Problem

PeerStore::add_peer returned early when the pubkey was already
stored, so Node::connect(node_id, new_address, persist = true) silently
kept the stale address for reconnection.

PeerStore::add_peer returned early when the pubkey was already stored,
so Node::connect(..., persist=true) with a new address silently kept
the stale address used for reconnection (see lightningdevkit#700).

Split add_peer into two methods sharing a persist-then-apply helper,
following the maintainer review on lightningdevkit#1002:

- upsert_peer updates the stored address on re-add. Used where the
  address is explicitly supplied: Node::connect with persist set,
  open_channel, and the LSPS2 payment path.
- add_peer_if_missing only stores unknown peers. Used for the
  gossip-derived address of inbound channel counterparties, which
  must not override an explicitly stored address.

In-memory state is only mutated after a successful write, matching
remove_peer. Following the review suggestion on lightningdevkit#1002, avoid cloning
the entire peer map: apply the update temporarily under the write lock
for serialization, restore it, persist, then apply it permanently.
Readers cannot observe the temporary value as they need the same lock.
Re-adding an unchanged peer is a no-op. remove_peer is switched to
the same pattern for consistency.

Addresses the peer-store side of lightningdevkit#700. The liquidity-source side
(NodeBuilder/Liquidity add_liquidity_source) is deliberately left
out here; it is tracked in lightningdevkit#1147.

Supersedes lightningdevkit#1002 and lightningdevkit#1115.

Co-authored-by: Bartok <259807879+Bartok9@users.noreply.github.com>
Assisted-by: goose (AI)
@ldk-reviews-bot

ldk-reviews-bot commented Oct 16, 2026 •

Copy link
Copy Markdown

I've assigned @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
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