From 38a24c9272638d4bd29f9b5a9a84079bed33b58f Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Wed, 12 Feb 2025 12:25:41 +0100 Subject: [PATCH] Reject inbound announced channels if not all requirements are met In particular, reject inbound announced channels if node alias and listening addresses are not set. We previously enforced this for outbound channels, here we start enforcing this check for inbound channels, too. --- src/event.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/event.rs b/src/event.rs index 40e236793..381742efe 100644 --- a/src/event.rs +++ b/src/event.rs @@ -8,10 +8,11 @@ use crate::types::{CustomTlvRecord, DynStore, Sweeper, Wallet}; use crate::{ - hex_utils, BumpTransactionEventHandler, ChannelManager, Config, Error, Graph, PeerInfo, - PeerStore, UserChannelId, + hex_utils, BumpTransactionEventHandler, ChannelManager, Error, Graph, PeerInfo, PeerStore, + UserChannelId, }; +use crate::config::{may_announce_channel, Config}; use crate::connection::ConnectionManager; use crate::fee_estimator::ConfirmationTarget; @@ -1041,15 +1042,29 @@ where funding_satoshis, channel_type, channel_negotiation_type: _, - is_announced: _, + is_announced, params: _, } => { - let anchor_channel = channel_type.requires_anchors_zero_fee_htlc_tx(); + if is_announced && !may_announce_channel(&*self.config) { + log_error!( + self.logger, + "Rejecting inbound announced channel from peer {} as not all required details are set. Please ensure node alias and listening addresses have been configured.", + counterparty_node_id, + ); - // TODO: We should use `is_announced` flag above and reject announced channels if - // we're not a forwading node, once we add a 'forwarding mode' based on listening - // address / node alias being set. + self.channel_manager + .force_close_without_broadcasting_txn( + &temporary_channel_id, + &counterparty_node_id, + "Channel request rejected".to_string(), + ) + .unwrap_or_else(|e| { + log_error!(self.logger, "Failed to reject channel: {:?}", e) + }); + return Ok(()); + } + let anchor_channel = channel_type.requires_anchors_zero_fee_htlc_tx(); if anchor_channel { if let Some(anchor_channels_config) = self.config.anchor_channels_config.as_ref()