Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

chuksys
Copy link

@chuksys chuksys commented Apr 22, 2025

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

  1. A send_to_human_readable_name function was added under Bolt12Payment.
  2. A HrnBolt12Offer PaymentKind variant was added.
  3. A HrnParsingFailed Error variant was added.
  4. These new enum variants were added to the uniffi bindings.

I plan to follow up with a PR for #436 and another PR that will add HRN sending for on-chain payments.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Apr 22, 2025

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

@ldk-reviews-bot ldk-reviews-bot requested a review from jkczyz April 22, 2025 00:52
Comment on lines 272 to 293
pub fn send_to_human_readable_name(
&self, name: &str, amount_msat: u64, dns_resolvers: Vec<Destination>,
) -> Result<PaymentId, Error> {
Copy link
Author

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.

Copy link
Collaborator

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 Destinations (see above) from the network graph is probably a good idea.

@tnull tnull requested review from tnull and removed request for jkczyz April 22, 2025 17:06
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @tnull! 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

🔔 2nd Reminder

Hey @tnull! 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.

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.

Thanks for looking into this, and please excuse the delay here!

/// [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 {
Copy link
Collaborator

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.

/// 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>,
Copy link
Collaborator

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.

Comment on lines 272 to 293
pub fn send_to_human_readable_name(
&self, name: &str, amount_msat: u64, dns_resolvers: Vec<Destination>,
) -> Result<PaymentId, Error> {
Copy link
Collaborator

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 Destinations (see above) from the network graph is probably a good idea.

@@ -429,6 +430,18 @@ impl UniffiCustomTypeConverter for DateTime {
}
}

impl UniffiCustomTypeConverter for HumanReadableName {
Copy link
Collaborator

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

@chuksys
Copy link
Author

chuksys commented Apr 30, 2025

Thank you for the feedback @tnull. I will address the comments and push the updated changes as soon as possible.

@sangbida
Copy link

sangbida commented May 5, 2025

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 dnssec addition. The test env may need to be configured to support dnssec?

EDIT: Nevermind, I think this is the CLN issue: #527 The test seems to be flaky.

@chuksys
Copy link
Author

chuksys commented May 10, 2025

I will address the comments and push the updated changes as soon as possible.

Still actively working on this. Will push updates once I'm done (likely within the next week).

@tnull
Copy link
Collaborator

tnull commented May 12, 2025

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 _tnull there) if you have any questions and/or are blocked on a particular issue! Happy to help!

@chuksys
Copy link
Author

chuksys commented May 12, 2025

Also don't hesitate to reach out (e.g. via LDK Discord -- I'm _tnull there) if you have any questions and/or are blocked on a particular issue! Happy to help!

Thank you!

@chuksys chuksys force-pushed the send-to-human-readable-names branch from 386f95f to 2e75be9 Compare May 13, 2025 18:31
@chuksys
Copy link
Author

chuksys commented May 13, 2025

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 node_ids to use as the Destination for HRNs dns resolution. As advised, I would follow up with another PR later that would fully expose Destination from LDK to uniFFI bindings and allow using BlindedPaths as the Destination for HRNs dns resolution. I am yet to implement the method which allows the user to easily fetch dns_resolver nodes from the network_graph - I will work on that next and push when done or perhaps open a new PR for that. Thanks!

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.

Already looks pretty good, some comments

src/builder.rs Outdated
@@ -457,6 +462,17 @@ impl NodeBuilder {
Ok(self)
}

/// Sets the default dns_resolvers to be used when sending payments to HRNs.
Copy link
Collaborator

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)?

src/config.rs Outdated
@@ -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.
Copy link
Collaborator

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

src/config.rs Outdated
/// 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.
Copy link
Collaborator

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.

src/config.rs Outdated
///
/// 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>>,
Copy link
Collaborator

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?

Copy link
Author

Choose a reason for hiding this comment

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

Also, should we maybe only add this as part of an new HumanReadableNamesConfig object, as we may be adding addtional configs in the future?

I think this is a good idea. I'll work on this.

src/lib.rs Outdated
@@ -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>> {
Copy link
Collaborator

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();
Copy link
Collaborator

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.

/// 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(
Copy link
Collaborator

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?

Copy link
Author

Choose a reason for hiding this comment

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

If we can intercept the InvoiceReceived event or have an event that is emitted after the offer is retrieved, I think we can have at least a test case built around any of these events.

I think the end-to-end test would be the ideal, eventually.

@chuksys chuksys force-pushed the send-to-human-readable-names branch from 8bf2184 to 0a9379a Compare May 28, 2025 12:42
@chuksys chuksys requested a review from tnull May 29, 2025 08:49
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.

Did another ~high-level-ish round of review, just commenting a few things that stood out to me.

src/builder.rs Outdated
@@ -459,6 +465,12 @@ impl NodeBuilder {
Ok(self)
}

/// Sets the default [`Config::hrn_config`] to be used when sending payments to HRNs.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to add this setter, let's drop it. Note we're not adding them for all Config values.

src/builder.rs Outdated
@@ -174,6 +175,8 @@ pub enum BuildError {
LoggerSetupFailed,
/// The given network does not match the node's previously configured network.
NetworkMismatch,
/// The dns_resolvers list provided for HRN resolution is empty
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think dns_resolvers list is outdated now. Let's link to the particular field in HumanReadableNamesConfig.

src/config.rs Outdated
@@ -103,6 +103,7 @@ pub const WALLET_KEYS_SEED_LEN: usize = 64;
/// | `log_level` | Debug |
/// | `anchor_channels_config` | Some(..) |
/// | `sending_parameters` | None |
/// | `dns_resolvers` | None |
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is outdated now.

src/config.rs Outdated
@@ -167,6 +168,8 @@ 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>,
/// Configuration Options for Human-readable Names.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: No need to use full title case here.

Suggested change
/// Configuration Options for Human-readable Names.
/// Configuration options for Human-Readable Names (BIP 353).

Could also link to the BIP here and elsewhere.

src/config.rs Outdated
@@ -167,6 +168,8 @@ 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>,
/// Configuration Options for Human-readable Names.
pub hrn_config: HumanReadableNamesConfig,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make this optional, defaulting to None for now? I think rather than only failing at runtime, we should refuse to startup with DnsResolversUnavailable on misconfiguration, i.e., if the user would enable it but won't supply DNS resolvers.

src/error.rs Outdated
/// Parsing a Human-Readable Name has failed
HrnParsingFailed,
/// The given operation failed due to `dns-resolvers` not being configured in builder.
DnsResolversNotConfigured,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's rename this DnsResolversUnavailable to mirror what we do for LiquiditySource.

Err(e) => Err(format!("Error creating HRN {:?}", e)),
};

Self { inner: hrn.expect("Error creating HRN") }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please never panic/expect/unwrap in production code.

@chuksys chuksys requested a review from tnull May 30, 2025 20:05
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @tnull! 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.

src/config.rs Outdated
}
}
}

/// Configuration options for Human-readable Names
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's link to BIP353 here, too. Also, nit, let's stick with Human-Readable Names, i.e., consistent capitalization everywhere.

src/error.rs Outdated
write!(f, "Failed to parse a human-readable name.")
},
Self::DnsResolversUnavailable => {
write!(f, "The given operation failed due to `dns-resolvers` not being configured in builder.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
write!(f, "The given operation failed due to `dns-resolvers` not being configured in builder.")
write!(f, "The given operation failed due to DNS resolvers not being configured.")

@@ -404,7 +404,7 @@ pub enum PaymentKind {
/// The secret used by the payment.
secret: Option<PaymentSecret>,
/// The ID of the offer this payment is for.
offer_id: OfferId,
offer_id: Option<OfferId>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please describe when this field would be set / unset.

src/event.rs Outdated
@@ -1417,8 +1417,20 @@ where
);
}
},
LdkEvent::InvoiceReceived { .. } => {
debug_assert!(false, "We currently don't handle BOLT12 invoices manually, so this event should never be emitted.");
LdkEvent::InvoiceReceived { payment_id, invoice, context: _, responder: _ } => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we'd ever actually see this emitted (see the previous debug_assert here), if we don't set manually_handle_bolt12_invoices. And if we do, we really need to handle this even properly, not only to update our PaymentStore.


#[cfg(not(feature = "uniffi"))]
pub fn maybe_convert_hrn(hrn: HumanReadableName) -> LdkHumanReadableName {
hrn.clone()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This clone can be dropped.

destinations,
) {
Ok(()) => {
log_info!(self.logger, "Initiated sending {} msats to {:?}", amount_msat, hrn);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, let's print the hrn as ... ₿{}@{}", hrn.user(), hrn.doman() for now, but I think we should implement Display for this upstream. Opened an issue for it: lightningdevkit/rust-lightning#3823

src/event.rs Outdated
Comment on lines 1435 to 1437
let _ = self
.channel_manager
.send_payment_for_bolt12_invoice(&invoice, context.as_ref());
Copy link
Author

@chuksys chuksys Jun 6, 2025

Choose a reason for hiding this comment

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

I didn't handle the error here because I'm not sure if we want to return a ReplayEvent Error when we get a Bolt12PaymentError::UnexpectedInvoice or Bolt12PaymentError::DuplicateInvoice - Plus since the success or failure of the payment, triggers Event::PaymentSent or Event::PaymentFailed (which are already properly handled), I'm thinking this might be the way to go. Please let me know what you think.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, true, but we should at the very least log the error here I think.

@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @tnull! 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.

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.

This needs a rebase now that #542 landed.

@chuksys chuksys force-pushed the send-to-human-readable-names branch from 75833b4 to eed246c Compare June 11, 2025 12:10
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.

Seems there are still a few rebase issues.

Feel free to squash fixups. Btw, going forward it would be helpful to provide actual commit messages behind the fixup! prefix rather than just mirroring the feature commit's headline.

@@ -41,6 +43,18 @@ type Offer = Arc<crate::ffi::Offer>;
type Refund = lightning::offers::refund::Refund;
#[cfg(feature = "uniffi")]
type Refund = Arc<crate::ffi::Refund>;
type HumanReadableName = LdkHumanReadableName;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems to be missing a newline and #[cfg(not(feature = "uniffi"))] ?

type HumanReadableName = Arc<crate::uniffi_types::HumanReadableName>;

#[cfg(not(feature = "uniffi"))]
pub fn maybe_convert_hrn(hrn: HumanReadableName) -> LdkHumanReadableName {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please reuse the generalized maybe_* methods now moved to ffi/mod.rs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This file was renamed as part of #542, please don't reintroduce it here but rather make the required changes to ffi/types.rs.

@chuksys chuksys force-pushed the send-to-human-readable-names branch from eed246c to 23207bc Compare June 12, 2025 14:11
@chuksys
Copy link
Author

chuksys commented Jun 12, 2025

Seems there are still a few rebase issues.

Feel free to squash fixups. Btw, going forward it would be helpful to provide actual commit messages behind the fixup! prefix rather than just mirroring the feature commit's headline.

Thanks for the feedback. I've fixed the rebase issues. Going forward, I will ensure to provide commit messages for fixups.

@chuksys chuksys requested a review from tnull June 12, 2025 14:26
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @tnull! 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

🔔 2nd Reminder

Hey @tnull! 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.

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.

Excuse the delay here. I think this mostly looks good, however, I want to hold of landing this until lightningdevkit/rust-lightning#3779 has concluded, as it seems we're considering actually removing the HRN resolution part (and hence the APIs) from LDK' ChannelManager, in which case resolution would need to be handled here and we'd otherwise just use the BOLT12 flow if it resolves to an offer.

@@ -854,4 +871,4 @@ typedef string NodeAlias;
typedef string OrderId;

[Custom]
typedef string DateTime;
typedef string DateTime;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Not sure why this change here was included. Please revert.

src/event.rs Outdated
Comment on lines 1435 to 1437
let _ = self
.channel_manager
.send_payment_for_bolt12_invoice(&invoice, context.as_ref());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, true, but we should at the very least log the error here I think.

@chuksys chuksys force-pushed the send-to-human-readable-names branch from 23207bc to 9e7b889 Compare June 20, 2025 17:50
chuksys added 2 commits June 20, 2025 19:57
…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.
@chuksys chuksys force-pushed the send-to-human-readable-names branch from 9e7b889 to 6068bf5 Compare June 20, 2025 18:58
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