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

Support paying directly to Human Readable Names using bLIP 32 #3283

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

TheBlueMatt
Copy link
Collaborator

Based on #3179 this fully implements BIP 353 sends using bLIP 32 DNS resolution with a wonderfully simple API:

        pub fn pay_for_offer_from_human_readable_name(
                &self, name: HumanReadableName, amount_msats: u64, payment_id: PaymentId,
                retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>,
                dns_resolvers: Vec<Destination>,
        ) -> Result<(), ()> {

Still needs a few trivial things piped out through to events (eg DNSSEC proofs as "proof of payment"), but its basically done!

Copy link

codecov bot commented Aug 30, 2024

Codecov Report

Attention: Patch coverage is 78.50340% with 158 lines in your changes missing coverage. Please review.

Project coverage is 89.75%. Comparing base (7e513f9) to head (d4691a1).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/onion_message/dns_resolution.rs 67.46% 42 Missing and 26 partials ⚠️
lightning-dns-resolver/src/lib.rs 90.33% 21 Missing and 5 partials ⚠️
lightning/src/ln/channelmanager.rs 79.81% 16 Missing and 6 partials ⚠️
lightning/src/ln/outbound_payment.rs 83.05% 9 Missing and 1 partial ⚠️
lightning/src/ln/peer_handler.rs 0.00% 6 Missing ⚠️
lightning/src/offers/invoice_request.rs 62.50% 6 Missing ⚠️
lightning/src/onion_message/functional_tests.rs 45.45% 6 Missing ⚠️
lightning/src/onion_message/packet.rs 33.33% 5 Missing and 1 partial ⚠️
lightning/src/onion_message/messenger.rs 84.61% 2 Missing and 2 partials ⚠️
lightning/src/ln/offers_tests.rs 0.00% 3 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3283      +/-   ##
==========================================
- Coverage   89.82%   89.75%   -0.08%     
==========================================
  Files         126      128       +2     
  Lines      103134   104018     +884     
  Branches   103134   104018     +884     
==========================================
+ Hits        92638    93358     +720     
- Misses       7776     7899     +123     
- Partials     2720     2761      +41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This creates the initial DNSSEC proof and query messages in a new
module in `onion_message`, as well as a new message handler to
handle them.

In the coming commits, a default implementation will be added which
verifies DNSSEC proofs which can be used to resolve BIP 353 URIs
without relying on anything outside of the lightning network.
This adds the requisite message parsing and handling code for the
new DNSSEC messages to `OnionMessenger`.
When we make a DNSSEC query with a reply path, we don't want to
allow the DNS resolver to attempt to respond to various nodes to
try to detect (through timining or other analysis) whether we were
the one who made the query. Thus, we need to include a nonce in the
context in our reply path, which we set up here by creating a new
context type for DNS resolutions.
BIP 353 `HumanReadableName`s are represented as `₿user@domain` and
can be resolved using DNS into a bitcoin: URI. In the next commit,
we will add such a resolver using onion messages to fetch records
from the DNS, which will rely on this new type to get name
information from outside LDK.
This adds a new utility struct, `OMNameResolver`, which implements
the core functionality required to resolve Human Readable Names,
namely generating `DNSSECQuery` onion messages, tracking the state
of requests, and ultimately receiving and verifying `DNSSECProof`
onion messages.

It tracks pending requests with a `PaymentId`, allowing for easy
integration into `ChannelManager` in a coming commit - mapping
received proofs to `PaymentId`s which we can then complete by
handing them `Offer`s to pay.

It does not, directly, implement `DNSResolverMessageHandler`, but
an implementation of `DNSResolverMessageHandler` becomes trivial
with `OMNameResolver` handling the inbound messages and creating
the messages to send.
When we resolve a Human Readable Name to a BOLT 12 `offer`, we may
end up resolving to a wildcard DNS name covering all possible
`user` parts. In that case, if we just blindly pay the `offer`, the
recipient would have no way to tell which `user` we paid.

Instead, BOLT 12 defines a field to include the HRN resolved in the
`invoice_request`, which we implement here.
In the next commit we'll want to use `create_blinded_path` to build
a blinded path with a `DNSResolverContext` rather than an
`OffersContext`. In order to do so, it needs to take a generic
`MessageContext` rather than an `OffersContext`, which we let it
here.
Now that we have the ability to resolve BIP 353 Human Readable
Names directly and have tracking for outbound payments waiting on
an offer resolution, we can implement full BIP 353 support in
`ChannelManager`.

Users will need one or more known nodes which offer DNS resolution
service over onion messages using bLIP 32, which they pass to
`ChannelManager::pay_for_offer_from_human_readable_name`, as well
as the `HumanReadableName` itself.

From there, `ChannelManager` asks the DNS resolver to provide a
DNSSEC proof, which it verifies, parses into an `Offer`, and then
pays.

For those who wish to support on-chain fallbacks, sadly, this will
not work, and they'll still have to use `OMNameResolver` directly
in order to use their existing bitcoin: URI parsing.
Now that `ChannelManager` supports using bLIP 32 to resolve BIP 353
Human Readable Names we should encourage users to use that feature
by making the "default" (in various type aliases) to use
`ChannelManager` as the `DNSResolverMessageHandler`.
@TheBlueMatt TheBlueMatt force-pushed the 2024-07-human-readable-names-resolution branch from 2171114 to b42d6e0 Compare August 31, 2024 02:51
When a lightning node wishes to send payments to a BIP 353 human
readable name (using BOLT 12), it first has to resolve that name to
a DNS TXT record. bLIP 32 defines a way to do so over onion
messages, and this completes our implementation thereof by adding
the server side.

It operates by simply accepting new messages and spawning tokio
tasks to do DNS lookups using the `dnsse_prover` crate. It also
contains full end-to-end tests of the BIP 353 -> BOLT 12 -> payment
logic using the new server code to do the resolution.

Note that because we now have a workspace crate which sets the
"lightning/dnssec" feature in its `dev-dependencies`, a naive
`cargo test` will test the "dnssec" feature.
@TheBlueMatt TheBlueMatt force-pushed the 2024-07-human-readable-names-resolution branch from b42d6e0 to d4691a1 Compare August 31, 2024 17:09
@tnull tnull self-requested a review September 2, 2024 14:30
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.

1 participant