Skip to content

Commit fa49217

Browse files
committed
fixup! Allow setting default DNS resolvers for HRNs
1 parent 1a2341a commit fa49217

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

bindings/ldk_node.udl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dictionary Config {
1313
u64 probing_liquidity_limit_multiplier;
1414
AnchorChannelsConfig? anchor_channels_config;
1515
SendingParameters? sending_parameters;
16+
sequence<PublicKey>? dns_resolvers_node_ids;
1617
};
1718

1819
dictionary AnchorChannelsConfig {
@@ -94,6 +95,8 @@ interface Builder {
9495
[Throws=BuildError]
9596
void set_node_alias(string node_alias);
9697
[Throws=BuildError]
98+
void set_dns_resolvers(sequence<PublicKey> dns_resolvers_node_ids);
99+
[Throws=BuildError]
97100
Node build();
98101
[Throws=BuildError]
99102
Node build_with_fs_store();
@@ -303,6 +306,7 @@ enum NodeError {
303306
"LiquiditySourceUnavailable",
304307
"LiquidityFeeTooHigh",
305308
"HrnParsingFailed",
309+
"DnsResolversNotConfigured",
306310
};
307311

308312
dictionary NodeStatus {
@@ -338,6 +342,7 @@ enum BuildError {
338342
"WalletSetupFailed",
339343
"LoggerSetupFailed",
340344
"NetworkMismatch",
345+
"DnsResolversEmpty",
341346
};
342347

343348
[Trait]

src/builder.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ use lightning::routing::scoring::{
4747
ProbabilisticScorer, ProbabilisticScoringDecayParameters, ProbabilisticScoringFeeParameters,
4848
};
4949
use lightning::sign::EntropySource;
50-
use lightning::onion_message::messenger::Destination;
5150

5251
use lightning::util::persist::{
5352
read_channel_monitors, CHANNEL_MANAGER_PERSISTENCE_KEY,
@@ -175,6 +174,8 @@ pub enum BuildError {
175174
LoggerSetupFailed,
176175
/// The given network does not match the node's previously configured network.
177176
NetworkMismatch,
177+
/// The dns_resolvers list provided for HRN resolution is empty
178+
DnsResolversEmpty,
178179
}
179180

180181
impl fmt::Display for BuildError {
@@ -202,6 +203,9 @@ impl fmt::Display for BuildError {
202203
Self::NetworkMismatch => {
203204
write!(f, "Given network does not match the node's previously configured network.")
204205
},
206+
Self::DnsResolversEmpty => {
207+
write!(f, "The dns_resolvers list provided for HRN resolution is empty.")
208+
},
205209
}
206210
}
207211
}
@@ -461,8 +465,13 @@ impl NodeBuilder {
461465
}
462466

463467
/// Sets the default dns_resolvers to be used when sending payments to HRNs.
464-
pub fn set_dns_resolvers(&mut self, dns_resolvers: Vec<Destination>) -> Result<&mut Self, BuildError> {
465-
self.config.dns_resolvers = Some(dns_resolvers);
468+
pub fn set_dns_resolvers(
469+
&mut self, dns_resolvers_node_ids: Vec<PublicKey>,
470+
) -> Result<&mut Self, BuildError> {
471+
if dns_resolvers_node_ids.is_empty() {
472+
return Err(BuildError::DnsResolversEmpty);
473+
}
474+
self.config.dns_resolvers_node_ids = Some(dns_resolvers_node_ids);
466475
Ok(self)
467476
}
468477

@@ -848,8 +857,8 @@ impl ArcedNodeBuilder {
848857
}
849858

850859
/// Sets the default dns_resolvers to be used when sending payments to HRNs.
851-
pub fn set_dns_resolvers(&self, dns_resolvers: Vec<Destination>) -> Result<(), BuildError> {
852-
self.inner.write().unwrap().set_dns_resolvers(dns_resolvers).map(|_| ());
860+
pub fn set_dns_resolvers(&self, dns_resolvers_node_ids: Vec<PublicKey>) -> Result<(), BuildError> {
861+
self.inner.write().unwrap().set_dns_resolvers(dns_resolvers_node_ids).map(|_| ())
853862
}
854863

855864
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options

src/config.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::logger::LogLevel;
1111
use crate::payment::SendingParameters;
1212

1313
use lightning::ln::msgs::SocketAddress;
14-
use lightning::onion_message::messenger::Destination;
1514
use lightning::routing::gossip::NodeAlias;
1615
use lightning::util::config::ChannelConfig as LdkChannelConfig;
1716
use lightning::util::config::MaxDustHTLCExposure as LdkMaxDustHTLCExposure;
@@ -105,7 +104,7 @@ pub const WALLET_KEYS_SEED_LEN: usize = 64;
105104
/// | `anchor_channels_config` | Some(..) |
106105
/// | `sending_parameters` | None |
107106
/// | `dns_resolvers` | None |
108-
///
107+
///
109108
/// See [`AnchorChannelsConfig`] and [`SendingParameters`] for more information regarding their
110109
/// respective default values.
111110
///
@@ -169,11 +168,11 @@ pub struct Config {
169168
/// **Note:** If unset, default parameters will be used, and you will be able to override the
170169
/// parameters on a per-payment basis in the corresponding method calls.
171170
pub sending_parameters: Option<SendingParameters>,
172-
/// The dns_resolver nodes (Destinations) to be used for resolving Human-readable Names.
173-
///
171+
/// The dns_resolver node_ids to be used for resolving Human-readable Names.
172+
///
174173
/// If set to `Some`, the values set will be used as dns_resolvers when sending to HRNs.
175174
/// **Note:** If set to `None`, payments to HRNs will fail.
176-
pub dns_resolvers: Option<Vec<Destination>>,
175+
pub dns_resolvers_node_ids: Option<Vec<PublicKey>>,
177176
}
178177

179178
impl Default for Config {
@@ -188,7 +187,7 @@ impl Default for Config {
188187
anchor_channels_config: Some(AnchorChannelsConfig::default()),
189188
sending_parameters: None,
190189
node_alias: None,
191-
dns_resolvers: None,
190+
dns_resolvers_node_ids: None,
192191
}
193192
}
194193
}

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,11 @@ impl Node {
829829
self.config.node_alias
830830
}
831831

832+
/// Returns the list of dns_resolvers that will be used to resolve HRNs.
833+
pub fn dns_resolvers(&self) -> Option<Vec<PublicKey>> {
834+
self.config.dns_resolvers_node_ids.clone()
835+
}
836+
832837
/// Returns a payment handler allowing to create and pay [BOLT 11] invoices.
833838
///
834839
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md

0 commit comments

Comments
 (0)