Skip to content

Commit f3738d7

Browse files
authored
Merge pull request lightningdevkit#100 from tankyleo/26-01-ann-addr
2 parents bdc7b94 + 55ce9cd commit f3738d7

3 files changed

Lines changed: 54 additions & 19 deletions

File tree

ldk-server/ldk-server/ldk-server-config.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Lightning node settings
22
[node]
33
network = "regtest" # Bitcoin network to use
4-
listening_address = "localhost:3001" # Lightning node listening address
4+
listening_addresses = ["localhost:3001"] # Lightning node listening addresses
5+
announcement_addresses = ["54.3.7.81:3001"] # Lightning node announcement addresses
56
rest_service_address = "127.0.0.1:3002" # LDK Server REST address
67
api_key = "your-secret-api-key" # API key for authenticating REST requests
78

@@ -18,7 +19,7 @@ file_path = "/tmp/ldk-server/ldk-server.log" # Log file path
1819
#key_path = "/path/to/tls.key" # Path to TLS private key, by default uses dir_path/tls.key
1920
hosts = ["example.com"] # Allowed hosts for TLS, will always include "localhost" and "127.0.0.1"
2021

21-
# Must set either bitcoind or esplora settings, but not both
22+
# Must set one of bitcoind, electrum, or esplora
2223

2324
# Bitcoin Core settings
2425
[bitcoind]

ldk-server/ldk-server/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ fn main() {
101101
};
102102

103103
ldk_node_config.storage_dir_path = config_file.storage_dir_path.clone();
104-
ldk_node_config.listening_addresses = Some(vec![config_file.listening_addr]);
104+
ldk_node_config.listening_addresses = config_file.listening_addrs;
105+
ldk_node_config.announcement_addresses = config_file.announcement_addrs;
105106
ldk_node_config.network = config_file.network;
106107

107108
let mut builder = Builder::from_config(ldk_node_config);

ldk-server/ldk-server/src/util/config.rs

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use serde::{Deserialize, Serialize};
2222
/// Configuration for LDK Server.
2323
#[derive(Debug)]
2424
pub struct Config {
25-
pub listening_addr: SocketAddress,
25+
pub listening_addrs: Option<Vec<SocketAddress>>,
26+
pub announcement_addrs: Option<Vec<SocketAddress>>,
2627
pub alias: Option<NodeAlias>,
2728
pub network: Network,
2829
pub api_key: String,
@@ -55,13 +56,40 @@ impl TryFrom<TomlConfig> for Config {
5556
type Error = io::Error;
5657

5758
fn try_from(toml_config: TomlConfig) -> io::Result<Self> {
58-
let listening_addr =
59-
SocketAddress::from_str(&toml_config.node.listening_address).map_err(|e| {
60-
io::Error::new(
61-
io::ErrorKind::InvalidInput,
62-
format!("Invalid listening address configured: {}", e),
63-
)
64-
})?;
59+
let listening_addrs = toml_config
60+
.node
61+
.listening_addresses
62+
.map(|addresses| {
63+
addresses
64+
.into_iter()
65+
.map(|addr| {
66+
SocketAddress::from_str(&addr).map_err(|e| {
67+
io::Error::new(
68+
io::ErrorKind::InvalidInput,
69+
format!("Invalid listening address configured: {}", e),
70+
)
71+
})
72+
})
73+
.collect()
74+
})
75+
.transpose()?;
76+
let announcement_addrs = toml_config
77+
.node
78+
.announcement_addresses
79+
.map(|addresses| {
80+
addresses
81+
.into_iter()
82+
.map(|addr| {
83+
SocketAddress::from_str(&addr).map_err(|e| {
84+
io::Error::new(
85+
io::ErrorKind::InvalidInput,
86+
format!("Invalid announcement address configured: {}", e),
87+
)
88+
})
89+
})
90+
.collect()
91+
})
92+
.transpose()?;
6593
let rest_service_addr = SocketAddr::from_str(&toml_config.node.rest_service_address)
6694
.map_err(|e| {
6795
io::Error::new(
@@ -161,7 +189,8 @@ impl TryFrom<TomlConfig> for Config {
161189
});
162190

163191
Ok(Config {
164-
listening_addr,
192+
listening_addrs,
193+
announcement_addrs,
165194
network: toml_config.node.network,
166195
alias,
167196
rest_service_addr,
@@ -195,7 +224,8 @@ pub struct TomlConfig {
195224
#[derive(Deserialize, Serialize)]
196225
struct NodeConfig {
197226
network: Network,
198-
listening_address: String,
227+
listening_addresses: Option<Vec<String>>,
228+
announcement_addresses: Option<Vec<String>>,
199229
rest_service_address: String,
200230
alias: Option<String>,
201231
api_key: String,
@@ -331,7 +361,8 @@ mod tests {
331361
let toml_config = r#"
332362
[node]
333363
network = "regtest"
334-
listening_address = "localhost:3001"
364+
listening_addresses = ["localhost:3001"]
365+
announcement_addresses = ["54.3.7.81:3001"]
335366
rest_service_address = "127.0.0.1:3002"
336367
alias = "LDK Server"
337368
api_key = "test_api_key"
@@ -375,7 +406,8 @@ mod tests {
375406

376407
let config = load_config(storage_path.join(config_file_name)).unwrap();
377408
let expected = Config {
378-
listening_addr: SocketAddress::from_str("localhost:3001").unwrap(),
409+
listening_addrs: Some(vec![SocketAddress::from_str("localhost:3001").unwrap()]),
410+
announcement_addrs: Some(vec![SocketAddress::from_str("54.3.7.81:3001").unwrap()]),
379411
alias: Some(NodeAlias(bytes)),
380412
network: Network::Regtest,
381413
rest_service_addr: SocketAddr::from_str("127.0.0.1:3002").unwrap(),
@@ -407,7 +439,9 @@ mod tests {
407439
log_file_path: Some("/var/log/ldk-server.log".to_string()),
408440
};
409441

410-
assert_eq!(config.listening_addr, expected.listening_addr);
442+
assert_eq!(config.listening_addrs, expected.listening_addrs);
443+
assert_eq!(config.announcement_addrs, expected.announcement_addrs);
444+
assert_eq!(config.alias, expected.alias);
411445
assert_eq!(config.network, expected.network);
412446
assert_eq!(config.rest_service_addr, expected.rest_service_addr);
413447
assert_eq!(config.api_key, expected.api_key);
@@ -424,13 +458,14 @@ mod tests {
424458
assert_eq!(config.rabbitmq_exchange_name, expected.rabbitmq_exchange_name);
425459
#[cfg(feature = "experimental-lsps2-support")]
426460
assert_eq!(config.lsps2_service_config.is_some(), expected.lsps2_service_config.is_some());
461+
assert_eq!(config.log_level, expected.log_level);
462+
assert_eq!(config.log_file_path, expected.log_file_path);
427463

428464
// Test case where only electrum is set
429465

430466
let toml_config = r#"
431467
[node]
432468
network = "regtest"
433-
listening_address = "localhost:3001"
434469
rest_service_address = "127.0.0.1:3002"
435470
alias = "LDK Server"
436471
api_key = "test_api_key"
@@ -475,7 +510,6 @@ mod tests {
475510
let toml_config = r#"
476511
[node]
477512
network = "regtest"
478-
listening_address = "localhost:3001"
479513
rest_service_address = "127.0.0.1:3002"
480514
alias = "LDK Server"
481515
api_key = "test_api_key"
@@ -524,7 +558,6 @@ mod tests {
524558
let toml_config = r#"
525559
[node]
526560
network = "regtest"
527-
listening_address = "localhost:3001"
528561
rest_service_address = "127.0.0.1:3002"
529562
alias = "LDK Server"
530563
api_key = "test_api_key"

0 commit comments

Comments
 (0)