Skip to content

Commit 4e0bd6d

Browse files
committed
Implement bLIP-32 resolver discovery via network graph
Adds logic to scan the network graph for nodes that support both DNS resolution and Onion Messaging. - Iterates through the network graph to find up to 5 candidate nodes. - Validates node features for DNS and Onion Message support. - Adds error handling and logging for missing BIP-353 requirements.
1 parent 8a4307d commit 4e0bd6d

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ enum NodeError {
366366
"AsyncPaymentServicesDisabled",
367367
"HrnParsingFailed",
368368
"HrnResolverNotConfigured",
369+
"NoDnsResolvers",
369370
};
370371

371372
dictionary NodeStatus {

src/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ pub enum Error {
133133
HrnParsingFailed,
134134
/// A HRN resolver was not configured.
135135
HrnResolverNotConfigured,
136+
/// No nodes in the network graph support both DNS resolution and onion messaging, which are required for bLIP-32.
137+
NoDnsResolvers,
136138
}
137139

138140
impl fmt::Display for Error {
@@ -218,6 +220,9 @@ impl fmt::Display for Error {
218220
Self::HrnResolverNotConfigured => {
219221
write!(f, "A HRN resolver was not configured.")
220222
},
223+
Self::NoDnsResolvers => {
224+
write!(f, "No nodes in the network graph support both DNS resolution and onion messaging, which are required for bLIP-32.")
225+
},
221226
}
222227
}
223228
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ impl Node {
980980
Arc::clone(&self.config),
981981
Arc::clone(&self.logger),
982982
Arc::clone(&self.hrn_resolver),
983+
Arc::clone(&self.network_graph),
983984
)
984985
}
985986

@@ -1001,6 +1002,7 @@ impl Node {
10011002
Arc::clone(&self.config),
10021003
Arc::clone(&self.logger),
10031004
Arc::clone(&self.hrn_resolver),
1005+
Arc::clone(&self.network_graph),
10041006
))
10051007
}
10061008

src/payment/unified.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::error::Error;
3434
use crate::ffi::maybe_wrap;
3535
use crate::logger::{log_error, LdkLogger, Logger};
3636
use crate::payment::{Bolt11Payment, Bolt12Payment, OnchainPayment};
37-
use crate::types::HRNResolver;
37+
use crate::types::{Graph, HRNResolver};
3838
use crate::Config;
3939

4040
type Uri<'a> = bip21::Uri<'a, NetworkChecked, Extras>;
@@ -69,15 +69,24 @@ pub struct UnifiedPayment {
6969
config: Arc<Config>,
7070
logger: Arc<Logger>,
7171
hrn_resolver: Arc<Option<Arc<HRNResolver>>>,
72+
network_graph: Arc<Graph>,
7273
}
7374

7475
impl UnifiedPayment {
7576
pub(crate) fn new(
7677
onchain_payment: Arc<OnchainPayment>, bolt11_invoice: Arc<Bolt11Payment>,
7778
bolt12_payment: Arc<Bolt12Payment>, config: Arc<Config>, logger: Arc<Logger>,
78-
hrn_resolver: Arc<Option<Arc<HRNResolver>>>,
79+
hrn_resolver: Arc<Option<Arc<HRNResolver>>>, network_graph: Arc<Graph>,
7980
) -> Self {
80-
Self { onchain_payment, bolt11_invoice, bolt12_payment, config, logger, hrn_resolver }
81+
Self {
82+
onchain_payment,
83+
bolt11_invoice,
84+
bolt12_payment,
85+
config,
86+
logger,
87+
hrn_resolver,
88+
network_graph,
89+
}
8190
}
8291

8392
/// Generates a URI with an on-chain address, [BOLT 11] invoice and [BOLT 12] offer.
@@ -165,6 +174,30 @@ impl UnifiedPayment {
165174
&self, uri_str: &str, amount_msat: Option<u64>,
166175
route_parameters: Option<RouteParametersConfig>, #[cfg(hrn_tests)] test_offer: &Offer,
167176
) -> Result<UnifiedPaymentResult, Error> {
177+
let dns_resolvers = {
178+
let mut resolvers = Vec::new();
179+
let network_graph = self.network_graph.read_only();
180+
181+
for (node_id, node) in network_graph.nodes().unordered_iter() {
182+
if let Some(info) = &node.announcement_info {
183+
let supports_dns = info.features().supports_dns_resolution();
184+
let supports_om = info.features().supports_onion_messages();
185+
if supports_dns && supports_om {
186+
resolvers.push(node_id.clone());
187+
}
188+
}
189+
if resolvers.len() > 5 {
190+
break;
191+
}
192+
}
193+
resolvers
194+
};
195+
196+
if dns_resolvers.is_empty() {
197+
log_error!(self.logger, "No nodes in the network graph support both DNS resolution and onion messaging, which are required for bLIP-32. Please ensure you have at least one such node in your network graph before making BIP-353 payments.");
198+
return Err(Error::NoDnsResolvers);
199+
}
200+
168201
let resolver = self.hrn_resolver.as_ref().clone().ok_or_else(|| {
169202
log_error!(self.logger, "No HRN resolver configured. Cannot resolve HRNs.");
170203
Error::HrnResolverNotConfigured

0 commit comments

Comments
 (0)