Skip to content

Add close-channel command to the CLI#65

Merged
jkczyz merged 5 commits into
lightningdevkit:mainfrom
moisesPompilio:issue-55
Jul 15, 2025
Merged

Add close-channel command to the CLI#65
jkczyz merged 5 commits into
lightningdevkit:mainfrom
moisesPompilio:issue-55

Conversation

@moisesPompilio

Copy link
Copy Markdown
Contributor

CLI: Add support for close-channel command

This adds a simple close-channel command to the CLI interface.
It reuses the existing close_channel method from ldk-server-client.

Closes #55.

@ldk-reviews-bot

ldk-reviews-bot commented Jun 18, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @jkczyz 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 jkczyz June 18, 2025 19:49

@jkczyz jkczyz 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.

Thanks for contributing!

Comment thread ldk-server-cli/src/main.rs Outdated
Comment on lines +214 to +215
force_close,
force_close_reason,

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.

Could you add a commit updating handle_close_channel_request to only allow force_close_reason when force_close is Some(true)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Change applied as requested, thanks!

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.

Hmmm... I was thinking we should do this on the server side. But I don't have a problem with doing it here (cc: @tnull any preference?). But we should probably error if force_close_reason is set but force_close isn't rather than just ignoring it. See Commands::Bolt11Receive handling for an example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense! I think the validation should be included in handle_close_channel_request on the ldk-server, since it would also cover requests made through the API and return proper errors there as well.

@tnull tnull Jun 23, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agree, we should probably also validate and error on the server side if the user supplies an arguement that doesn't fit the intended use case. Alternatively, we could split the channel closing API in a mutual close and force close variant, which would ensure we always just set the right fields for the right calls.

@tnull tnull requested a review from jkczyz June 20, 2025 08:59
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot

Copy link
Copy Markdown

🔔 2nd Reminder

Hey @jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@moisesPompilio

Copy link
Copy Markdown
Contributor Author

Split channel closing into separate endpoints for mutual and force close

  • Removed force_close and force_close_reason from CloseChannel.
  • Added a dedicated ForceCloseChannel endpoint.
  • This ensures proper argument validation and avoids misuse.

Comment thread ldk-server-cli/src/main.rs Outdated
#[arg(short, long)]
counterparty_node_id: String,
},

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.

nit: remove empty line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread ldk-server-protos/src/proto/api.proto Outdated
string user_channel_id = 1;
// The hex-encoded public key of the node to close a channel with.
string counterparty_node_id = 2;
// The reason for force-closing, can only be set while force closing a channel.

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.

"can only be set while force closing a channel" isn't needed anymore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread ldk-server/src/api/mod.rs Outdated
Comment on lines +23 to +36
pub fn parse_user_channel_id(id: &str) -> Result<UserChannelId, LdkServerError> {
Ok(UserChannelId(id.parse::<u128>().map_err(|_| {
LdkServerError::new(InvalidRequestError, "Invalid UserChannelId.".to_string())
})?))
}

pub fn parse_counterparty_node_id(id: &str) -> Result<PublicKey, LdkServerError> {
PublicKey::from_str(id).map_err(|e| {
LdkServerError::new(
InvalidRequestError,
format!("Invalid counterparty node ID, error: {}", e),
)
})
}

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.

Do these need to be pub? IMO, we should just leave these in close_channel.rs and not make a separate file for handle_force_close_channel_request. There's enough in common that it can go in close_channel.rs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved handle_force_close_channel_request and the shared parsing functions into close_channel.rs as suggested. Also removed the unnecessary pub modifiers.

Introduce ForceCloseChannelRequest and ForceCloseChannelResponse to the API,
implement the handle_force_close_channel_request function, and register the new
endpoint in the service router.

@enigbe enigbe 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.

I've reviewed and tested this. Looks good to me.

@jkczyz jkczyz merged commit 9702286 into lightningdevkit:main Jul 15, 2025
7 checks passed
rsafier pushed a commit to rsafier/ldk-server that referenced this pull request Apr 20, 2026
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.

command in CLI to close channel

5 participants