Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ldk-server/ldk-server-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ rpc_address = "127.0.0.1:18444" # RPC endpoint
rpc_user = "polaruser" # RPC username
rpc_password = "polarpass" # RPC password

# Electrum settings
[electrum]
server_url = "ssl://electrum.blockstream.info:50002" # Electrum endpoint
# server_url = "tcp://electrum.blockstream.info:50001"

# Esplora settings
[esplora]
server_url = "https://mempool.space/api" # Esplora endpoint
Expand Down
3 changes: 3 additions & 0 deletions ldk-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ fn main() {
rpc_password,
);
},
ChainSource::Electrum { server_url } => {
builder.set_chain_source_electrum(server_url, None);
},
ChainSource::Esplora { server_url } => {
builder.set_chain_source_esplora(server_url, None);
},
Expand Down
70 changes: 63 additions & 7 deletions ldk-server/src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct Config {
#[derive(Debug)]
pub enum ChainSource {
Rpc { rpc_address: SocketAddr, rpc_user: String, rpc_password: String },
Electrum { server_url: String },
Esplora { server_url: String },
}

Expand All @@ -58,9 +59,12 @@ impl TryFrom<TomlConfig> for Config {
format!("Invalid rest service address configured: {}", e),
)
})?;
let chain_source = match (toml_config.esplora, toml_config.bitcoind) {
(Some(EsploraConfig { server_url }), None) => ChainSource::Esplora { server_url },
(None, Some(BitcoindConfig { rpc_address, rpc_user, rpc_password })) => {
let chain_source = match (toml_config.esplora, toml_config.electrum, toml_config.bitcoind) {
(Some(EsploraConfig { server_url }), None, None) => ChainSource::Esplora { server_url },
(None, Some(ElectrumConfig { server_url }), None) => {
ChainSource::Electrum { server_url }
},
(None, None, Some(BitcoindConfig { rpc_address, rpc_user, rpc_password })) => {
let rpc_address = SocketAddr::from_str(&rpc_address).map_err(|e| {
io::Error::new(
io::ErrorKind::InvalidInput,
Expand All @@ -69,16 +73,18 @@ impl TryFrom<TomlConfig> for Config {
})?;
ChainSource::Rpc { rpc_address, rpc_user, rpc_password }
},
(Some(_), Some(_)) => {
(None, None, None) => {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("Must set a single chain source, multiple were configured"),
format!(
"At least one chain source must be set, either esplora, electrum, or bitcoind"
),
))
},
(None, None) => {
_ => {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("At least one chain source must be set, either bitcoind or esplora"),
format!("Must set a single chain source, multiple were configured"),
))
},
};
Expand Down Expand Up @@ -161,6 +167,7 @@ pub struct TomlConfig {
node: NodeConfig,
storage: StorageConfig,
bitcoind: Option<BitcoindConfig>,
electrum: Option<ElectrumConfig>,
esplora: Option<EsploraConfig>,
rabbitmq: Option<RabbitmqConfig>,
liquidity: Option<LiquidityConfig>,
Expand Down Expand Up @@ -192,6 +199,11 @@ struct BitcoindConfig {
rpc_password: String,
}

#[derive(Deserialize, Serialize)]
struct ElectrumConfig {
server_url: String,
}

#[derive(Deserialize, Serialize)]
struct EsploraConfig {
server_url: String,
Expand Down Expand Up @@ -370,6 +382,50 @@ mod tests {
#[cfg(feature = "experimental-lsps2-support")]
assert_eq!(config.lsps2_service_config.is_some(), expected.lsps2_service_config.is_some());

// Test case where only electrum is set

let toml_config = r#"
[node]
network = "regtest"
listening_address = "localhost:3001"
rest_service_address = "127.0.0.1:3002"
alias = "LDK Server"

[storage.disk]
dir_path = "/tmp"

[log]
level = "Trace"
file = "/var/log/ldk-server.log"

[electrum]
server_url = "ssl://electrum.blockstream.info:50002"

[rabbitmq]
connection_string = "rabbitmq_connection_string"
exchange_name = "rabbitmq_exchange_name"

[liquidity.lsps2_service]
advertise_service = false
channel_opening_fee_ppm = 1000 # 0.1% fee
channel_over_provisioning_ppm = 500000 # 50% extra capacity
min_channel_opening_fee_msat = 10000000 # 10,000 satoshis
min_channel_lifetime = 4320 # ~30 days
max_client_to_self_delay = 1440 # ~10 days
min_payment_size_msat = 10000000 # 10,000 satoshis
max_payment_size_msat = 25000000000 # 0.25 BTC
client_trusts_lsp = true
"#;

fs::write(storage_path.join(config_file_name), toml_config).unwrap();
let config = load_config(storage_path.join(config_file_name)).unwrap();

let ChainSource::Electrum { server_url } = config.chain_source else {
panic!("unexpected chain source");
};

assert_eq!(server_url, "ssl://electrum.blockstream.info:50002");

// Test case where only bitcoind is set

let toml_config = r#"
Expand Down