Skip to content

Commit 575b70f

Browse files
committed
Announce node_announcemnet even without listen addresses
Even if we don't have any listen addresses, it's still useful to broadcast a node_announcement to get our node_features out there. Here we do this and also improve the timing of our node_announcement updates to be less spammy.
1 parent 7aceee9 commit 575b70f

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/main.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -781,24 +781,29 @@ async fn start_ldk() {
781781
});
782782

783783
// Regularly broadcast our node_announcement. This is only required (or possible) if we have
784-
// some public channels, and is only useful if we have public listen address(es) to announce.
785-
// In a production environment, this should occur only after the announcement of new channels
786-
// to avoid churn in the global network graph.
784+
// some public channels.
787785
let peer_man = Arc::clone(&peer_manager);
786+
let chan_man = Arc::clone(&channel_manager);
788787
let network = args.network;
789-
if !args.ldk_announced_listen_addr.is_empty() {
790-
tokio::spawn(async move {
791-
let mut interval = tokio::time::interval(Duration::from_secs(60));
792-
loop {
793-
interval.tick().await;
788+
tokio::spawn(async move {
789+
// First wait a minute until we have some peers and maybe have opened a channel.
790+
tokio::time::sleep(Duration::from_secs(60)).await;
791+
// Then, update our announcement once an hour to keep it fresh but avoid unnecessary churn
792+
// in the global gossip network.
793+
let mut interval = tokio::time::interval(Duration::from_secs(3600));
794+
loop {
795+
// Don't bother trying to announce if we don't have any public channls, though our
796+
// peers should drop such an announcement anyway.
797+
if chan_man.list_channels().iter().any(|chan| chan.is_public) {
794798
peer_man.broadcast_node_announcement(
795799
[0; 3],
796800
args.ldk_announced_node_name,
797801
args.ldk_announced_listen_addr.clone(),
798802
);
799803
}
800-
});
801-
}
804+
interval.tick().await;
805+
}
806+
});
802807

803808
// Start the CLI.
804809
cli::poll_for_user_input(

0 commit comments

Comments
 (0)