Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add close_channels_with_peer command to gateway liquidity API #5218

Merged
merged 2 commits into from
May 23, 2024

Conversation

tvolk131
Copy link
Contributor

@tvolk131 tvolk131 commented May 7, 2024

This will be an important command to have once we ship an LDK-powered gateway since the liquidity API will be the only way to manage channels

Only implementing for LND for now since LND and LDK support closing channels by funding TXID + output index, while CLN instead requires funding tx block height + transaction index + output index

Changed from closing by TXID + output index to closing all channels with a specific peer

@m1sterc001guy
Copy link
Contributor

Only implementing for LND for now since LND and LDK support closing channels by funding TXID + output index, while CLN instead requires funding tx block height + transaction index + output index

CLN supports closing a channel by peer id: https://docs.corelightning.org/reference/lightning-close

For LND/LDK, you could lookup the TXID + output index using something like ListChannels https://github.com/lightningnetwork/lnd/blob/3e36df42e590ef44c8f8f99afc5657024dc462c7/lnrpc/lightning.proto#L1595

Maybe it makes more sense to have the API accept a PublicKey as an indicate of the channel(s) to close?

@tvolk131
Copy link
Contributor Author

tvolk131 commented May 9, 2024

CLN supports closing a channel by peer id: https://docs.corelightning.org/reference/lightning-close

That works, but if there are multiple channels open with the same peer then CLN refuses to close any channels:

Failed to close channel: Error code -1: Peer has multiple channels: use channel_id or short_channel_id

What do you think about adding a CloseChannelsWithPeer command instead of CloseChannel and under the hood for LND CLN and LDK we list channels, filtering by peer ID, then close all matching channels?

@tvolk131 tvolk131 force-pushed the liquidity_api_close_channel branch 3 times, most recently from ef05669 to e0ab490 Compare May 11, 2024 16:20
@tvolk131 tvolk131 changed the title Add close_channel command to gateway liquidity API feat: add close_channels_with_peer command to gateway liquidity API May 11, 2024
@tvolk131 tvolk131 marked this pull request as ready for review May 11, 2024 16:34
@tvolk131 tvolk131 requested review from a team as code owners May 11, 2024 16:34

client
.lightning()
.close_channel(CloseChannelRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

We might eventually want a way to query the status of closed channels. This RPC returns a stream and (especially for LDK), the operator will probably want to know what the state of their channel close is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I talked with tnull and it sounds like ldk-node v0.3 will provide a much better API for tracking channel lifecycle. It sounds like v0.3 will be released very soon, so I'll probably wait for that and then put more thought into how we want to expose channel state tracking behavior.

@m1sterc001guy
Copy link
Contributor

Overall I think its good enough to merge, I would prefer to fix the String vs bytes issue though.

Perhaps we should start adding devimint tests that exercise these endpoints?

@tvolk131 tvolk131 force-pushed the liquidity_api_close_channel branch 2 times, most recently from 5bd19dd to 1880735 Compare May 15, 2024 21:38
@tvolk131
Copy link
Contributor Author

Perhaps we should start adding devimint tests that exercise these endpoints?

Agreed! First I'd like to remove connect-to-peer and merge the behavior into open-channel

elsirion
elsirion previously approved these changes May 16, 2024
Copy link
Contributor

@elsirion elsirion left a comment

Choose a reason for hiding this comment

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

Looks ok enough, feel free to merge. Seconding @m1sterc001guy's comments about testing.

.into_inner()
.channels;

for channel in &channels_with_peer {
Copy link
Contributor

Choose a reason for hiding this comment

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

A failure in this loop would be annoying since the first channels are already closed while later ones stay open. Seems like a potential source of bugs. I'd much prefer the "single channel closing" semantics eventually.

Copy link
Contributor

Choose a reason for hiding this comment

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

This function doesn't wait for the channel to close anyway, we'll eventually need a way to track that as well. Rather than failing and returning here (and above in the CLN implementation), I think emitting a warning and trying to close the next channel would be sufficient

let num_channels_closed = client()
.close_channels_with_peer(CloseChannelsWithPeerPayload { pubkey })
.await?;
println!("Closed {num_channels_closed} channel(s)");
Copy link
Contributor

Choose a reason for hiding this comment

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

Ick. Can we change this to return JSON with num_channels_closed as one of the fields? That way tests can parse it and we can use print_response here instead

Copy link
Contributor

@elsirion elsirion May 20, 2024

Choose a reason for hiding this comment

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

Totally missed that 😬

@@ -9,6 +9,7 @@ fn main() {
.build_server(true)
.build_client(true)
.protoc_arg("--experimental_allow_proto3_optional")
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
Copy link
Contributor Author

@tvolk131 tvolk131 May 20, 2024

Choose a reason for hiding this comment

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

Note for reviewer: We're adding this so we can encode CloseChannelsWithPeerResponse as JSON

@elsirion elsirion added this pull request to the merge queue May 23, 2024
Merged via the queue into fedimint:master with commit acedd1f May 23, 2024
21 checks passed
@tvolk131 tvolk131 deleted the liquidity_api_close_channel branch May 30, 2024 22:49
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.

None yet

3 participants