Skip to content

Commit e6348b8

Browse files
committed
Require inbound channels with anchor outputs to be accepted manually
Since the use of channels with anchor outputs requires a reserve of onchain funds to handle channel force closures, it would be irresponsible to allow a node to accept inbound channel without first consulting such reserves. To allow users to do so, we require such channels be manually accepted.
1 parent 25e3f94 commit e6348b8

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

lightning/src/ln/channelmanager.rs

+50-2
Original file line numberDiff line numberDiff line change
@@ -5103,9 +5103,13 @@ where
51035103
return Err(MsgHandleErrInternal::send_err_msg_no_close("temporary_channel_id collision for the same peer!".to_owned(), msg.temporary_channel_id.clone()))
51045104
} else {
51055105
if !self.default_configuration.manually_accept_inbound_channels {
5106-
if channel.context.get_channel_type().requires_zero_conf() {
5106+
let channel_type = channel.context.get_channel_type();
5107+
if channel_type.requires_zero_conf() {
51075108
return Err(MsgHandleErrInternal::send_err_msg_no_close("No zero confirmation channels accepted".to_owned(), msg.temporary_channel_id.clone()));
51085109
}
5110+
if channel_type.requires_anchors_zero_fee_htlc_tx() {
5111+
return Err(MsgHandleErrInternal::send_err_msg_no_close("No channels with anchor outputs accepted".to_owned(), msg.temporary_channel_id.clone()));
5112+
}
51095113
peer_state.pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
51105114
node_id: counterparty_node_id.clone(),
51115115
msg: channel.accept_inbound_channel(user_channel_id),
@@ -8732,7 +8736,7 @@ mod tests {
87328736
use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
87338737
use crate::ln::channelmanager::{inbound_payment, PaymentId, PaymentSendFailure, RecipientOnionFields, InterceptId};
87348738
use crate::ln::functional_test_utils::*;
8735-
use crate::ln::msgs;
8739+
use crate::ln::msgs::{self, ErrorAction};
87368740
use crate::ln::msgs::ChannelMessageHandler;
87378741
use crate::routing::router::{PaymentParameters, RouteParameters, find_route};
87388742
use crate::util::errors::APIError;
@@ -9728,6 +9732,50 @@ mod tests {
97289732
sender_intended_amt_msat - extra_fee_msat, 42, None, true, Some(extra_fee_msat)).is_ok());
97299733
}
97309734

9735+
#[test]
9736+
fn test_inbound_anchors_manual_acceptance() {
9737+
// Tests that we properly limit inbound channels when we have the manual-channel-acceptance
9738+
// flag set and (sometimes) accept channels as 0conf.
9739+
let mut anchors_cfg = test_default_channel_config();
9740+
anchors_cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
9741+
9742+
let mut anchors_manual_accept_cfg = anchors_cfg.clone();
9743+
anchors_manual_accept_cfg.manually_accept_inbound_channels = true;
9744+
9745+
let chanmon_cfgs = create_chanmon_cfgs(3);
9746+
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
9747+
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs,
9748+
&[Some(anchors_cfg.clone()), Some(anchors_cfg.clone()), Some(anchors_manual_accept_cfg.clone())]);
9749+
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
9750+
9751+
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 0, 42, None).unwrap();
9752+
let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
9753+
9754+
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg);
9755+
assert!(nodes[1].node.get_and_clear_pending_events().is_empty());
9756+
let msg_events = nodes[1].node.get_and_clear_pending_msg_events();
9757+
match &msg_events[0] {
9758+
MessageSendEvent::HandleError { node_id, action } => {
9759+
assert_eq!(*node_id, nodes[0].node.get_our_node_id());
9760+
match action {
9761+
ErrorAction::SendErrorMessage { msg } =>
9762+
assert_eq!(msg.data, "No channels with anchor outputs accepted".to_owned()),
9763+
_ => panic!("Unexpected error action"),
9764+
}
9765+
}
9766+
_ => panic!("Unexpected event"),
9767+
}
9768+
9769+
nodes[2].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg);
9770+
let events = nodes[2].node.get_and_clear_pending_events();
9771+
match events[0] {
9772+
Event::OpenChannelRequest { temporary_channel_id, .. } =>
9773+
nodes[2].node.accept_inbound_channel(&temporary_channel_id, &nodes[0].node.get_our_node_id(), 23).unwrap(),
9774+
_ => panic!("Unexpected event"),
9775+
}
9776+
get_event_msg!(nodes[2], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
9777+
}
9778+
97319779
#[test]
97329780
fn test_anchors_zero_fee_htlc_tx_fallback() {
97339781
// Tests that if both nodes support anchors, but the remote node does not want to accept

lightning/src/ln/monitor_tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,7 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) {
17211721
let mut config = test_default_channel_config();
17221722
if anchors {
17231723
config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
1724+
config.manually_accept_inbound_channels = true;
17241725
}
17251726
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config), Some(config)]);
17261727
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
@@ -1870,6 +1871,7 @@ fn test_yield_anchors_events() {
18701871
let mut anchors_config = UserConfig::default();
18711872
anchors_config.channel_handshake_config.announced_channel = true;
18721873
anchors_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
1874+
anchors_config.manually_accept_inbound_channels = true;
18731875
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(anchors_config), Some(anchors_config)]);
18741876
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
18751877

@@ -2002,6 +2004,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
20022004
let mut anchors_config = UserConfig::default();
20032005
anchors_config.channel_handshake_config.announced_channel = true;
20042006
anchors_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
2007+
anchors_config.manually_accept_inbound_channels = true;
20052008
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(anchors_config), Some(anchors_config)]);
20062009

20072010
let bob_persister: test_utils::TestPersister;

lightning/src/util/config.rs

+7
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ pub struct ChannelHandshakeConfig {
153153
/// channels. This feature requires having a reserve of onchain funds readily available to bump
154154
/// transactions in the event of a channel force close to avoid the possibility of losing funds.
155155
///
156+
/// Note that if you wish accept inbound channels with anchor outputs, you must enable
157+
/// [`UserConfig::manually_accept_inbound_channels`] and manually accept them with
158+
/// [`ChannelManager::accept_inbound_channel`]. This is done to give you the chance to check
159+
/// whether your reserve of onchain funds is enough to cover the fees for all existing and new
160+
/// channels featuring anchor outputs in the event of a force close.
161+
///
156162
/// If this option is set, channels may be created that will not be readable by LDK versions
157163
/// prior to 0.0.116, causing [`ChannelManager`]'s read method to return a
158164
/// [`DecodeError::InvalidValue`].
@@ -168,6 +174,7 @@ pub struct ChannelHandshakeConfig {
168174
/// Default value: false. This value is likely to change to true in the future.
169175
///
170176
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
177+
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
171178
/// [`DecodeError::InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
172179
/// [`SIGHASH_SINGLE + update_fee Considered Harmful`]: https://lists.linuxfoundation.org/pipermail/lightning-dev/2020-September/002796.html
173180
pub negotiate_anchors_zero_fee_htlc_tx: bool,

0 commit comments

Comments
 (0)