Skip to content

Commit 90e1eea

Browse files
committed
Regularly broadcast node announcement
1 parent abfda94 commit 90e1eea

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/lib.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,12 @@ const BDK_CLIENT_CONCURRENCY: u8 = 8;
169169
// The timeout after which we abandon retrying failed payments.
170170
const LDK_PAYMENT_RETRY_TIMEOUT: Duration = Duration::from_secs(10);
171171

172-
// The time in between peer reconnection attempts.
172+
// The time in-between peer reconnection attempts.
173173
const PEER_RECONNECTION_INTERVAL: Duration = Duration::from_secs(10);
174174

175+
// The time in-between node announcement broadcast attempts.
176+
const NODE_ANN_BCAST_INTERVAL: Duration = Duration::from_secs(60 * 10);
177+
175178
// The length in bytes of our wallets' keys seed.
176179
const WALLET_KEYS_SEED_LEN: usize = 64;
177180

@@ -852,10 +855,13 @@ impl Node {
852855
let stop_connect = Arc::clone(&stop_running);
853856
runtime.spawn(async move {
854857
let mut interval = tokio::time::interval(PEER_RECONNECTION_INTERVAL);
858+
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
855859
loop {
856860
if stop_connect.load(Ordering::Acquire) {
857861
return;
858862
}
863+
864+
interval.tick().await;
859865
let pm_peers = connect_pm
860866
.get_peer_node_ids()
861867
.iter()
@@ -877,7 +883,33 @@ impl Node {
877883
.await;
878884
}
879885
}
880-
interval.tick().await;
886+
}
887+
});
888+
889+
// Regularly broadcast node announcements.
890+
let bcast_cm = Arc::clone(&self.channel_manager);
891+
let bcast_pm = Arc::clone(&self.peer_manager);
892+
let bcast_config = Arc::clone(&self.config);
893+
let stop_bcast = Arc::clone(&stop_running);
894+
runtime.spawn(async move {
895+
let mut interval = tokio::time::interval(NODE_ANN_BCAST_INTERVAL);
896+
loop {
897+
if stop_bcast.load(Ordering::Acquire) {
898+
return;
899+
}
900+
901+
if bcast_cm.list_channels().iter().any(|chan| chan.is_public) {
902+
interval.tick().await;
903+
904+
while bcast_pm.get_peer_node_ids().is_empty() {
905+
// Sleep a bit and retry if we don't have any peers yet.
906+
tokio::time::sleep(Duration::from_secs(5)).await;
907+
}
908+
909+
let addresses =
910+
bcast_config.listening_address.iter().cloned().map(|a| a.0).collect();
911+
bcast_pm.broadcast_node_announcement([0; 3], [0; 32], addresses);
912+
}
881913
}
882914
});
883915

0 commit comments

Comments
 (0)