Skip to content

Commit db92053

Browse files
committed
Add SpliceConfig to NodeConfig
Introduce SpliceConfig with two knobs (enabled, poll_interval) and thread it through NodeConfig and the daemon TOML loader. No behaviour change yet; the splice manager that consumes this config lands in a later commit. Defaults are enabled=true and poll_interval=30s. 30s balances wasted ticks against post-reopen responsiveness; tests will override to 1s. There is deliberately no fee or threshold knob: the live ldk-node estimate covers fees and ldk-node itself enforces the dust gate, so extra configuration would just be second-guessing the wallet. The TOML schema uses poll_interval_secs (u64) rather than a humantime string to avoid pulling in another dependency for one field. The [splice] section is optional; missing or partial sections fall back to SpliceConfig::default(), so existing configs keep loading. SpliceConfig lives in the lib (mdk::node) rather than the daemon crate because the splice manager itself will live in the lib too. The daemon imports it from there.
1 parent be6b5c3 commit db92053

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/daemon/config.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@ use std::io;
22
use std::net::SocketAddr;
33
use std::path::PathBuf;
44
use std::str::FromStr;
5+
use std::time::Duration;
56

67
use ldk_node::bitcoin::Network;
78
use ldk_node::lightning::ln::msgs::SocketAddress;
89
use ldk_node::lightning::routing::gossip::NodeAlias;
910
use log::LevelFilter;
1011
use serde::Deserialize;
1112

13+
use mdk::node::SpliceConfig;
14+
1215
#[derive(Deserialize)]
1316
struct TomlConfig {
1417
node: Option<NodeSection>,
1518
storage: Option<StorageSection>,
1619
log: Option<LogSection>,
20+
splice: Option<SpliceSection>,
1721
}
1822

1923
#[derive(Deserialize)]
@@ -43,6 +47,12 @@ struct LogSection {
4347
file: Option<String>,
4448
}
4549

50+
#[derive(Deserialize)]
51+
struct SpliceSection {
52+
enabled: Option<bool>,
53+
poll_interval_secs: Option<u64>,
54+
}
55+
4656
pub struct MdkConfig {
4757
pub network: Network,
4858
pub listening_addrs: Option<Vec<SocketAddress>>,
@@ -52,6 +62,7 @@ pub struct MdkConfig {
5262
pub storage_dir_path: Option<String>,
5363
pub log_level: LevelFilter,
5464
pub pathfinding_scores_source_url: Option<String>,
65+
pub splice: SpliceConfig,
5566
}
5667

5768
pub fn load_config(path: &str) -> io::Result<MdkConfig> {
@@ -109,6 +120,20 @@ pub fn load_config(path: &str) -> io::Result<MdkConfig> {
109120
None => LevelFilter::Debug,
110121
};
111122

123+
let splice = match toml.splice {
124+
Some(s) => {
125+
let defaults = SpliceConfig::default();
126+
SpliceConfig {
127+
enabled: s.enabled.unwrap_or(defaults.enabled),
128+
poll_interval: s
129+
.poll_interval_secs
130+
.map(Duration::from_secs)
131+
.unwrap_or(defaults.poll_interval),
132+
}
133+
}
134+
None => SpliceConfig::default(),
135+
};
136+
112137
Ok(MdkConfig {
113138
network,
114139
listening_addrs,
@@ -118,6 +143,7 @@ pub fn load_config(path: &str) -> io::Result<MdkConfig> {
118143
storage_dir_path,
119144
log_level,
120145
pathfinding_scores_source_url: node.pathfinding_scores_source_url,
146+
splice,
121147
})
122148
}
123149

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ fn main() {
131131
pathfinding_scores_source_url: config_file.pathfinding_scores_source_url,
132132
mnemonic: mnemonic_phrase,
133133
infra,
134+
splice: config_file.splice,
134135
};
135136

136137
// Separate HTTP client for daemon concerns (webhooks, expiry monitor).

src/mdk/node.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::HashMap;
22
use std::net::ToSocketAddrs;
33
use std::str::FromStr;
44
use std::sync::Arc;
5+
use std::time::Duration;
56

67
use ldk_node::bip39::Mnemonic;
78
use ldk_node::bitcoin::hashes::sha256;
@@ -26,6 +27,25 @@ pub struct NodeConfig {
2627
pub pathfinding_scores_source_url: Option<String>,
2728
pub mnemonic: String,
2829
pub infra: NetworkInfra,
30+
pub splice: SpliceConfig,
31+
}
32+
33+
/// Configuration for the auto-splice manager. The manager wakes up
34+
/// every `poll_interval`, reads the spendable on-chain balance, and
35+
/// splices it into an existing LSP channel when one is available.
36+
#[derive(Debug, Clone)]
37+
pub struct SpliceConfig {
38+
pub enabled: bool,
39+
pub poll_interval: Duration,
40+
}
41+
42+
impl Default for SpliceConfig {
43+
fn default() -> Self {
44+
Self {
45+
enabled: true,
46+
poll_interval: Duration::from_secs(30),
47+
}
48+
}
2949
}
3050

3151
pub fn build_node(

0 commit comments

Comments
 (0)