Merge PR 'Ignore duplicate announcement_signatures' (#5529)
What changed, and why it matters
This change prevents a Lightning node from repeatedly broadcasting the same channel announcement if a peer keeps replaying a specific protocol message (announcement_signatures). Before the fix, a malicious or buggy peer could make the node generate and flood fresh channel_announcement broadcasts, wasting bandwidth and gossip buffer space across the network. The patch adds a flag so only the first processed announcement_signatures triggers a broadcast, with one deliberate exception after a node restart to preserve reliability.
Treat as a low-to-moderate hardening fix. Reviewers should confirm the flag is reset in all relevant channel state transitions (reconnect, closure, force-close) and consider whether persistence is desirable to also suppress the post-restart replay window.
Security signals we found
gossip amplification / bandwidth exhaustion via replayed protocol message
state tracking added to deduplicate announcement_signatures handling
ChannelError::Ignore used to drop duplicate instead of failing channel
new regression test describes counterparty replay scenario and mitigation
Evidence from the diff
The commit introduces a new ChannelContext field, broadcasted_signed_announcement, tracked in memory only (not persisted). When handle_announcement_signatures is called, if the flag is already true the message is ignored with a ChannelError::Ignore. Otherwise the node signs and broadcasts the channel_announcement and sets the flag. The flag is reset on channel reconnection/reestablishment and on channel closure. Because it is not serialized, a replayed announcement_signatures after a node restart is allowed to generate one more broadcast, then suppressed again. A regression test verifies both immediate replay suppression and the post-restart one-time behavior.
Changed components
lightning/src/ln/channel.rslightning/src/ln/reload_tests.rsInspect captured patch +116 / −1
### lightning/src/ln/channel.rs
@@ -3821,6 +3821,8 @@ pub(super) struct ChannelContext<SP: SignerProvider> {
/// This can be used to rebroadcast the channel_announcement message later.
announcement_sigs: Option<(Signature, Signature)>,
+ broadcasted_signed_announcement: bool,
+
/// lnd has a long-standing bug where, upon reconnection, if the channel is not yet confirmed
/// they will not send a channel_reestablish until the channel locks in. Then, they will send a
/// channel_ready *before* sending the channel_reestablish (which is clearly a violation of
@@ -4600,6 +4602,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
closing_signed_in_flight: false,
announcement_sigs: None,
+ broadcasted_signed_announcement: false,
workaround_lnd_bug_4006: None,
funding_locked_txid_sent_in_reestablish: None,
@@ -4909,6 +4912,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
closing_signed_in_flight: false,
announcement_sigs: None,
+ broadcasted_signed_announcement: false,
workaround_lnd_bug_4006: None,
funding_locked_txid_sent_in_reestablish: None,
@@ -10133,6 +10137,7 @@ where
if self.context.announcement_sigs_state == AnnouncementSigsState::MessageSent || self.context.announcement_sigs_state == AnnouncementSigsState::Committed {
self.context.announcement_sigs_state = AnnouncementSigsState::NotSent;
}
+ self.context.broadcasted_signed_announcement = false;
// Upon reconnect we have to start the closing_signed dance over, but shutdown messages
// will be retransmitted.
@@ -12444,6 +12449,7 @@ where
self.context.interactive_tx_signing_session = None;
self.pending_splice = None;
self.context.announcement_sigs = None;
+ self.context.broadcasted_signed_announcement = false;
self.context.announcement_sigs_state = AnnouncementSigsState::NotSent;
let funding_txo = self
@@ -13074,6 +13080,12 @@ where
)));
}
+ if self.context.broadcasted_signed_announcement {
+ return Err(ChannelError::Ignore(
+ "Ignoring duplicate announcement_signatures - we already generated a signed channel_announcement for this channel"
+ .to_owned()));
+ }
+
let announcement = self.get_channel_announcement(node_signer, chain_hash, user_config)?;
let msghash = hash_to_message!(&Sha256d::hash(&announcement.encode()[..])[..]);
@@ -13095,7 +13107,9 @@ where
"Got announcement_signatures prior to the required six confirmations - we may not have received a block yet that our peer has".to_owned()));
}
- self.sign_channel_announcement(node_signer, announcement)
+ let signed_announcement = self.sign_channel_announcement(node_signer, announcement)?;
+ self.context.broadcasted_signed_announcement = true;
+ Ok(signed_announcement)
}
/// Gets a signed channel_announcement for this channel, if we previously received an
@@ -17980,6 +17994,7 @@ impl<'a, 'b, 'c, ES: EntropySource, SP: SignerProvider>
closing_signed_in_flight: false,
announcement_sigs,
+ broadcasted_signed_announcement: false,
workaround_lnd_bug_4006: None,
funding_locked_txid_sent_in_reestablish: None,
### lightning/src/ln/reload_tests.rs
@@ -190,6 +190,106 @@ fn test_funding_peer_disconnect() {
reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1]));
}
+#[test]
+fn test_duplicate_announcement_signatures_ignored() {
+ // A counterparty with a confirmed public channel can replay the announcement_signatures it
+ // originally sent, which are indistinguishable from a legitimate retransmission. If we
+ // generated a fresh channel_announcement broadcast for each replay, the counterparty could
+ // flood our peers' gossip buffers, so only the first announcement_signatures we process may
+ // generate a broadcast. The signed channel_announcement we generate in response is not
+ // tracked across restarts, however, so one replayed announcement_signatures still generates
+ // a broadcast after a restart (in case we shut down after processing it but before the
+ // announcement reached our peers). Further replays must not.
+ let chanmon_cfgs = create_chanmon_cfgs(2);
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+ let persister;
+ let new_chain_monitor;
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
+ let nodes_0_deserialized;
+ let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+
+ let node_a_id = nodes[0].node.get_our_node_id();
+ let node_b_id = nodes[1].node.get_our_node_id();
+
+ let ((as_channel_ready, as_announcement_sigs), chan_id, _) =
+ create_chan_between_nodes_with_value_a(&nodes[0], &nodes[1], 100000, 10001);
+
+ // Deliver nodes[0]'s channel_ready, prompting nodes[1] to send its announcement_signatures,
+ // then deliver announcement_signatures both ways, generating a channel_announcement broadcast
+ // on each side.
+ nodes[1].node.handle_channel_ready(node_a_id, &as_channel_ready);
+ let bs_announcement_sigs =
+ get_event_msg!(nodes[1], MessageSendEvent::SendAnnouncementSignatures, node_a_id);
+ nodes[1].node.handle_announcement_signatures(node_a_id, &as_announcement_sigs);
+ let events = nodes[1].node.get_and_clear_pending_msg_events();
+ assert_eq!(events.len(), 1);
+ let chan_announcement = match events[0] {
+ MessageSendEvent::BroadcastChannelAnnouncement { ref msg, .. } => msg.clone(),
+ _ => panic!("Unexpected event {:?}", events[0]),
+ };
+ expect_channel_ready_event(&nodes[1], &node_a_id);
+
+ nodes[0].node.handle_announcement_signatures(node_b_id, &bs_announcement_sigs);
+ let events = nodes[0].node.get_and_clear_pending_msg_events();
+ assert_eq!(events.len(), 1);
+ match events[0] {
+ MessageSendEvent::BroadcastChannelAnnouncement { ref msg, .. } => {
+ assert_eq!(*msg, chan_announcement);
+ },
+ _ => panic!("Unexpected event {:?}", events[0]),
+ }
+
+ // Replays on either side must not generate a fresh broadcast.
+ nodes[0].node.handle_announcement_signatures(node_b_id, &bs_announcement_sigs);
+ assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
+ nodes[1].node.handle_announcement_signatures(node_a_id, &as_announcement_sigs);
+ assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
+
+ nodes[1].node.peer_disconnected(node_a_id);
+
+ let chan_0_monitor_serialized = get_monitor!(nodes[0], chan_id).encode();
+ reload_node!(nodes[0], &nodes[0].node.encode(), &[&chan_0_monitor_serialized], persister, new_chain_monitor, nodes_0_deserialized);
+
+ nodes[0].node.peer_connected(node_b_id, &msgs::Init {
+ features: nodes[1].node.init_features(), networks: None, remote_network_address: None
+ }, true).unwrap();
+ let as_reestablish = get_chan_reestablish_msgs!(nodes[0], nodes[1]).pop().unwrap();
+ nodes[1].node.peer_connected(node_a_id, &msgs::Init {
+ features: nodes[0].node.init_features(), networks: None, remote_network_address: None
+ }, false).unwrap();
+ let bs_reestablish = get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap();
+
+ nodes[0].node.handle_channel_reestablish(node_b_id, &bs_reestablish);
+ // Both sides are still on their initial commitment number, so the reloaded node retransmits
+ // its channel_ready, announcement_signatures, and channel_update, which we drop.
+ let events = nodes[0].node.get_and_clear_pending_msg_events();
+ assert_eq!(events.len(), 3);
+ assert!(matches!(&events[0], MessageSendEvent::SendChannelReady { .. }));
+ assert!(matches!(&events[1], MessageSendEvent::SendAnnouncementSignatures { .. }));
+ assert!(matches!(events[2], MessageSendEvent::SendChannelUpdate { .. }));
+
+ nodes[1].node.handle_channel_reestablish(node_a_id, &as_reestablish);
+ // nodes[1] retransmits its channel_ready, announcement_signatures, and channel_update, which
+ // we drop rather than deliver, replaying the original announcement_signatures below instead.
+ let events = nodes[1].node.get_and_clear_pending_msg_events();
+ assert_eq!(events.len(), 3);
+ assert!(matches!(&events[0], MessageSendEvent::SendChannelReady { .. }));
+ assert!(matches!(&events[1], MessageSendEvent::SendAnnouncementSignatures { .. }));
+ assert!(matches!(events[2], MessageSendEvent::SendChannelUpdate { .. }));
+
+ nodes[0].node.handle_announcement_signatures(node_b_id, &bs_announcement_sigs);
+ let events = nodes[0].node.get_and_clear_pending_msg_events();
+ assert_eq!(events.len(), 1);
+ match events[0] {
+ MessageSendEvent::BroadcastChannelAnnouncement { ref msg, .. } => {
+ assert_eq!(*msg, chan_announcement);
+ },
+ _ => panic!("Unexpected event {:?}", events[0]),
+ }
+ nodes[0].node.handle_announcement_signatures(node_b_id, &bs_announcement_sigs);
+ assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
+}
+
#[test]
fn test_no_txn_manager_serialize_deserialize() {
let chanmon_cfgs = create_chanmon_cfgs(2);Why this scored 52/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.