diff --git a/config.example.json b/config.example.json index 84738a7..00d7cce 100644 --- a/config.example.json +++ b/config.example.json @@ -22,6 +22,8 @@ "02abc123...@1.2.3.4:9735" ], "amount_msats": [1000, 10000, 100000, 1000000], - "timeout_sec": 60 + "timeout_sec": 60, + "probe_delay_sec": 1, + "peer_delay_sec": 2 } } diff --git a/prober_config.json.example b/prober_config.json.example index 55bd1bd..0105357 100644 --- a/prober_config.json.example +++ b/prober_config.json.example @@ -5,5 +5,7 @@ "037d8e050899fa0732fdd6fc1e0d5d8d685c2093932a7e10dc5e6fab8a34ed1c43" ], "probe_amount_msats": [1000, 10000000, 100000000, 500000000], - "probe_timeout_sec": 3 + "probe_timeout_sec": 3, + "probe_delay_sec": 1, + "peer_delay_sec": 2 } diff --git a/src/cli.rs b/src/cli.rs index 4711ec1..40ecb19 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -42,6 +42,8 @@ pub(crate) struct ProbingConfig { pub(crate) peers: Vec, pub(crate) amount_msats: Vec, pub(crate) timeout_sec: u64, + pub(crate) probe_delay_sec: u64, + pub(crate) peer_delay_sec: u64, } pub(crate) struct LdkUserInfo { diff --git a/src/config.rs b/src/config.rs index 3b0ff70..039a325 100644 --- a/src/config.rs +++ b/src/config.rs @@ -63,6 +63,10 @@ pub struct ProbingConfig { pub amount_msats: Vec, #[serde(default = "default_probe_timeout")] pub timeout_sec: u64, + #[serde(default = "default_probe_delay")] + pub probe_delay_sec: u64, + #[serde(default = "default_peer_delay")] + pub peer_delay_sec: u64, } // Default functions @@ -86,6 +90,14 @@ fn default_probe_timeout() -> u64 { 60 } +fn default_probe_delay() -> u64 { + 1 +} + +fn default_peer_delay() -> u64 { + 2 +} + impl Default for RapidGossipSyncConfig { fn default() -> Self { Self { enabled: true, url: None, interval_hours: 6 } @@ -177,6 +189,8 @@ impl NodeConfig { peers: p.peers, amount_msats: p.amount_msats, timeout_sec: p.timeout_sec, + probe_delay_sec: p.probe_delay_sec, + peer_delay_sec: p.peer_delay_sec, }); LdkUserInfo { bitcoind_rpc_username: self.bitcoind.rpc_username, @@ -225,7 +239,9 @@ pub fn print_config_help() { "interval_sec": 300, "peers": [], "amount_msats": [1000, 10000, 100000], - "timeout_sec": 60 + "timeout_sec": 60, + "probe_delay_sec": 1, + "peer_delay_sec": 2 }} }}"# ); diff --git a/src/main.rs b/src/main.rs index bd45c21..0ac6e77 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1317,16 +1317,20 @@ async fn start_ldk() { sorted_amounts.sort(); let probe_timeout = Duration::from_secs(probe_config.timeout_sec); + let probe_delay = Duration::from_secs(probe_config.probe_delay_sec); + let peer_delay = Duration::from_secs(probe_config.peer_delay_sec); // Log startup configuration lightning::log_info!( &*probing_logger, - "Probing started: {} peers, {} amounts {:?} msat, interval={}s, timeout={}s", + "Probing started: {} peers, {} amounts {:?} msat, interval={}s, timeout={}s, probe_delay={}s, peer_delay={}s", probe_config.peers.len(), sorted_amounts.len(), sorted_amounts, probe_config.interval_sec, - probe_config.timeout_sec + probe_config.timeout_sec, + probe_config.probe_delay_sec, + probe_config.peer_delay_sec ); tokio::spawn(async move { @@ -1336,7 +1340,8 @@ async fn start_ldk() { interval.tick().await; // Probe each peer with amounts from smallest to largest - for peer in &probe_config.peers { + let peer_count = probe_config.peers.len(); + for (peer_idx, peer) in probe_config.peers.iter().enumerate() { let peer_short = truncate_pubkey(peer); 'amounts: for &amount in &sorted_amounts { // Send the probe and get the payment hash @@ -1373,7 +1378,8 @@ async fn start_ldk() { amount, hash ); - // Probe succeeded, continue to next amount + // Probe succeeded, sleep before next amount + tokio::time::sleep(probe_delay).await; }, Ok(Ok(ProbeOutcome::Failed)) => { lightning::log_warn!( @@ -1383,6 +1389,7 @@ async fn start_ldk() { amount, hash ); + tokio::time::sleep(probe_delay).await; break 'amounts; }, Ok(Err(_)) => { @@ -1393,6 +1400,7 @@ async fn start_ldk() { amount, hash ); + tokio::time::sleep(probe_delay).await; break 'amounts; }, Err(_) => { @@ -1409,6 +1417,7 @@ async fn start_ldk() { .unwrap() .pending_probes .remove(&hash); + tokio::time::sleep(probe_delay).await; break 'amounts; }, } @@ -1419,9 +1428,15 @@ async fn start_ldk() { peer_short, amount ); + tokio::time::sleep(probe_delay).await; break 'amounts; } } + + // Sleep between peers (except after the last peer) + if peer_idx < peer_count - 1 { + tokio::time::sleep(peer_delay).await; + } } } });