Skip to content

Make node's address optional when opening channel#832

Open
benthecarman wants to merge 1 commit intolightningdevkit:mainfrom
benthecarman:opt-socket-addr
Open

Make node's address optional when opening channel#832
benthecarman wants to merge 1 commit intolightningdevkit:mainfrom
benthecarman:opt-socket-addr

Conversation

@benthecarman
Copy link
Contributor

@benthecarman benthecarman commented Mar 18, 2026

Previously we always required providing the node's address when opening a channel, this made the api annoying in some cases as you may already be connected to the peer but still need to provide the socket address.

Here we make it optional and will return a ConnectionFailed error when the socket address is not provided and we are not connected to the peer.

@benthecarman benthecarman requested a review from tnull March 18, 2026 19:01
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Mar 18, 2026

👋 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.

Copy link
Contributor

@tankyleo tankyleo left a comment

Choose a reason for hiding this comment

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

In the ldk-server PR, I mentioned potentially looking up the socket address from the gossip network graph. CLN does this.

Upon further thought, I'm thinking it might be best to let users implement that feature themselves, using the existing API calls on ldk-node.

Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

So, as mentioned in #490 and lightningdevkit/ldk-server#159 I'm not the biggest fan of this change as the API now indicates "address is optional", which it isn't. However, it seems everybody else disagrees with me, and I do not feel too strongly about the matter, so the changes are fine by me.

I would prefer to not test them via channel_full_cycle though, but rather add a dedicated/separate test case for it, if we deem them test-worhty.

pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
node_a: TestNode, node_b: TestNode, bitcoind: &BitcoindClient, electrsd: &E, allow_0conf: bool,
expect_anchor_channel: bool, force_close: bool,
expect_anchor_channel: bool, force_close: bool, connect_first: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, rather than adding yet another bool here, please create a dedicated test for it. Alternatively, it might better fit to add it to connection_restart_behavior or a similar test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gave it its own test

@tnull
Copy link
Collaborator

tnull commented Mar 19, 2026

In the ldk-server PR, I mentioned potentially looking up the socket address from the gossip network graph. CLN does this.

Upon further thought, I'm thinking it might be best to let users implement that feature themselves, using the existing API calls on ldk-node.

I guess we could? What was the reasoning for your change of mind?

@tankyleo
Copy link
Contributor

I guess we could? What was the reasoning for your change of mind?

I could totally see us implementing this behavior here in ldk-node, but here's my case against:

The principle of least surprise. If I were not familiar with LN gossip messages, I would find it surprising if I omitted the address, and had never connected to the peer before, and my node actually connected to the peer at channel open using a SocketAddress.

Also, how would we pick which address to prioritize among the addresses the node has specified in its node_announcement ? Perhaps the user has different preferences on whether onionV3 or IPV4 addresses should be prioritized.

I could see this happening at a higher level, but overall I find making a decision here at ldk-node to be too opinionated, and we should leave users the freedom to specify the exact behavior themselves using the existing API calls on ldk-node.

Previously we always required providing the node's address when opening
a channel, this made the api annoying in some cases as you may already
be connected to the peer but still need to provide the socket address.

Here we make it optional and will return a `ConnectionFailed` error when
the socket address is not provided and we are not connected to the peer.
@tnull
Copy link
Collaborator

tnull commented Mar 20, 2026

I guess we could? What was the reasoning for your change of mind?

I could totally see us implementing this behavior here in ldk-node, but here's my case against:

The principle of least surprise. If I were not familiar with LN gossip messages, I would find it surprising if I omitted the address, and had never connected to the peer before, and my node actually connected to the peer at channel open using a SocketAddress.

Also, how would we pick which address to prioritize among the addresses the node has specified in its node_announcement ? Perhaps the user has different preferences on whether onionV3 or IPV4 addresses should be prioritized.

I could see this happening at a higher level, but overall I find making a decision here at ldk-node to be too opinionated, and we should leave users the freedom to specify the exact behavior themselves using the existing API calls on ldk-node.

Makes sense, though arguably, if you're really after the principle of least surprise, you might want to leave the argument as required. :)

// If we are connected, grab the socket address as we need to make sure we have it persisted
// in our peer storage for future reconnections.
let peer =
self.peer_manager.peer_by_node_id(&node_id).ok_or(Error::ConnectionFailed)?;
Copy link
Collaborator

@tnull tnull Mar 20, 2026

Choose a reason for hiding this comment

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

Hmm, it's a bit weird that this looks directly at peer manager and doesn't incorporate any connections that are inflight in ConnectionManager (i.e., two channel opens in quick succession will still have the second one fail, potentially?).

Apart from that we probably want to introduce a dedicated error type that communicates why we failed to open a channel, and ConnectionFailed seems wrong here (as we didn't even attempt the connection in the first place, for example)

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