Skip to content

Commit c69b95f

Browse files
committed
fixup! Allow setting default DNS resolvers for HRNs
1 parent 0a9379a commit c69b95f

File tree

3 files changed

+21
-30
lines changed

3 files changed

+21
-30
lines changed

bindings/ldk_node.udl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dictionary Config {
1313
u64 probing_liquidity_limit_multiplier;
1414
AnchorChannelsConfig? anchor_channels_config;
1515
SendingParameters? sending_parameters;
16-
HumanReadableNamesConfig hrn_config;
16+
HumanReadableNamesConfig? hrn_config;
1717
};
1818

1919
dictionary HumanReadableNamesConfig {
@@ -98,7 +98,6 @@ interface Builder {
9898
void set_announcement_addresses(sequence<SocketAddress> announcement_addresses);
9999
[Throws=BuildError]
100100
void set_node_alias(string node_alias);
101-
void set_hrn_config(HumanReadableNamesConfig hrn_config);
102101
[Throws=BuildError]
103102
Node build();
104103
[Throws=BuildError]
@@ -318,7 +317,7 @@ enum NodeError {
318317
"LiquiditySourceUnavailable",
319318
"LiquidityFeeTooHigh",
320319
"HrnParsingFailed",
321-
"DnsResolversNotConfigured",
320+
"DnsResolversUnavailable",
322321
};
323322

324323
dictionary NodeStatus {
@@ -354,7 +353,7 @@ enum BuildError {
354353
"WalletSetupFailed",
355354
"LoggerSetupFailed",
356355
"NetworkMismatch",
357-
"DnsResolversEmpty",
356+
"DnsResolversUnavailable",
358357
};
359358

360359
[Trait]

src/builder.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
use crate::chain::{ChainSource, DEFAULT_ESPLORA_SERVER_URL};
99
use crate::config::{
1010
default_user_config, may_announce_channel, AnnounceError, Config, ElectrumSyncConfig,
11-
EsploraSyncConfig, HumanReadableNamesConfig, DEFAULT_LOG_FILENAME, DEFAULT_LOG_LEVEL,
12-
WALLET_KEYS_SEED_LEN,
11+
EsploraSyncConfig, DEFAULT_LOG_FILENAME, DEFAULT_LOG_LEVEL, WALLET_KEYS_SEED_LEN,
1312
};
1413

1514
use crate::connection::ConnectionManager;
@@ -175,8 +174,10 @@ pub enum BuildError {
175174
LoggerSetupFailed,
176175
/// The given network does not match the node's previously configured network.
177176
NetworkMismatch,
178-
/// The dns_resolvers list provided for HRN resolution is empty
179-
DnsResolversEmpty,
177+
/// The [`dns_resolvers_node_ids`] provided for HRN resolution is empty.
178+
///
179+
/// [`dns_resolvers_node_ids`]: crate::config::HumanReadableNamesConfig::dns_resolvers_node_ids
180+
DnsResolversUnavailable,
180181
}
181182

182183
impl fmt::Display for BuildError {
@@ -204,7 +205,7 @@ impl fmt::Display for BuildError {
204205
Self::NetworkMismatch => {
205206
write!(f, "Given network does not match the node's previously configured network.")
206207
},
207-
Self::DnsResolversEmpty => {
208+
Self::DnsResolversUnavailable => {
208209
write!(f, "The dns_resolvers list provided for HRN resolution is empty.")
209210
},
210211
}
@@ -465,12 +466,6 @@ impl NodeBuilder {
465466
Ok(self)
466467
}
467468

468-
/// Sets the default [`Config::hrn_config`] to be used when sending payments to HRNs.
469-
pub fn set_hrn_config(&mut self, hrn_config: HumanReadableNamesConfig) -> &mut Self {
470-
self.config.hrn_config = hrn_config;
471-
self
472-
}
473-
474469
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options
475470
/// previously configured.
476471
pub fn build(&self) -> Result<Node, BuildError> {
@@ -852,11 +847,6 @@ impl ArcedNodeBuilder {
852847
self.inner.write().unwrap().set_node_alias(node_alias).map(|_| ())
853848
}
854849

855-
/// Sets the default [`Config::hrn_config`] to be used when sending payments to HRNs.
856-
pub fn set_hrn_config(&self, hrn_config: HumanReadableNamesConfig) {
857-
self.inner.write().unwrap().set_hrn_config(hrn_config);
858-
}
859-
860850
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options
861851
/// previously configured.
862852
pub fn build(&self) -> Result<Arc<Node>, BuildError> {
@@ -1509,6 +1499,12 @@ fn build_with_store_internal(
15091499
},
15101500
};
15111501

1502+
if let Some(hrn_config) = &config.hrn_config {
1503+
if hrn_config.dns_resolvers_node_ids.is_empty() {
1504+
return Err(BuildError::DnsResolversUnavailable);
1505+
}
1506+
};
1507+
15121508
let (stop_sender, _) = tokio::sync::watch::channel(());
15131509
let (event_handling_stopped_sender, _) = tokio::sync::watch::channel(());
15141510

src/config.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub const WALLET_KEYS_SEED_LEN: usize = 64;
103103
/// | `log_level` | Debug |
104104
/// | `anchor_channels_config` | Some(..) |
105105
/// | `sending_parameters` | None |
106-
/// | `dns_resolvers` | None |
106+
/// | `hrn_config` | None |
107107
///
108108
/// See [`AnchorChannelsConfig`] and [`SendingParameters`] for more information regarding their
109109
/// respective default values.
@@ -168,8 +168,10 @@ pub struct Config {
168168
/// **Note:** If unset, default parameters will be used, and you will be able to override the
169169
/// parameters on a per-payment basis in the corresponding method calls.
170170
pub sending_parameters: Option<SendingParameters>,
171-
/// Configuration Options for Human-readable Names.
172-
pub hrn_config: HumanReadableNamesConfig,
171+
/// Configuration options for Human-Readable Names ([BIP 353]).
172+
///
173+
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
174+
pub hrn_config: Option<HumanReadableNamesConfig>,
173175
}
174176

175177
impl Default for Config {
@@ -184,7 +186,7 @@ impl Default for Config {
184186
anchor_channels_config: Some(AnchorChannelsConfig::default()),
185187
sending_parameters: None,
186188
node_alias: None,
187-
hrn_config: HumanReadableNamesConfig::default(),
189+
hrn_config: None,
188190
}
189191
}
190192
}
@@ -200,12 +202,6 @@ pub struct HumanReadableNamesConfig {
200202
pub dns_resolvers_node_ids: Vec<PublicKey>,
201203
}
202204

203-
impl Default for HumanReadableNamesConfig {
204-
fn default() -> Self {
205-
Self { dns_resolvers_node_ids: vec![] }
206-
}
207-
}
208-
209205
/// Configuration options pertaining to 'Anchor' channels, i.e., channels for which the
210206
/// `option_anchors_zero_fee_htlc_tx` channel type is negotiated.
211207
///

0 commit comments

Comments
 (0)