From 1abbe2a2374e99704cea8599f5ac578d85425b92 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 2 Oct 2024 18:12:38 +0000 Subject: [PATCH 1/2] Add support for parsing the `dns_resolver` feature bit This feature bit is used to indicate that a node will make DNS queries on behalf of onion message senders, returning DNSSEC TXT proofs for the requested names. It is used to signal support for bLIP 32 resolution and can be used to find nodes from which we can try to resolve BIP 32 HRNs. --- lightning-types/src/features.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lightning-types/src/features.rs b/lightning-types/src/features.rs index 7ce87e0263e..f0d7f497f2b 100644 --- a/lightning-types/src/features.rs +++ b/lightning-types/src/features.rs @@ -68,6 +68,8 @@ //! (see the [`Keysend` feature assignment proposal](https://github.com/lightning/bolts/issues/605#issuecomment-606679798) for more information). //! - `Trampoline` - supports receiving and forwarding Trampoline payments //! (see the [`Trampoline` feature proposal](https://github.com/lightning/bolts/pull/836) for more information). +//! - `DnsResolver` - supports resolving DNS names to TXT DNSSEC proofs for BIP 353 payments +//! (see [bLIP 32](https://github.com/lightning/blips/blob/master/blip-0032.md) for more information). //! //! LDK knows about the following features, but does not support them: //! - `AnchorsNonzeroFeeHtlcTx` - the initial version of anchor outputs, which was later found to be @@ -177,6 +179,10 @@ mod sealed { ZeroConf | Keysend, // Byte 7 Trampoline, + // Byte 8 - 31 + ,,,,,,,,,,,,,,,,,,,,,,,, + // Byte 32 + DnsResolver, ] ); define_context!(ChannelContext, []); @@ -565,6 +571,17 @@ mod sealed { supports_trampoline_routing, requires_trampoline_routing ); + define_feature!( + 259, + DnsResolver, + [NodeContext], + "Feature flags for DNS resolving.", + set_dns_resolution_optional, + set_dns_resolution_required, + supports_dns_resolution, + requires_dns_resolution + ); + // Note: update the module-level docs when a new feature bit is added! #[cfg(any(test, feature = "_test_utils"))] From 457b634d09e53ecb9cdd1b3b14c62ba5c2b95201 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 2 Oct 2024 18:21:33 +0000 Subject: [PATCH 2/2] Allow a `DNSResolverMessageHandler` to set `dns_resolver` feature A `DNSResolverMessageHandler` which handles resolution requests should want the `NodeFeatures` included in the node's `node_announcement` to include `dns_resolver` to indicate to the world that it provides that service. Here we enable this by requesting extra feature flags from the `DNSResolverMessageHandler` in the features `OnionMessenger`, in turn, provides to `PeerManager` (which builds the `node_announcement`). --- lightning/src/onion_message/dns_resolution.rs | 9 +++++++++ lightning/src/onion_message/messenger.rs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lightning/src/onion_message/dns_resolution.rs b/lightning/src/onion_message/dns_resolution.rs index af133aa7ab4..bbf8caa4f71 100644 --- a/lightning/src/onion_message/dns_resolution.rs +++ b/lightning/src/onion_message/dns_resolution.rs @@ -34,6 +34,8 @@ use dnssec_prover::validation::verify_rr_stream; use dnssec_prover::rr::Name; +use lightning_types::features::NodeFeatures; + use crate::blinded_path::message::DNSResolverContext; use crate::io; #[cfg(feature = "dnssec")] @@ -67,6 +69,13 @@ pub trait DNSResolverMessageHandler { /// With this, we should be able to validate the DNS record we requested. fn handle_dnssec_proof(&self, message: DNSSECProof, context: DNSResolverContext); + /// Gets the node feature flags which this handler itself supports. Useful for setting the + /// `dns_resolver` flag if this handler supports returning [`DNSSECProof`] messages in response + /// to [`DNSSECQuery`] messages. + fn provided_node_features(&self) -> NodeFeatures { + NodeFeatures::empty() + } + /// Release any [`DNSResolverMessage`]s that need to be sent. fn release_pending_messages(&self) -> Vec<(DNSResolverMessage, MessageSendInstructions)> { vec![] diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index c531846912f..0d7243193a3 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -1778,7 +1778,7 @@ where fn provided_node_features(&self) -> NodeFeatures { let mut features = NodeFeatures::empty(); features.set_onion_messages_optional(); - features + features | self.dns_resolver_handler.provided_node_features() } fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures {