-
Notifications
You must be signed in to change notification settings - Fork 103
Add support for sending to human-readable names (BIP 353) #528
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
base: main
Are you sure you want to change the base?
Add support for sending to human-readable names (BIP 353) #528
Conversation
👋 Thanks for assigning @tnull as a reviewer! |
src/payment/bolt12.rs
Outdated
pub fn send_to_human_readable_name( | ||
&self, name: &str, amount_msat: u64, dns_resolvers: Vec<Destination>, | ||
) -> Result<PaymentId, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should probably expose this method to uniffi bindings?
Also, for dns_resolvers
maybe I should add a method in graph.rs which helps find all nodes that have a certain feature flag. This could make it simpler for the user to find all dns_resolver
nodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should probably expose this method to uniffi bindings?
Yes, you'll need to expose this method and all types it requires.
Also, for dns_resolvers maybe I should add a method in graph.rs which helps find all nodes that have a certain feature flag. This could make it simpler for the user to find all dns_resolver nodes.
Yes, populating the list of default Destination
s (see above) from the network graph is probably a good idea.
🔔 1st Reminder Hey @tnull! This PR has been waiting for your review. |
🔔 2nd Reminder Hey @tnull! This PR has been waiting for your review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this, and please excuse the delay here!
src/payment/store.rs
Outdated
/// [HumanReadableName]: crate::lightning::onion_message::dns_resolution::HumanReadableName | ||
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki | ||
/// [bLIP 32]: https://github.com/lightning/blips/blob/master/blip-0032.md | ||
HrnBolt12Offer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm not sure we want to add a separate PaymentKind
variant for this. Likely it should just be a Bolt12Offer
? In the upcoming 'payment metadata store' (see #425), we might then store the HRN as associated metadata though.
src/payment/bolt12.rs
Outdated
/// These nodes can be found by running a search through the `NetworkGraph` to find nodes that announce the | ||
/// `dns_resolver` feature flag. | ||
pub fn send_to_human_readable_name( | ||
&self, name: &str, amount_msat: u64, dns_resolvers: Vec<Destination>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think rather then replicating LDK's API and have the user give the Destination
for each send, in LDK Node we should probably allow users to set default DNS resolvers via the Builder
and/or the Config
. Here, we'd then error-out if the user didn't configure them upfront, and in the future we might be able to supply some default values.
src/payment/bolt12.rs
Outdated
pub fn send_to_human_readable_name( | ||
&self, name: &str, amount_msat: u64, dns_resolvers: Vec<Destination>, | ||
) -> Result<PaymentId, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should probably expose this method to uniffi bindings?
Yes, you'll need to expose this method and all types it requires.
Also, for dns_resolvers maybe I should add a method in graph.rs which helps find all nodes that have a certain feature flag. This could make it simpler for the user to find all dns_resolver nodes.
Yes, populating the list of default Destination
s (see above) from the network graph is probably a good idea.
src/uniffi_types.rs
Outdated
@@ -429,6 +430,18 @@ impl UniffiCustomTypeConverter for DateTime { | |||
} | |||
} | |||
|
|||
impl UniffiCustomTypeConverter for HumanReadableName { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's avoid introducing yet another UniffiCustomTypeConverter
for this, as we're actually currently working towards removing them for Bolt11Invoice
, Offer
, etc.
So we should just expose the HumanReadableName
as a Uniffi interface
, and if we find its API can't fully exposed, we'll need to create a type wrapper in uniffi_types.rs
for it that is switched based on the uniffi
flag (see #522 for reference).
Thank you for the feedback @tnull. I will address the comments and push the updated changes as soon as possible. |
Had a quick look at why some of the CI tests could be failing. I think the cln test is potentially failing because of the EDIT: Nevermind, I think this is the CLN issue: #527 The test seems to be flaky. |
Still actively working on this. Will push updates once I'm done (likely within the next week). |
Cool! Also don't hesitate to reach out (e.g. via LDK Discord -- I'm |
Thank you! |
…2 Offers BIP 353 introduced human-readable names which has been implemented in LDK (0.1). This commit adds support for sending to HRNs that resolve to Bolt12 Offers by using the LDK pay_for_offer_from_human_readable_name method in ChannelManager.
386f95f
to
2e75be9
Compare
Hi @tnull, thanks once again for the pointer you gave me in our discord chat. I just pushed some updates that allow the user to set a list of default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already looks pretty good, some comments
@@ -457,6 +462,17 @@ impl NodeBuilder { | |||
Ok(self) | |||
} | |||
|
|||
/// Sets the default dns_resolvers to be used when sending payments to HRNs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we link to the actual config field here (and below accordingly)?
@@ -167,6 +168,11 @@ pub struct Config { | |||
/// **Note:** If unset, default parameters will be used, and you will be able to override the | |||
/// parameters on a per-payment basis in the corresponding method calls. | |||
pub sending_parameters: Option<SendingParameters>, | |||
/// The dns_resolvers node_ids to be used for resolving Human-readable Names. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Let's avoid using non-local variable names like dns_resolvers
and node_ids
. Instead, just say "The DNS resolvers.."
/// The dns_resolvers node_ids to be used for resolving Human-readable Names. | ||
/// | ||
/// If set to `Some`, the values set will be used as dns_resolvers when sending to HRNs. | ||
/// **Note:** If set to `None`, payments to HRNs will fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Lets put this note in a dedicated paragraph.
/// | ||
/// If set to `Some`, the values set will be used as dns_resolvers when sending to HRNs. | ||
/// **Note:** If set to `None`, payments to HRNs will fail. | ||
pub dns_resolvers_node_ids: Option<Vec<PublicKey>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this an option rather than just having a Vec
? Is this so that in the future it can more easily be converted to an override value, once we discover default resolvers via the network graph?
Also, should we maybe only add this as part of an new HumanReadableNamesConfig
object, as we may be adding addtional configs in the future?
@@ -829,6 +829,11 @@ impl Node { | |||
self.config.node_alias | |||
} | |||
|
|||
/// Returns the list of dns_resolvers that will be used to resolve HRNs. | |||
pub fn dns_resolvers(&self) -> Option<Vec<PublicKey>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this extra accessor, users can just access the config.
}?; | ||
|
||
let destinations: Vec<Destination> = | ||
dns_resolvers.into_iter().map(|public_key| Destination::Node(public_key)).collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this directly in the match above, so we don't have to first clone
and then collect
again, which is an unnecessary allocation.
dns_resolvers.into_iter().map(|public_key| Destination::Node(public_key)).collect(); | ||
|
||
match self.channel_manager.pay_for_offer_from_human_readable_name( | ||
hrn.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this clone is necessary?
Some(amount_msat), | ||
None, | ||
PaymentDirection::Outbound, | ||
PaymentStatus::Pending, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't we add it as Failed
here?
) { | ||
Ok(()) => { | ||
log_info!(self.logger, "Initiated sending {} msats to {}", amount_msat, name); | ||
let kind = PaymentKind::Bolt12Offer { |
There was a problem hiding this comment.
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 we can't set any of these fields and they'd never really be updated. I wonder if we should intercept the InvoiceReceived
event to at least set some of these fields when we get access to the invoice for this payment?
Also opened lightningdevkit/rust-lightning#3779 as it would be helpful to have a dedicated event that emits the offer after it has been retrieved.
/// amount paid to be determined by the user. | ||
/// | ||
/// If `dns_resolvers_node_ids` in Config is set to `None`, this operation will fail. | ||
pub fn send_to_human_readable_name( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we can add a test case to check that this works somehow? Or would we need to wait for #436 to be able to create an end-to-end test?
This PR is a first step to add support for human-readable names as outlined in BIP 353 and implemented in LDK 0.1.
Refs #435
Changes
send_to_human_readable_name
function was added underBolt12Payment
.HrnBolt12Offer
PaymentKind variant was added.HrnParsingFailed
Error variant was added.I plan to follow up with a PR for #436 and another PR that will add HRN sending for on-chain payments.