Repository navigation
fix(peer_store): upsert peer address when re-adding known peer - #1175
vincenzopalazzo wants to merge 2 commits into
Conversation
|
👋 Thanks for assigning @tnull as a reviewer! |
There was a problem hiding this comment.
🤖 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.
|
Please rebase this onto #1234. |
1b28e63 to
358673c
Compare
|
Sorry for delay, this should be ready for another pass! |
tnull
left a comment
There was a problem hiding this comment.
Claude:
!already_connectedplusOk(())doesn't prove this call dialedaddress:connect_peer_if_necessaryalso succeeds after joining a pending attempt (e.g. the reconnect loop dialing the stored address) or after an inbound connection.ConnectionManagershould return whether its own
dial succeeded, and only then should we upsert.- A
connectthat joins a failing reconnect attempt never tries the new address, which is the #700 case. It should fall through to its own dial.- The new integration test also passes on
main. Needs one where the stored address actually changes: connect via the first listening address, restartnode_b, connect via the second.
|
Ok, I pushed the fix that was commented on by Claude and made a round of review with Neon; it should be fine for another round now. thanks |
f440eca to
8e3bc29
Compare
Replaces the stored address through the persist-first update_peers path from lightningdevkit#1234. No-ops when the peer is already stored at the same address. Co-authored-by: Bartok <259807879+Bartok9@users.noreply.github.com> Assisted-by: Cursor Grok (AI) Co-authored-by: Cursor <cursoragent@cursor.com>
connect_peer_if_necessary reports Dialed only for its own outbound dial. Joining another attempt or an inbound connection is NotDialed, so an unverified address cannot overwrite a working one. Pending attempts store their address. A connect that joins a failed attempt to the same address returns that error; to a different address it logs and retries, so a reconnect stuck on a stale address cannot swallow a new one (lightningdevkit#700). Assisted-by: Cursor Grok (AI) Co-authored-by: Cursor <cursoragent@cursor.com>
cc27889 to
98e0d6c
Compare
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.
upsert_peerreplaces a stored address throughupdate_peers.Node::connectandopen_channelcall it only when this call establishesa new outbound connection to the given address (
ConnectPeerResult::Dialed).Joining another attempt, or finding the peer already connected (including
an inbound connection), keeps
add_peer, so an address we did not dialcannot overwrite a working one.
A connect that joins a failed attempt to a different address logs that
error and retries its own address, so a reconnect stuck on a stale address
cannot swallow the new one (#700). Joining a failed attempt to the same
address returns that error, and only one outbound dial is in flight per peer.
The LSPS2 receive path stays
add_peer.Assisted-by: Cursor Grok (AI)