Skip to content

Commit 2329307

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 5a5164a commit 2329307

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5039,9 +5039,13 @@ where
50395039
return Err(MsgHandleErrInternal::send_err_msg_no_close("temporary_channel_id collision for the same peer!".to_owned(), msg.temporary_channel_id.clone()))
50405040
} else {
50415041
if !self.default_configuration.manually_accept_inbound_channels {
5042-
if channel.context.get_channel_type().requires_zero_conf() {
5042+
let channel_type = channel.context.get_channel_type();
5043+
if channel_type.requires_zero_conf() {
50435044
return Err(MsgHandleErrInternal::send_err_msg_no_close("No zero confirmation channels accepted".to_owned(), msg.temporary_channel_id.clone()));
50445045
}
5046+
if channel_type.requires_anchors_zero_fee_htlc_tx() {
5047+
return Err(MsgHandleErrInternal::send_err_msg_no_close("No channels with anchor outputs accepted".to_owned(), msg.temporary_channel_id.clone()));
5048+
}
50455049
peer_state.pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
50465050
node_id: counterparty_node_id.clone(),
50475051
msg: channel.accept_inbound_channel(user_channel_id),
@@ -8664,7 +8668,7 @@ mod tests {
86648668
use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
86658669
use crate::ln::channelmanager::{inbound_payment, PaymentId, PaymentSendFailure, RecipientOnionFields, InterceptId};
86668670
use crate::ln::functional_test_utils::*;
8667-
use crate::ln::msgs;
8671+
use crate::ln::msgs::{self, ErrorAction};
86688672
use crate::ln::msgs::ChannelMessageHandler;
86698673
use crate::routing::router::{PaymentParameters, RouteParameters, find_route};
86708674
use crate::util::errors::APIError;
@@ -9616,6 +9620,50 @@ mod tests {
96169620
get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, last_random_pk);
96179621
}
96189622

9623+
#[test]
9624+
fn test_inbound_anchors_manual_acceptance() {
9625+
// Tests that we properly limit inbound channels when we have the manual-channel-acceptance
9626+
// flag set and (sometimes) accept channels as 0conf.
9627+
let mut anchors_cfg = test_default_channel_config();
9628+
anchors_cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
9629+
9630+
let mut anchors_manual_accept_cfg = anchors_cfg.clone();
9631+
anchors_manual_accept_cfg.manually_accept_inbound_channels = true;
9632+
9633+
let chanmon_cfgs = create_chanmon_cfgs(3);
9634+
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
9635+
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs,
9636+
&[Some(anchors_cfg.clone()), Some(anchors_cfg.clone()), Some(anchors_manual_accept_cfg.clone())]);
9637+
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
9638+
9639+
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 0, 42, None).unwrap();
9640+
let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
9641+
9642+
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg);
9643+
assert!(nodes[1].node.get_and_clear_pending_events().is_empty());
9644+
let msg_events = nodes[1].node.get_and_clear_pending_msg_events();
9645+
match &msg_events[0] {
9646+
MessageSendEvent::HandleError { node_id, action } => {
9647+
assert_eq!(*node_id, nodes[0].node.get_our_node_id());
9648+
match action {
9649+
ErrorAction::SendErrorMessage { msg } =>
9650+
assert_eq!(msg.data, "No channels with anchor outputs accepted".to_owned()),
9651+
_ => panic!("Unexpected error action"),
9652+
}
9653+
}
9654+
_ => panic!("Unexpected event"),
9655+
}
9656+
9657+
nodes[2].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg);
9658+
let events = nodes[2].node.get_and_clear_pending_events();
9659+
match events[0] {
9660+
Event::OpenChannelRequest { temporary_channel_id, .. } =>
9661+
nodes[2].node.accept_inbound_channel(&temporary_channel_id, &nodes[0].node.get_our_node_id(), 23).unwrap(),
9662+
_ => panic!("Unexpected event"),
9663+
}
9664+
get_event_msg!(nodes[2], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
9665+
}
9666+
96199667
#[test]
96209668
fn test_anchors_zero_fee_htlc_tx_fallback() {
96219669
// Tests that if both nodes support anchors, but the remote node does not want to accept

lightning/src/ln/monitor_tests.rs

Lines changed: 3 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ 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`].
159+
///
156160
/// If this option is set, channels may be created that will not be readable by LDK versions
157161
/// prior to 0.0.116, causing [`ChannelManager`]'s read method to return a
158162
/// [`DecodeError::InvalidValue`].

0 commit comments

Comments
 (0)