Skip to content

Commit 9a6abfd

Browse files
committed
Re-broadcast channel_announcements every six blocks for a week
When we first get a public channel confirmed at six blocks, we broadcast a `channel_announcement` once and then move on. As long as it makes it into our local network graph that should be okay, as we should send peers our network graph contents as they seek to sync, however its possible an ill-timed shutdown could cause this to fail, and relying on peers to do a full historical sync from us may delay `channel_announcement` propagation. Instead, here, we re-broadcast our `channel_announcement`s every six blocks for a week, which should be way more than robust enough to get them properly across the P2P network. Fixes #2418
1 parent ad19d93 commit 9a6abfd

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

lightning/src/ln/channelmanager.rs

+34-10
Original file line numberDiff line numberDiff line change
@@ -10216,23 +10216,47 @@ where
1021610216
emit_channel_ready_event!(pending_events, channel);
1021710217
}
1021810218

10219-
if let Some(announcement_sigs) = announcement_sigs {
10220-
log_trace!(logger, "Sending announcement_signatures for channel {}", channel.context.channel_id());
10221-
pending_msg_events.push(events::MessageSendEvent::SendAnnouncementSignatures {
10222-
node_id: channel.context.get_counterparty_node_id(),
10223-
msg: announcement_sigs,
10224-
});
10225-
if let Some(height) = height_opt {
10226-
if let Some(announcement) = channel.get_signed_channel_announcement(&self.node_signer, self.chain_hash, height, &self.default_configuration) {
10219+
if let Some(height) = height_opt {
10220+
// (re-)broadcast signed `channel_announcement`s and
10221+
// `channel_update`s for any channels less than a week old.
10222+
let funding_conf_height =
10223+
channel.context.get_funding_tx_confirmation_height().unwrap_or(height);
10224+
// To avoid broadcast storms after each block, only
10225+
// re-broadcast every hour (6 blocks) after the initial
10226+
// broadcast, or if this is the first time we're ready to
10227+
// broadcast this channel.
10228+
let rebroadcast_announcement = funding_conf_height < height + 1008
10229+
&& funding_conf_height % 6 == height % 6;
10230+
let mut should_announce = announcement_sigs.is_some() || rebroadcast_announcement;
10231+
// Most of our tests were written when we only broadcasted
10232+
// `channel_announcement`s once and then never re-broadcasted
10233+
// them again, so disable the re-broadcasting entirely in tests
10234+
#[cfg(test)]
10235+
{
10236+
should_announce = announcement_sigs.is_some();
10237+
}
10238+
if should_announce {
10239+
if let Some(announcement) = channel.get_signed_channel_announcement(
10240+
&self.node_signer, self.chain_hash, height, &self.default_configuration,
10241+
) {
1022710242
pending_msg_events.push(events::MessageSendEvent::BroadcastChannelAnnouncement {
1022810243
msg: announcement,
10229-
// Note that announcement_signatures fails if the channel cannot be announced,
10230-
// so get_channel_update_for_broadcast will never fail by the time we get here.
10244+
// Note that get_signed_channel_announcement fails
10245+
// if the channel cannot be announced, so
10246+
// get_channel_update_for_broadcast will never fail
10247+
// by the time we get here.
1023110248
update_msg: Some(self.get_channel_update_for_broadcast(channel).unwrap()),
1023210249
});
1023310250
}
1023410251
}
1023510252
}
10253+
if let Some(announcement_sigs) = announcement_sigs {
10254+
log_trace!(logger, "Sending announcement_signatures for channel {}", channel.context.channel_id());
10255+
pending_msg_events.push(events::MessageSendEvent::SendAnnouncementSignatures {
10256+
node_id: channel.context.get_counterparty_node_id(),
10257+
msg: announcement_sigs,
10258+
});
10259+
}
1023610260
if channel.is_our_channel_ready() {
1023710261
if let Some(real_scid) = channel.context.get_short_channel_id() {
1023810262
// If we sent a 0conf channel_ready, and now have an SCID, we add it

lightning/src/ln/priv_short_conf_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ fn do_test_1_conf_open(connect_style: ConnectStyle) {
190190
connect_blocks(&nodes[1], 5);
191191
let bs_announce_events = nodes[1].node.get_and_clear_pending_msg_events();
192192
assert_eq!(bs_announce_events.len(), 2);
193-
let bs_announcement_sigs = if let MessageSendEvent::SendAnnouncementSignatures { ref node_id, ref msg } = bs_announce_events[0] {
193+
let bs_announcement_sigs = if let MessageSendEvent::SendAnnouncementSignatures { ref node_id, ref msg } = bs_announce_events[1] {
194194
assert_eq!(*node_id, nodes[0].node.get_our_node_id());
195195
msg.clone()
196196
} else { panic!("Unexpected event"); };
197-
let (bs_announcement, bs_update) = if let MessageSendEvent::BroadcastChannelAnnouncement { ref msg, ref update_msg } = bs_announce_events[1] {
197+
let (bs_announcement, bs_update) = if let MessageSendEvent::BroadcastChannelAnnouncement { ref msg, ref update_msg } = bs_announce_events[0] {
198198
(msg.clone(), update_msg.clone().unwrap())
199199
} else { panic!("Unexpected event"); };
200200

0 commit comments

Comments
 (0)