Skip to content

Implement first set of Api's #5

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

Merged
merged 9 commits into from
Sep 25, 2024
Merged

Implement first set of Api's #5

merged 9 commits into from
Sep 25, 2024

Conversation

G8XSU
Copy link
Contributor

@G8XSU G8XSU commented Sep 5, 2024

Adds implementation for:

  • CloseChannel Api
  • Bolt12Send Api
  • Bolt12Receive Api
  • Bolt11Send Api
  • OpenChannel Api
  • BOLT11Receive Api
  • OnchainSend Api
  • OnchainReceive Api

Based on #2

@tnull
Copy link
Collaborator

tnull commented Sep 9, 2024

This needs a rebase now.

@G8XSU G8XSU changed the title [Draft Pr] Implement first set of Api's Implement first set of Api's Sep 10, 2024
@G8XSU G8XSU requested a review from tnull September 10, 2024 22:12
node: Arc<Node>, request: OnchainSendRequest,
) -> Result<OnchainSendResponse, ldk_node::NodeError> {
let address = Address::from_str(&request.address)
.map_err(|_| ldk_node::NodeError::InvalidAddress)?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we import NodeError to avoid the prefix?

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 kept it to make it explicit when there are other error types floating around, specifically ldk-server specific.
But I dont mind it either way.

) -> Result<OnchainSendResponse, ldk_node::NodeError> {
let address = Address::from_str(&request.address)
.map_err(|_| ldk_node::NodeError::InvalidAddress)?
.require_network(node.config().network)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if it would be worth retrieving the Config once and then giving a &Config to the handler methods rather than always calling in? Would at least avoid cloning it every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not all api's need it, and there could be future such instances where a subset of api's need some field.
I think we shouldn't add it to common handler for now.


pub(crate) fn handle_onchain_send_request(
node: Arc<Node>, request: OnchainSendRequest,
) -> Result<OnchainSendResponse, ldk_node::NodeError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be fine for the intial step, but we might need to introduce a separate error type that wraps the NodeError, i.e., will be a superset?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah currently it is only for initial step, will probably spend more time on error handling when we have it in api interface.

request.announce_channel,
)?;
let response =
OpenChannelResponse { user_channel_id: user_channel_id.0.to_be_bytes().to_vec() };
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if it would be worth down the line defining some kind of de/ser traits to make sure the encoding from these types into their respective field types is always consistent and we can't accidentally, e.g., encode as little-endian in some places?

pub(crate) fn handle_close_channel_request(
node: Arc<Node>, request: CloseChannelRequest,
) -> Result<CloseChannelResponse, ldk_node::NodeError> {
//TODO: Should this be string?
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO, since PaymentId is its dedicated proto type, UserChannelId/ChannelId, etc. should probably also follow the same pattern?

Copy link
Contributor Author

@G8XSU G8XSU Sep 11, 2024

Choose a reason for hiding this comment

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

@tnull @jkczyz
The main problem is user interaction with these byte identifiers, for which I could use some ideas. Essentially, IDs such as ChannelId, UserChannelId, and PaymentId are not human-readable in byte form and cannot be easily input or output as bytes.

Using bytes is fine for programmatic access, but for CLI or while interacting with a lightning node through a UI, this isn't really feasible. We have a similar problem for the logs of these IDs as well. (See: lightningdevkit/rust-lightning#3306)

In my opinion, we need a standardized way of interacting with these in a human-friendly manner, not just for debug logs. For this, I was considering whether we can use a hex representation string in the interface. This could be just for the CLI/UI or as part of the main API interface.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Mhh, I don't have a strong opinion, but I do think it should be uniform, at least across all *Id types.

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 thought more about this,
I don't think adding separate types for *Id helps from API perspective. It just introduces further nesting of types.
It might make sense in ldk-node api to introduce special types where you can have type checking but not in an api.

{
payment_id :PaymentId{data:[..]},
user_channel_id: UserChannelId{data:[..]},
channel_id: ChannelId{data:[..]},
}
compared to:  
{
payment_id :[..],
user_channel_id: [..],
channel_id: [..],
}

Bolt11SendResponse { payment_id: Some(PaymentId { data: payment_id.0.to_vec() }) }
compared to 
Bolt11SendResponse { payment_id: payment_id.0.to_vec() }

So to make it uniform, I am thinking of removing PaymentId type itself.

Copy link
Collaborator

@tnull tnull Sep 25, 2024

Choose a reason for hiding this comment

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

So to make it uniform, I am thinking of removing PaymentId type itself.

Alright, fine by me as long as it's uniform and ~predictable by the user/dev so they don't have to look up every single detail in the docs when using the API. And, at this stage, we could still easily change anything if we find a reason why we need separate types in the future.

Feel free to add the commit dropping PaymentId here before we land this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes added a commit for it.
Squashed and rebased.

@G8XSU G8XSU requested a review from tnull September 16, 2024 20:12
@G8XSU
Copy link
Contributor Author

G8XSU commented Sep 16, 2024

@tnull Is there any additional feedback on this?

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.

@tnull Is there any additional feedback on this?

Not really, but we should probably come to a conclusion on #5 (comment) and #5 (comment) before we move on?

Besides that, feel free to interleave and squash the fixups into their respective commits.

use crate::api::onchain_send::*;
use crate::api::open_channel::*;
use crate::api::bolt11_receive::handle_bolt11_receive_request;
use crate::api::bolt11_receive::BOLT11_RECEIVE_PATH;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Could group the imports from each module, but doesn't matter too much.

@G8XSU
Copy link
Contributor Author

G8XSU commented Sep 25, 2024

Squashed.
Need to rebase.

@G8XSU G8XSU requested a review from tnull September 25, 2024 05:20
@G8XSU
Copy link
Contributor Author

G8XSU commented Sep 25, 2024

Squashed and rebased.

@tnull tnull merged commit 1d702ed into lightningdevkit:main Sep 25, 2024
@G8XSU G8XSU mentioned this pull request Oct 14, 2024
13 tasks
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.

3 participants