Skip to content

Commit 3913fe5

Browse files
committed
fixup! Allow setting default DNS resolvers for HRNs
1 parent a71ce33 commit 3913fe5

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
@@ -45,7 +45,6 @@ use lightning::routing::scoring::{
4545
ProbabilisticScorer, ProbabilisticScoringDecayParameters, ProbabilisticScoringFeeParameters,
4646
};
4747
use lightning::sign::EntropySource;
48-
use lightning::onion_message::messenger::Destination;
4948

5049
use lightning::util::persist::{
5150
read_channel_monitors, CHANNEL_MANAGER_PERSISTENCE_KEY,
@@ -173,6 +172,8 @@ pub enum BuildError {
173172
LoggerSetupFailed,
174173
/// The given network does not match the node's previously configured network.
175174
NetworkMismatch,
175+
/// The dns_resolvers list provided for HRN resolution is empty
176+
DnsResolversEmpty,
176177
}
177178

178179
impl fmt::Display for BuildError {
@@ -200,6 +201,9 @@ impl fmt::Display for BuildError {
200201
Self::NetworkMismatch => {
201202
write!(f, "Given network does not match the node's previously configured network.")
202203
},
204+
Self::DnsResolversEmpty => {
205+
write!(f, "The dns_resolvers list provided for HRN resolution is empty.")
206+
},
203207
}
204208
}
205209
}
@@ -459,8 +463,13 @@ impl NodeBuilder {
459463
}
460464

461465
/// Sets the default dns_resolvers to be used when sending payments to HRNs.
462-
pub fn set_dns_resolvers(&mut self, dns_resolvers: Vec<Destination>) -> Result<&mut Self, BuildError> {
463-
self.config.dns_resolvers = Some(dns_resolvers);
466+
pub fn set_dns_resolvers(
467+
&mut self, dns_resolvers_node_ids: Vec<PublicKey>,
468+
) -> Result<&mut Self, BuildError> {
469+
if dns_resolvers_node_ids.is_empty() {
470+
return Err(BuildError::DnsResolversEmpty);
471+
}
472+
self.config.dns_resolvers_node_ids = Some(dns_resolvers_node_ids);
464473
Ok(self)
465474
}
466475

@@ -846,8 +855,8 @@ impl ArcedNodeBuilder {
846855
}
847856

848857
/// Sets the default dns_resolvers to be used when sending payments to HRNs.
849-
pub fn set_dns_resolvers(&self, dns_resolvers: Vec<Destination>) -> Result<(), BuildError> {
850-
self.inner.write().unwrap().set_dns_resolvers(dns_resolvers).map(|_| ());
858+
pub fn set_dns_resolvers(&self, dns_resolvers_node_ids: Vec<PublicKey>) -> Result<(), BuildError> {
859+
self.inner.write().unwrap().set_dns_resolvers(dns_resolvers_node_ids).map(|_| ())
851860
}
852861

853862
/// 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)