Skip to content

Commit d0a385e

Browse files
committed
Deduce ldk-server network via its API
Previously we had to specify the network in the config file. Now, as the network field is added to the get-node-info response we can deduce it ourselves.
1 parent 3a53974 commit d0a385e

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,12 @@ The required access details will depend on the node implementation.
104104
{
105105
"address": <ip:port or domain:port>,
106106
"api_key": <hex_encoded_api_key>,
107-
"cert": <path_to_tls_cert>,
108-
"network": <bitcoin|testnet|signet|regtest>
107+
"cert": <path_to_tls_cert>
109108
}
110109
```
111110
The `api_key` is the raw bytes of `~/.ldk-server/<network>/api_key` hex-encoded.
112111
Unlike other backends, ldk-server does not require an `id` field — the node's
113-
public key is fetched automatically on startup.
112+
public key and network are fetched automatically on startup.
114113

115114
Note: ldk-server channels are **unannounced by default**. Pass `--announce-channel`
116115
to `open-channel` (and set `announcement_addresses` in the ldk-server config) to
@@ -158,8 +157,7 @@ to send and receive payments when running with random activity.
158157
{
159158
"address": "localhost:3536",
160159
"api_key": "ldk_server_hex_encoded_api_key",
161-
"cert": "/path/tls.crt",
162-
"network": "signet"
160+
"cert": "/path/tls.crt"
163161
}
164162
]
165163
}

simln-lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ rand_distr = "0.4.3"
3333
rand_chacha = "0.3.1"
3434
reqwest = { version = "0.12", features = ["json", "multipart"] }
3535
tokio-util = { version = "0.7.13", features = ["rt"] }
36-
ldk-server-client = { git = "https://github.com/lightningdevkit/ldk-server", rev = "570ed527535da0ec1dae431fac3ce46e5e6a468f" }
36+
ldk-server-client = { git = "https://github.com/lightningdevkit/ldk-server", rev = "bf4d8bd5be283068a8988750827c858f294e8524" }
3737

3838
[dev-dependencies]
3939
ntest = "0.9.0"

simln-lib/src/ldk.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pub struct LdkConnection {
3434
pub api_key: String,
3535
#[serde(deserialize_with = "serializers::deserialize_path")]
3636
pub cert: String,
37-
pub network: Network,
3837
}
3938

4039
impl LdkNode {
@@ -62,6 +61,7 @@ impl LdkNode {
6261
let pubkey = PublicKey::from_str(&info.node_id)
6362
.map_err(|err| LightningError::GetInfoError(err.to_string()))?;
6463
let alias = info.node_alias.unwrap_or_default();
64+
let network = network_from_proto(info.network)?;
6565

6666
// ldk-server doesn't expose feature bits, but it always supports keysend
6767
// via `spontaneous_send`, so advertise it so sim-ln's keysend checks pass.
@@ -75,7 +75,7 @@ impl LdkNode {
7575
features,
7676
alias,
7777
},
78-
network: connection.network,
78+
network,
7979
})
8080
}
8181
}
@@ -247,6 +247,20 @@ impl LightningNode for LdkNode {
247247
}
248248
}
249249

250+
/// Convert the `types.Network` proto enum (encoded as i32) returned by
251+
/// ldk-server's GetNodeInfo into a `bitcoin::Network`.
252+
fn network_from_proto(value: i32) -> Result<Network, LightningError> {
253+
match value {
254+
0 => Ok(Network::Bitcoin),
255+
1 => Ok(Network::Testnet),
256+
3 => Ok(Network::Signet),
257+
4 => Ok(Network::Regtest),
258+
other => Err(LightningError::GetInfoError(format!(
259+
"ldk-server returned unsupported network value: {other}"
260+
))),
261+
}
262+
}
263+
250264
fn string_to_payment_hash(hash: &str) -> Result<PaymentHash, LightningError> {
251265
let bytes = hex::decode(hash).map_err(|_| LightningError::InvalidPaymentHash)?;
252266
let slice: [u8; 32] = bytes

0 commit comments

Comments
 (0)