Skip to content

Commit 50d7854

Browse files
feat(server): default the REST service address
Default `rest_service_address` to `127.0.0.1:3536` when omitted from the server config. Closes: #160 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 18954b3 commit 50d7854

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

ldk-server/ldk-server-config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
network = "regtest" # Bitcoin network to use
44
listening_addresses = ["localhost:3001"] # Lightning node listening addresses
55
announcement_addresses = ["54.3.7.81:3001"] # Lightning node announcement addresses
6-
rest_service_address = "127.0.0.1:3002" # LDK Server REST address
6+
#rest_service_address = "127.0.0.1:3536" # LDK Server REST address (optional, defaults to 127.0.0.1:3536)
77
alias = "ldk_server" # Lightning node alias
88
#pathfinding_scores_source_url = "" # External Pathfinding Scores Source
99
#rgs_server_url = "https://rapidsync.lightningdevkit.org/snapshot/v2/" # Optional: RGS URL for rapid gossip sync

ldk-server/src/util/config.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use ldk_node::liquidity::LSPS2ServiceConfig;
2121
use log::LevelFilter;
2222
use serde::{Deserialize, Serialize};
2323

24+
const DEFAULT_REST_SERVICE_ADDRESS: &str = "127.0.0.1:3536";
25+
2426
#[cfg(not(test))]
2527
const DEFAULT_CONFIG_FILE: &str = "config.toml";
2628

@@ -211,7 +213,7 @@ impl ConfigBuilder {
211213

212214
let rest_service_addr = self
213215
.rest_service_address
214-
.ok_or_else(|| missing_field_err("rest_service_address"))?
216+
.unwrap_or_else(|| DEFAULT_REST_SERVICE_ADDRESS.to_string())
215217
.parse::<SocketAddr>()
216218
.map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?;
217219

@@ -1109,7 +1111,6 @@ mod tests {
11091111
validate_missing!("rpc_password", missing_field_msg("bitcoind_rpc_password"));
11101112
validate_missing!("rpc_user", missing_field_msg("bitcoind_rpc_user"));
11111113
validate_missing!("rpc_address", missing_field_msg("bitcoind_rpc_address"));
1112-
validate_missing!("rest_service_address =", missing_field_msg("rest_service_address"));
11131114
validate_missing!("network =", missing_field_msg("network"));
11141115
}
11151116

@@ -1196,7 +1197,6 @@ mod tests {
11961197
validate_missing!(bitcoind_rpc_user, missing_field_msg("bitcoind_rpc_user"));
11971198
validate_missing!(bitcoind_rpc_address, missing_field_msg("bitcoind_rpc_address"));
11981199
validate_missing!(node_network, missing_field_msg("network"));
1199-
validate_missing!(node_rest_service_address, missing_field_msg("rest_service_address"));
12001200
}
12011201

12021202
#[test]
@@ -1309,4 +1309,35 @@ mod tests {
13091309
let err = result.unwrap_err();
13101310
assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
13111311
}
1312+
1313+
#[test]
1314+
#[cfg(not(feature = "experimental-lsps2-support"))]
1315+
#[cfg(not(feature = "events-rabbitmq"))]
1316+
fn test_default_rest_service_address() {
1317+
let storage_path = std::env::temp_dir();
1318+
let config_file_name = "test_default_rest_service_address.toml";
1319+
1320+
// Config without rest_service_address
1321+
let toml_config = r#"
1322+
[node]
1323+
network = "regtest"
1324+
1325+
[bitcoind]
1326+
rpc_address = "127.0.0.1:8332"
1327+
rpc_user = "bitcoind-testuser"
1328+
rpc_password = "bitcoind-testpassword"
1329+
"#;
1330+
1331+
fs::write(storage_path.join(config_file_name), toml_config).unwrap();
1332+
1333+
let mut args_config = empty_args_config();
1334+
args_config.config_file =
1335+
Some(storage_path.join(config_file_name).to_string_lossy().to_string());
1336+
1337+
let config = load_config(&args_config).unwrap();
1338+
assert_eq!(
1339+
config.rest_service_addr,
1340+
SocketAddr::from_str(DEFAULT_REST_SERVICE_ADDRESS).unwrap()
1341+
);
1342+
}
13121343
}

0 commit comments

Comments
 (0)