From 86d25a2ea81e3a4caf4c6db3d29802edf467d8c2 Mon Sep 17 00:00:00 2001 From: elnosh Date: Fri, 23 Jan 2026 09:41:43 -0500 Subject: [PATCH] Default to anchors and remove automatic channel acceptance Changes `negotiate_anchors_zero_fee_htlc_tx` default to true and removes the `manually_accept_inbound_channels` config option. This will require users to manually have to accept all inbound channels. --- fuzz/src/chanmon_consistency.rs | 56 +++-- lightning-background-processor/src/lib.rs | 23 +- .../tests/lsps2_integration_tests.rs | 4 - lightning/src/events/mod.rs | 54 ++--- lightning/src/ln/async_payments_tests.rs | 1 - lightning/src/ln/async_signer_tests.rs | 22 +- lightning/src/ln/chanmon_update_fail_tests.rs | 8 +- lightning/src/ln/channel.rs | 7 +- lightning/src/ln/channel_open_tests.rs | 199 ++++++++---------- lightning/src/ln/channel_state.rs | 7 +- lightning/src/ln/channel_type_tests.rs | 8 +- lightning/src/ln/channelmanager.rs | 172 ++++++--------- lightning/src/ln/functional_test_utils.rs | 61 ++++-- lightning/src/ln/functional_tests.rs | 28 ++- lightning/src/ln/htlc_reserve_unit_tests.rs | 4 +- lightning/src/ln/invoice_utils.rs | 5 +- lightning/src/ln/monitor_tests.rs | 16 +- lightning/src/ln/payment_tests.rs | 3 - lightning/src/ln/priv_short_conf_tests.rs | 57 +---- lightning/src/ln/reload_tests.rs | 2 +- lightning/src/ln/reorg_tests.rs | 7 +- lightning/src/ln/shutdown_tests.rs | 25 ++- lightning/src/ln/splicing_tests.rs | 14 +- lightning/src/ln/update_fee_tests.rs | 15 +- lightning/src/ln/zero_fee_commitment_tests.rs | 3 - lightning/src/util/config.rs | 50 ++--- ...-manual-channel-accept-default-anchors.txt | 16 ++ 27 files changed, 382 insertions(+), 485 deletions(-) create mode 100644 pending_changelog/4337-manual-channel-accept-default-anchors.txt diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index f87af5c6ff5..d31cfcb5dd5 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -710,9 +710,8 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { config.channel_config.forwarding_fee_proportional_millionths = 0; config.channel_handshake_config.announce_for_forwarding = true; config.reject_inbound_splices = false; - if anchors { - config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - config.manually_accept_inbound_channels = true; + if !anchors { + config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = false; } let network = Network::Bitcoin; let best_block_timestamp = genesis_block(network).header.time; @@ -761,9 +760,8 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { config.channel_config.forwarding_fee_proportional_millionths = 0; config.channel_handshake_config.announce_for_forwarding = true; config.reject_inbound_splices = false; - if anchors { - config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - config.manually_accept_inbound_channels = true; + if !anchors { + config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = false; } let mut monitors = new_hash_map(); @@ -874,30 +872,28 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { $dest.handle_open_channel($source.get_our_node_id(), &open_channel); let accept_channel = { - if anchors { - let events = $dest.get_and_clear_pending_events(); - assert_eq!(events.len(), 1); - if let events::Event::OpenChannelRequest { - ref temporary_channel_id, - ref counterparty_node_id, - .. - } = events[0] - { - let mut random_bytes = [0u8; 16]; - random_bytes - .copy_from_slice(&$dest_keys_manager.get_secure_random_bytes()[..16]); - let user_channel_id = u128::from_be_bytes(random_bytes); - $dest - .accept_inbound_channel( - temporary_channel_id, - counterparty_node_id, - user_channel_id, - None, - ) - .unwrap(); - } else { - panic!("Wrong event type"); - } + let events = $dest.get_and_clear_pending_events(); + assert_eq!(events.len(), 1); + if let events::Event::OpenChannelRequest { + ref temporary_channel_id, + ref counterparty_node_id, + .. + } = events[0] + { + let mut random_bytes = [0u8; 16]; + random_bytes + .copy_from_slice(&$dest_keys_manager.get_secure_random_bytes()[..16]); + let user_channel_id = u128::from_be_bytes(random_bytes); + $dest + .accept_inbound_channel( + temporary_channel_id, + counterparty_node_id, + user_channel_id, + None, + ) + .unwrap(); + } else { + panic!("Wrong event type"); } let events = $dest.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index c38d6dfe080..617189ca83d 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -2465,6 +2465,8 @@ mod tests { )); let best_block = BestBlock::from_network(network); let params = ChainParameters { network, best_block }; + let mut config = UserConfig::default(); + config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = false; let manager = Arc::new(ChannelManager::new( Arc::clone(&fee_estimator), Arc::clone(&chain_monitor), @@ -2475,7 +2477,7 @@ mod tests { Arc::clone(&keys_manager), Arc::clone(&keys_manager), Arc::clone(&keys_manager), - UserConfig::default(), + config, params, genesis_block.header.time, )); @@ -2628,6 +2630,25 @@ mod tests { $node_b.node.get_our_node_id() ); $node_b.node.handle_open_channel($node_a.node.get_our_node_id(), &msg_a); + let events = $node_b.node.get_and_clear_pending_events(); + assert_eq!(events.len(), 1); + match &events[0] { + Event::OpenChannelRequest { + temporary_channel_id, counterparty_node_id, .. + } => { + $node_b + .node + .accept_inbound_channel( + temporary_channel_id, + counterparty_node_id, + 42, + None, + ) + .unwrap(); + }, + _ => panic!("Unexpected event"), + }; + let msg_b = get_event_msg!( $node_b, MessageSendEvent::SendAcceptChannel, diff --git a/lightning-liquidity/tests/lsps2_integration_tests.rs b/lightning-liquidity/tests/lsps2_integration_tests.rs index 2e469d149b0..1f80c03f72c 100644 --- a/lightning-liquidity/tests/lsps2_integration_tests.rs +++ b/lightning-liquidity/tests/lsps2_integration_tests.rs @@ -1160,7 +1160,6 @@ fn client_trusts_lsp_end_to_end_test() { service_node_config.accept_intercept_htlcs = true; let mut client_node_config = test_default_channel_config(); - client_node_config.manually_accept_inbound_channels = true; client_node_config.channel_config.accept_underpaying_htlcs = true; let node_chanmgrs = create_node_chanmgrs( 3, @@ -1633,7 +1632,6 @@ fn late_payment_forwarded_and_safe_after_force_close_does_not_broadcast() { service_node_config.accept_intercept_htlcs = true; let mut client_node_config = test_default_channel_config(); - client_node_config.manually_accept_inbound_channels = true; client_node_config.channel_config.accept_underpaying_htlcs = true; let node_chanmgrs = create_node_chanmgrs( @@ -1824,7 +1822,6 @@ fn htlc_timeout_before_client_claim_results_in_handling_failed() { service_node_config.accept_intercept_htlcs = true; let mut client_node_config = test_default_channel_config(); - client_node_config.manually_accept_inbound_channels = true; client_node_config.channel_config.accept_underpaying_htlcs = true; let node_chanmgrs = create_node_chanmgrs( @@ -2160,7 +2157,6 @@ fn client_trusts_lsp_partial_fee_does_not_trigger_broadcast() { service_node_config.accept_intercept_htlcs = true; let mut client_node_config = test_default_channel_config(); - client_node_config.manually_accept_inbound_channels = true; client_node_config.channel_config.accept_underpaying_htlcs = true; let node_chanmgrs = create_node_chanmgrs( diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index d97ae6097b6..fee2fb6b0a4 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -244,9 +244,7 @@ pub struct ClaimedHTLC { pub channel_id: ChannelId, /// The `user_channel_id` of the channel over which the HTLC was received. This is the value /// passed in to [`ChannelManager::create_channel`] for outbound channels, or to - /// [`ChannelManager::accept_inbound_channel`] for inbound channels if - /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise - /// `user_channel_id` will be randomized for an inbound channel. + /// [`ChannelManager::accept_inbound_channel`]. /// /// This field will be zero for a payment that was serialized prior to LDK version 0.0.117. (This /// should only happen in the case that a payment was claimable prior to LDK version 0.0.117, but @@ -254,7 +252,6 @@ pub struct ClaimedHTLC { /// /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel - /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels pub user_channel_id: u128, /// The block height at which this HTLC expires. pub cltv_expiry: u32, @@ -764,14 +761,11 @@ pub enum Event { /// The script which should be used in the transaction output. output_script: ScriptBuf, /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound - /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if - /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise - /// `user_channel_id` will be randomized for an inbound channel. This may be zero for objects - /// serialized with LDK versions prior to 0.0.113. + /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels. + /// This may be zero for objects serialized with LDK versions prior to 0.0.113. /// /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel - /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels user_channel_id: u128, }, /// Used to indicate that the counterparty node has provided the signature(s) required to @@ -1394,13 +1388,10 @@ pub enum Event { /// The `channel_id` of the channel that is pending confirmation. channel_id: ChannelId, /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound - /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if - /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise - /// `user_channel_id` will be randomized for an inbound channel. + /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels. /// /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel - /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels user_channel_id: u128, /// The `temporary_channel_id` this channel used to be known by during channel establishment. /// @@ -1434,13 +1425,10 @@ pub enum Event { /// The `channel_id` of the channel that is ready. channel_id: ChannelId, /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound - /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if - /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise - /// `user_channel_id` will be randomized for an inbound channel. + /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels. /// /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel - /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels user_channel_id: u128, /// The `node_id` of the channel counterparty. counterparty_node_id: PublicKey, @@ -1456,11 +1444,10 @@ pub enum Event { /// process of closure. This includes previously opened channels, and channels that time out from not being funded. /// /// Note that this event is only triggered for accepted channels: if the - /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true and the channel is - /// rejected, no `ChannelClosed` event will be sent. + /// [`Event::OpenChannelRequest`] was rejected, no `ChannelClosed` event will be sent. /// /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel - /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels + /// [`Event::OpenChannelRequest`]: Event::OpenChannelRequest /// /// # Failure Behavior and Persistence /// This event will eventually be replayed after failures-to-handle (i.e., the event handler @@ -1470,15 +1457,12 @@ pub enum Event { /// resolving the channel are likely still awaiting confirmation. channel_id: ChannelId, /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound - /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if - /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise - /// `user_channel_id` will be randomized for inbound channels. + /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels. /// This may be zero for inbound channels serialized prior to 0.0.113 and will always be /// zero for objects serialized with LDK versions prior to 0.0.102. /// /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel - /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels user_channel_id: u128, /// The reason the channel was closed. reason: ClosureReason, @@ -1522,13 +1506,10 @@ pub enum Event { /// The `channel_id` of the channel that has a pending splice funding transaction. channel_id: ChannelId, /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound - /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if - /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise - /// `user_channel_id` will be randomized for an inbound channel. + /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels. /// /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel - /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels user_channel_id: u128, /// The `node_id` of the channel counterparty. counterparty_node_id: PublicKey, @@ -1555,13 +1536,10 @@ pub enum Event { /// The `channel_id` of the channel for which the splice failed. channel_id: ChannelId, /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound - /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if - /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise - /// `user_channel_id` will be randomized for an inbound channel. + /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels. /// /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel - /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels user_channel_id: u128, /// The `node_id` of the channel counterparty. counterparty_node_id: PublicKey, @@ -1594,14 +1572,12 @@ pub enum Event { }, /// Indicates a request to open a new channel by a peer. /// + /// This event is triggered for all inbound requests to open a new channel. /// To accept the request (and in the case of a dual-funded channel, not contribute funds), /// call [`ChannelManager::accept_inbound_channel`]. /// To reject the request, call [`ChannelManager::force_close_broadcasting_latest_txn`]. /// Note that a [`ChannelClosed`] event will _not_ be triggered if the channel is rejected. /// - /// The event is only triggered when a new open channel request is received and the - /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. - /// /// # Failure Behavior and Persistence /// This event will eventually be replayed after failures-to-handle (i.e., the event handler /// returning `Err(ReplayEvent ())`) and won't be persisted across restarts. @@ -1609,7 +1585,6 @@ pub enum Event { /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel /// [`ChannelClosed`]: Event::ChannelClosed /// [`ChannelManager::force_close_broadcasting_latest_txn`]: crate::ln::channelmanager::ChannelManager::force_close_broadcasting_latest_txn - /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels OpenChannelRequest { /// The temporary channel ID of the channel requested to be opened. /// @@ -1851,11 +1826,8 @@ pub enum Event { /// /// [`ChannelManager::funding_transaction_signed`]: crate::ln::channelmanager::ChannelManager::funding_transaction_signed counterparty_node_id: PublicKey, - /// The `user_channel_id` value passed in for outbound channels, or for inbound channels if - /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise - /// `user_channel_id` will be randomized for inbound channels. - /// - /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels + /// The `user_channel_id` value passed in for outbound channels, or for inbound + /// channels. user_channel_id: u128, /// The unsigned transaction to be signed and passed back to /// [`ChannelManager::funding_transaction_signed`]. diff --git a/lightning/src/ln/async_payments_tests.rs b/lightning/src/ln/async_payments_tests.rs index 0b2652920e1..1bc08f2c1a1 100644 --- a/lightning/src/ln/async_payments_tests.rs +++ b/lightning/src/ln/async_payments_tests.rs @@ -3059,7 +3059,6 @@ fn intercepted_hold_htlc() { let chanmon_cfgs = create_chanmon_cfgs(4); let node_cfgs = create_node_cfgs(4, &chanmon_cfgs); let (sender_cfg, mut recipient_cfg) = (often_offline_node_cfg(), often_offline_node_cfg()); - recipient_cfg.manually_accept_inbound_channels = true; recipient_cfg.channel_handshake_limits.force_announced_channel_preference = false; let mut lsp_cfg = test_default_channel_config(); diff --git a/lightning/src/ln/async_signer_tests.rs b/lightning/src/ln/async_signer_tests.rs index f38afc41fcc..d57fdec0214 100644 --- a/lightning/src/ln/async_signer_tests.rs +++ b/lightning/src/ln/async_signer_tests.rs @@ -36,12 +36,9 @@ fn test_open_channel() { fn do_test_open_channel(zero_conf: bool) { // Simulate acquiring the commitment point for `open_channel` and `accept_channel` asynchronously. - let mut manually_accept_config = test_default_channel_config(); - manually_accept_config.manually_accept_inbound_channels = zero_conf; - let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(manually_accept_config)]); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let 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(); @@ -88,8 +85,15 @@ fn do_test_open_channel(zero_conf: bool) { ev => panic!("Expected OpenChannelRequest, not {:?}", ev), } } else { - let msgs = nodes[1].node.get_and_clear_pending_msg_events(); - assert!(msgs.is_empty(), "Expected no message events; got {:?}", msgs); + let events = nodes[1].node.get_and_clear_pending_events(); + assert_eq!(events.len(), 1, "Expected one event, got {}", events.len()); + match &events[0] { + Event::OpenChannelRequest { temporary_channel_id, .. } => nodes[1] + .node + .accept_inbound_channel(temporary_channel_id, &node_a_id, 0, None) + .unwrap(), + ev => panic!("Expected OpenChannelRequest, not {:?}", ev), + } } let channel_id_1 = { @@ -130,7 +134,7 @@ fn do_test_funding_created(signer_ops: Vec) { // nodes[0] --- open_channel --> nodes[1] let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); - nodes[1].node.handle_open_channel(node_a_id, &open_chan_msg); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_chan_msg); // nodes[0] <-- accept_channel --- nodes[1] nodes[0].node.handle_accept_channel( @@ -207,7 +211,7 @@ fn do_test_funding_signed(signer_ops: Vec) { // nodes[0] --- open_channel --> nodes[1] let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); - nodes[1].node.handle_open_channel(node_a_id, &open_chan_msg); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_chan_msg); // nodes[0] <-- accept_channel --- nodes[1] nodes[0].node.handle_accept_channel( @@ -364,7 +368,6 @@ fn test_funding_signed_0conf() { fn do_test_funding_signed_0conf(signer_ops: Vec) { // Simulate acquiring the signature for `funding_signed` asynchronously for a zero-conf channel. let mut manually_accept_config = test_default_channel_config(); - manually_accept_config.manually_accept_inbound_channels = true; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); @@ -998,7 +1001,6 @@ fn do_test_async_holder_signatures(keyed_anchors: bool, p2a_anchor: bool, remote let mut config = test_default_channel_config(); config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = keyed_anchors; config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; - config.manually_accept_inbound_channels = keyed_anchors || p2a_anchor; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index ff499d049d4..7d979c7edf5 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -2128,10 +2128,8 @@ fn do_during_funding_monitor_fail( let node_b_id = nodes[1].node.get_our_node_id(); nodes[0].node.create_channel(node_b_id, 100000, 10001, 43, None, None).unwrap(); - nodes[1].node.handle_open_channel( - node_a_id, - &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id), - ); + let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel_msg); nodes[0].node.handle_accept_channel( node_b_id, &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id), @@ -3217,7 +3215,6 @@ fn do_test_outbound_reload_without_init_mon(use_0conf: bool) { let new_chain_monitor; let mut chan_config = test_default_channel_config(); - chan_config.manually_accept_inbound_channels = true; chan_config.channel_handshake_limits.trust_own_funding_0conf = true; let node_chanmgrs = @@ -3327,7 +3324,6 @@ fn do_test_inbound_reload_without_init_mon(use_0conf: bool, lock_commitment: boo let new_chain_monitor; let mut chan_config = test_default_channel_config(); - chan_config.manually_accept_inbound_channels = true; chan_config.channel_handshake_limits.trust_own_funding_0conf = true; let node_chanmgrs = diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index fd780da8d91..0751ed21fe1 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -16280,7 +16280,8 @@ mod tests { // Create Node A's channel pointing to Node B's pubkey let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap()); - let config = UserConfig::default(); + let mut config = UserConfig::default(); + config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = false; let mut node_a_chan = OutboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_init_features(&config), 10000000, 100000, 42, &config, 0, 42, None, &logger).unwrap(); // Create Node B's channel by receiving Node A's open_channel message @@ -16370,7 +16371,8 @@ mod tests { let logger = TestLogger::new(); let node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap()); - let config = UserConfig::default(); + let mut config = UserConfig::default(); + config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = false; let mut chan = OutboundV1Channel::<&TestKeysInterface>::new(&fee_est, &&keys_provider, &&keys_provider, node_id, &channelmanager::provided_init_features(&config), 10000000, 100000, 42, &config, 0, 42, None, &logger).unwrap(); let commitment_tx_fee_0_htlcs = commit_tx_fee_sat(chan.context.feerate_per_kw, 0, chan.funding.get_channel_type()) * 1000; @@ -17770,7 +17772,6 @@ mod tests { // Node id for alice and bob doesn't matter to our test vectors. let bob_node_id = crate::util::test_utils::pubkey(2); let mut config = UserConfig::default(); - config.manually_accept_inbound_channels = true; config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true; let mut chan = OutboundV1Channel::<&Keys>::new( diff --git a/lightning/src/ln/channel_open_tests.rs b/lightning/src/ln/channel_open_tests.rs index 3a9c266aacd..2a1d3f527ca 100644 --- a/lightning/src/ln/channel_open_tests.rs +++ b/lightning/src/ln/channel_open_tests.rs @@ -16,7 +16,8 @@ use crate::chain::{self, ChannelMonitorUpdateStatus}; use crate::events::{ClosureReason, Event, FundingInfo}; use crate::ln::channel::{ get_holder_selected_channel_reserve_satoshis, ChannelError, InboundV1Channel, - OutboundV1Channel, COINBASE_MATURITY, UNFUNDED_CHANNEL_AGE_LIMIT_TICKS, + OutboundV1Channel, COINBASE_MATURITY, MIN_AFFORDABLE_HTLC_COUNT, + UNFUNDED_CHANNEL_AGE_LIMIT_TICKS, }; use crate::ln::channelmanager::{ self, BREAKDOWN_TIMEOUT, MAX_UNFUNDED_CHANNEL_PEERS, MAX_UNFUNDED_CHANS_PER_PEER, @@ -25,7 +26,7 @@ use crate::ln::msgs::{ AcceptChannel, BaseMessageHandler, ChannelMessageHandler, ErrorAction, MessageSendEvent, }; use crate::ln::types::ChannelId; -use crate::ln::{functional_test_utils::*, msgs}; +use crate::ln::{chan_utils, functional_test_utils::*, msgs}; use crate::sign::EntropySource; use crate::util::config::{ ChannelConfigOverrides, ChannelConfigUpdate, ChannelHandshakeConfigUpdate, UserConfig, @@ -62,7 +63,7 @@ fn test_outbound_chans_unlimited() { let mut open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b); for _ in 0..MAX_UNFUNDED_CHANS_PER_PEER { - nodes[1].node.handle_open_channel(node_a, &open_channel_msg); + handle_and_accept_open_channel(&nodes[1], node_a, &open_channel_msg); get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a); open_channel_msg.common_fields.temporary_channel_id = ChannelId::temporary_from_entropy_source(&nodes[0].keys_manager); @@ -90,13 +91,10 @@ fn test_outbound_chans_unlimited() { #[test] fn test_0conf_limiting() { - // Tests that we properly limit inbound channels when we have the manual-channel-acceptance - // flag set and (sometimes) accept channels as 0conf. + // Tests that we properly limit inbound channels but accept channels as 0conf. let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let mut settings = test_default_channel_config(); - settings.manually_accept_inbound_channels = true; - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(settings)]); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // Note that create_network connects the nodes together for us @@ -110,24 +108,14 @@ fn test_0conf_limiting() { }; // First, get us up to MAX_UNFUNDED_CHANNEL_PEERS so we can test at the edge - for _ in 0..MAX_UNFUNDED_CHANNEL_PEERS - 1 { + for _ in 0..MAX_UNFUNDED_CHANNEL_PEERS { let random_pk = PublicKey::from_secret_key( &nodes[0].node.secp_ctx, &SecretKey::from_slice(&nodes[1].keys_manager.get_secure_random_bytes()).unwrap(), ); nodes[1].node.peer_connected(random_pk, init_msg, true).unwrap(); - nodes[1].node.handle_open_channel(random_pk, &open_channel_msg); - let events = nodes[1].node.get_and_clear_pending_events(); - match events[0] { - Event::OpenChannelRequest { temporary_channel_id, .. } => { - nodes[1] - .node - .accept_inbound_channel(&temporary_channel_id, &random_pk, 23, None) - .unwrap(); - }, - _ => panic!("Unexpected event"), - } + handle_and_accept_open_channel(&nodes[1], random_pk, &open_channel_msg); get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, random_pk); open_channel_msg.common_fields.temporary_channel_id = ChannelId::temporary_from_entropy_source(&nodes[0].keys_manager); @@ -185,13 +173,12 @@ fn test_0conf_limiting() { #[test] fn test_inbound_anchors_manual_acceptance() { - let mut anchors_cfg = test_default_channel_config(); - anchors_cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; + let mut anchors_cfg = test_anchors_channel_config(); do_test_manual_inbound_accept_with_override(anchors_cfg, None); } #[test] -fn test_inbound_anchors_manual_acceptance_overridden() { +fn test_inbound_anchors_config_overridden() { let overrides = ChannelConfigOverrides { handshake_overrides: Some(ChannelHandshakeConfigUpdate { max_inbound_htlc_value_in_flight_percent_of_channel: Some(5), @@ -204,9 +191,7 @@ fn test_inbound_anchors_manual_acceptance_overridden() { update_overrides: None, }; - let mut anchors_cfg = test_default_channel_config(); - anchors_cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - + let anchors_cfg = test_anchors_channel_config(); let accept_message = do_test_manual_inbound_accept_with_override(anchors_cfg, Some(overrides)); assert_eq!(accept_message.common_fields.max_htlc_value_in_flight_msat, 5_000_000); assert_eq!(accept_message.common_fields.htlc_minimum_msat, 1_000); @@ -226,15 +211,12 @@ fn test_inbound_zero_fee_commitments_manual_acceptance() { fn do_test_manual_inbound_accept_with_override( start_cfg: UserConfig, config_overrides: Option, ) -> AcceptChannel { - let mut mannual_accept_cfg = start_cfg.clone(); - mannual_accept_cfg.manually_accept_inbound_channels = true; - let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs( 3, &node_cfgs, - &[Some(start_cfg.clone()), Some(start_cfg.clone()), Some(mannual_accept_cfg.clone())], + &[Some(start_cfg.clone()), Some(start_cfg.clone()), Some(start_cfg)], ); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); @@ -243,22 +225,6 @@ fn do_test_manual_inbound_accept_with_override( nodes[0].node.create_channel(node_b, 100_000, 0, 42, None, None).unwrap(); let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b); - nodes[1].node.handle_open_channel(node_a, &open_channel_msg); - assert!(nodes[1].node.get_and_clear_pending_events().is_empty()); - let msg_events = nodes[1].node.get_and_clear_pending_msg_events(); - match &msg_events[0] { - MessageSendEvent::HandleError { node_id, action } => { - assert_eq!(*node_id, node_a); - match action { - ErrorAction::SendErrorMessage { msg } => { - assert_eq!(msg.data, "No channels with anchor outputs accepted".to_owned()) - }, - _ => panic!("Unexpected error action"), - } - }, - _ => panic!("Unexpected event"), - } - nodes[2].node.handle_open_channel(node_a, &open_channel_msg); let events = nodes[2].node.get_and_clear_pending_events(); match events[0] { @@ -281,7 +247,6 @@ fn test_anchors_zero_fee_htlc_tx_downgrade() { let mut receiver_cfg = test_default_channel_config(); receiver_cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - receiver_cfg.manually_accept_inbound_channels = true; let start_type = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(); let end_type = ChannelTypeFeatures::only_static_remote_key(); @@ -303,7 +268,6 @@ fn test_scid_privacy_downgrade() { receiver_cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true; receiver_cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; receiver_cfg.channel_handshake_config.negotiate_scid_privacy = true; - receiver_cfg.manually_accept_inbound_channels = true; let mut start_type = ChannelTypeFeatures::anchors_zero_fee_commitments(); start_type.set_scid_privacy_required(); @@ -328,7 +292,6 @@ fn test_zero_fee_commitments_downgrade() { let mut receiver_cfg = test_default_channel_config(); receiver_cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true; receiver_cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - receiver_cfg.manually_accept_inbound_channels = true; let start_type = ChannelTypeFeatures::anchors_zero_fee_commitments(); let downgrade_types = vec![ @@ -348,7 +311,7 @@ fn test_zero_fee_commitments_downgrade_to_static_remote() { let mut receiver_cfg = test_default_channel_config(); receiver_cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true; - receiver_cfg.manually_accept_inbound_channels = true; + receiver_cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = false; let start_type = ChannelTypeFeatures::anchors_zero_fee_commitments(); let end_type = ChannelTypeFeatures::only_static_remote_key(); @@ -409,7 +372,6 @@ fn test_no_channel_downgrade() { let initiator_cfg = test_default_channel_config(); let mut receiver_cfg = test_default_channel_config(); receiver_cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - receiver_cfg.manually_accept_inbound_channels = true; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); @@ -469,7 +431,7 @@ fn test_channel_resumption_fail_post_funding() { nodes[0].node.create_channel(node_b_id, 1_000_000, 0, 42, None, None).unwrap(); let open_chan = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); - nodes[1].node.handle_open_channel(node_a_id, &open_chan); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_chan); let accept_chan = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); nodes[0].node.handle_accept_channel(node_b_id, &accept_chan); @@ -514,7 +476,12 @@ pub fn test_insane_channel_opens() { let channel_value_sat = 31337; // same as funding satoshis let channel_reserve_satoshis = get_holder_selected_channel_reserve_satoshis(channel_value_sat, &cfg); - let push_msat = (channel_value_sat - channel_reserve_satoshis) * 1000; + let commit_tx_fee = chan_utils::commit_tx_fee_sat( + 253, + MIN_AFFORDABLE_HTLC_COUNT, + &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), + ); + let push_msat = (channel_value_sat - channel_reserve_satoshis - commit_tx_fee) * 1000; // Have node0 initiate a channel to node1 with aforementioned parameters nodes[0].node.create_channel(node_b_id, channel_value_sat, push_msat, 42, None, None).unwrap(); @@ -529,6 +496,22 @@ pub fn test_insane_channel_opens() { |expected_error_str: &str, message_mutator: fn(msgs::OpenChannel) -> msgs::OpenChannel| { let open_channel_mutated = message_mutator(open_channel_message.clone()); nodes[1].node.handle_open_channel(node_a_id, &open_channel_mutated); + let events = nodes[1].node.get_and_clear_pending_events(); + match events[0] { + Event::OpenChannelRequest { + temporary_channel_id, counterparty_node_id, .. + } => match nodes[1].node.accept_inbound_channel( + &temporary_channel_id, + &counterparty_node_id, + 42, + None, + ) { + Err(_) => {}, + _ => panic!(), + }, + _ => panic!("Unexpected event"), + } + let msg_events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(msg_events.len(), 1); let expected_regex = regex::Regex::new(expected_error_str).unwrap(); @@ -625,7 +608,6 @@ pub fn test_insane_channel_opens() { #[xtest(feature = "_externalize_tests")] fn test_insane_zero_fee_channel_open() { let mut cfg = UserConfig::default(); - cfg.manually_accept_inbound_channels = true; cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true; let chanmon_cfgs = create_chanmon_cfgs(2); @@ -746,7 +728,8 @@ fn do_test_sanity_on_in_flight_opens(steps: u8) { if steps & 0x0f == 1 { return; } - nodes[1].node.handle_open_channel(node_a_id, &open_channel); + + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel); let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); if steps & 0x0f == 2 { @@ -925,17 +908,24 @@ pub fn bolt2_open_channel_sane_dust_limit() { node0_to_1_send_open_channel.channel_reserve_satoshis = 100001; nodes[1].node.handle_open_channel(node_a_id, &node0_to_1_send_open_channel); - let events = nodes[1].node.get_and_clear_pending_msg_events(); - let err_msg = match events[0] { - MessageSendEvent::HandleError { - action: ErrorAction::SendErrorMessage { ref msg }, .. - } => msg.clone(), + let events = nodes[1].node.get_and_clear_pending_events(); + match events[0] { + Event::OpenChannelRequest { temporary_channel_id, counterparty_node_id, .. } => match nodes + [1] + .node + .accept_inbound_channel(&temporary_channel_id, &counterparty_node_id, 42, None) + { + Err(APIError::ChannelUnavailable { err }) => assert_eq!( + err, + "dust_limit_satoshis (547) is greater than the implementation limit (546)" + ), + _ => panic!(), + }, _ => panic!("Unexpected event"), - }; - assert_eq!( - err_msg.data, - "dust_limit_satoshis (547) is greater than the implementation limit (546)" - ); + } + let events = nodes[1].node.get_and_clear_pending_msg_events(); + assert_eq!(events.len(), 1); + assert!(matches!(events[0], MessageSendEvent::HandleError { .. })); } #[xtest(feature = "_externalize_tests")] @@ -1022,7 +1012,7 @@ pub fn test_user_configurable_csv_delay() { // We test msg.to_self_delay <= config.their_to_self_delay is enforced in Chanel::accept_channel() nodes[0].node.create_channel(node_b_id, 1000000, 1000000, 42, None, None).unwrap(); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); - nodes[1].node.handle_open_channel(node_a_id, &open_channel); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel); let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); @@ -1078,24 +1068,20 @@ pub fn test_user_configurable_csv_delay() { } #[xtest(feature = "_externalize_tests")] -pub fn test_manually_accept_inbound_channel_request() { - let mut manually_accept_conf = UserConfig::default(); - manually_accept_conf.manually_accept_inbound_channels = true; - manually_accept_conf.channel_handshake_config.minimum_depth = 1; +pub fn test_accept_inbound_channel_config_override() { + let mut conf = UserConfig::default(); + conf.channel_handshake_config.minimum_depth = 1; + conf.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = false; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = - create_node_chanmgrs(2, &node_cfgs, &[None, Some(manually_accept_conf.clone())]); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(conf.clone())]); let 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(); - nodes[0] - .node - .create_channel(node_b_id, 100000, 10001, 42, None, Some(manually_accept_conf)) - .unwrap(); + nodes[0].node.create_channel(node_b_id, 100000, 10001, 42, None, Some(conf)).unwrap(); let res = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); nodes[1].node.handle_open_channel(node_a_id, &res); @@ -1203,28 +1189,19 @@ pub fn test_manually_accept_inbound_channel_request() { } #[xtest(feature = "_externalize_tests")] -pub fn test_manually_reject_inbound_channel_request() { - let mut manually_accept_conf = UserConfig::default(); - manually_accept_conf.manually_accept_inbound_channels = true; +pub fn test_reject_inbound_channel_request() { let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = - create_node_chanmgrs(2, &node_cfgs, &[None, Some(manually_accept_conf.clone())]); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let 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(); - nodes[0] - .node - .create_channel(node_b_id, 100000, 10001, 42, None, Some(manually_accept_conf)) - .unwrap(); + nodes[0].node.create_channel(node_b_id, 100000, 10001, 42, None, None).unwrap(); let res = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); nodes[1].node.handle_open_channel(node_a_id, &res); - - // Assert that `nodes[1]` has no `MessageSendEvent::SendAcceptChannel` in `msg_events` before - // rejecting the inbound channel request. assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); let err = "Channel force-closed".to_string(); let events = nodes[1].node.get_and_clear_pending_events(); @@ -1254,29 +1231,19 @@ pub fn test_manually_reject_inbound_channel_request() { #[xtest(feature = "_externalize_tests")] pub fn test_can_not_accept_inbound_channel_twice() { - let mut manually_accept_conf = UserConfig::default(); - manually_accept_conf.manually_accept_inbound_channels = true; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = - create_node_chanmgrs(2, &node_cfgs, &[None, Some(manually_accept_conf.clone())]); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let 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(); - nodes[0] - .node - .create_channel(node_b_id, 100000, 10001, 42, None, Some(manually_accept_conf)) - .unwrap(); + nodes[0].node.create_channel(node_b_id, 100000, 10001, 42, None, None).unwrap(); let res = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); nodes[1].node.handle_open_channel(node_a_id, &res); - - // Assert that `nodes[1]` has no `MessageSendEvent::SendAcceptChannel` in `msg_events` before - // accepting the inbound channel request. assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); - let events = nodes[1].node.get_and_clear_pending_events(); match events[0] { Event::OpenChannelRequest { temporary_channel_id, .. } => { @@ -1359,7 +1326,7 @@ pub fn test_duplicate_temporary_channel_id_from_different_peers() { // Assert that `nodes[0]` can accept both `OpenChannel` requests, even though they use the same // `temporary_channel_id` as they are from different peers. - nodes[0].node.handle_open_channel(node_b_id, &open_chan_msg_chan_1_0); + handle_and_accept_open_channel(&nodes[0], node_b_id, &open_chan_msg_chan_1_0); { let events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -1375,7 +1342,7 @@ pub fn test_duplicate_temporary_channel_id_from_different_peers() { } } - nodes[0].node.handle_open_channel(node_c_id, &open_chan_msg_chan_2_0); + handle_and_accept_open_channel(&nodes[0], node_c_id, &open_chan_msg_chan_2_0); { let events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -1416,7 +1383,8 @@ pub fn test_duplicate_funding_err_in_funding() { let mut open_chan_msg = get_event_msg!(nodes[2], MessageSendEvent::SendOpenChannel, node_b_id); let node_c_temp_chan_id = open_chan_msg.common_fields.temporary_channel_id; open_chan_msg.common_fields.temporary_channel_id = real_channel_id; - nodes[1].node.handle_open_channel(node_c_id, &open_chan_msg); + handle_and_accept_open_channel(&nodes[1], node_c_id, &open_chan_msg); + let mut accept_chan_msg = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_c_id); accept_chan_msg.common_fields.temporary_channel_id = node_c_temp_chan_id; @@ -1461,7 +1429,7 @@ pub fn test_duplicate_chan_id() { // Create an initial channel nodes[0].node.create_channel(node_b_id, 100000, 10001, 42, None, None).unwrap(); let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); - nodes[1].node.handle_open_channel(node_a_id, &open_chan_msg); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_chan_msg); nodes[0].node.handle_accept_channel( node_b_id, &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id), @@ -1548,7 +1516,7 @@ pub fn test_duplicate_chan_id() { // Now try to create a second channel which has a duplicate funding output. nodes[0].node.create_channel(node_b_id, 100000, 10001, 42, None, None).unwrap(); let open_chan_2_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); - nodes[1].node.handle_open_channel(node_a_id, &open_chan_2_msg); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_chan_2_msg); nodes[0].node.handle_accept_channel( node_b_id, &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id), @@ -1652,10 +1620,8 @@ pub fn test_invalid_funding_tx() { let node_b_id = nodes[1].node.get_our_node_id(); nodes[0].node.create_channel(node_b_id, 100_000, 10_000, 42, None, None).unwrap(); - nodes[1].node.handle_open_channel( - node_a_id, - &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id), - ); + let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel_msg); nodes[0].node.handle_accept_channel( node_b_id, &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id), @@ -1769,10 +1735,9 @@ pub fn test_coinbase_funding_tx() { nodes[0].node.create_channel(node_b_id, 100000, 10001, 42, None, None).unwrap(); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel); - nodes[1].node.handle_open_channel(node_a_id, &open_channel); let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); - nodes[0].node.handle_accept_channel(node_b_id, &accept_channel); // Create the coinbase funding transaction. @@ -1831,7 +1796,8 @@ pub fn test_non_final_funding_tx() { nodes[0].node.create_channel(node_b_id, 100_000, 0, 42, None, None).unwrap(); let open_channel_message = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); - nodes[1].node.handle_open_channel(node_a_id, &open_channel_message); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel_message); + let accept_channel_message = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); nodes[0].node.handle_accept_channel(node_b_id, &accept_channel_message); @@ -1890,7 +1856,8 @@ pub fn test_non_final_funding_tx_within_headroom() { nodes[0].node.create_channel(node_b_id, 100_000, 0, 42, None, None).unwrap(); let open_channel_message = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); - nodes[1].node.handle_open_channel(node_a_id, &open_channel_message); + // nodes[1].node.handle_open_channel(node_a_id, &open_channel_message); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel_message); let accept_channel_message = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); nodes[0].node.handle_accept_channel(node_b_id, &accept_channel_message); @@ -2364,7 +2331,6 @@ pub fn test_accept_inbound_channel_errors_queued() { let mut config0 = test_default_channel_config(); let mut config1 = config0.clone(); config1.channel_handshake_limits.their_to_self_delay = 1000; - config1.manually_accept_inbound_channels = true; config0.channel_handshake_config.our_to_self_delay = 2000; let chanmon_cfgs = create_chanmon_cfgs(2); @@ -2410,8 +2376,8 @@ pub fn test_manual_funding_abandon() { assert!(nodes[0].node.create_channel(node_b_id, 100_000, 0, 42, None, None).is_ok()); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel); - nodes[1].node.handle_open_channel(node_a_id, &open_channel); let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); nodes[0].node.handle_accept_channel(node_b_id, &accept_channel); @@ -2459,10 +2425,9 @@ pub fn test_funding_signed_event() { assert!(nodes[0].node.create_channel(node_b_id, 100_000, 0, 42, None, None).is_ok()); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel); - nodes[1].node.handle_open_channel(node_a_id, &open_channel); let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); - nodes[0].node.handle_accept_channel(node_b_id, &accept_channel); let (temp_channel_id, tx, funding_outpoint) = create_funding_transaction(&nodes[0], &node_b_id, 100_000, 42); diff --git a/lightning/src/ln/channel_state.rs b/lightning/src/ln/channel_state.rs index d10327b259a..024c83633e9 100644 --- a/lightning/src/ln/channel_state.rs +++ b/lightning/src/ln/channel_state.rs @@ -368,14 +368,11 @@ pub struct ChannelDetails { /// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat pub unspendable_punishment_reserve: Option, /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound - /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if - /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise - /// `user_channel_id` will be randomized for an inbound channel. This may be zero for objects - /// serialized with LDK versions prior to 0.0.113. + /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels. + /// This may be zero for objects serialized with LDK versions prior to 0.0.113. /// /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel - /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels pub user_channel_id: u128, /// The currently negotiated fee rate denominated in satoshi per 1000 weight units, /// which is applied to commitment and HTLC transactions. diff --git a/lightning/src/ln/channel_type_tests.rs b/lightning/src/ln/channel_type_tests.rs index 13470d50614..2b069a6d314 100644 --- a/lightning/src/ln/channel_type_tests.rs +++ b/lightning/src/ln/channel_type_tests.rs @@ -34,8 +34,10 @@ fn test_option_anchors_zero_fee_initial() { let mut expected_type = ChannelTypeFeatures::only_static_remote_key(); expected_type.set_anchors_zero_fee_htlc_tx_required(); + let mut start_cfg = UserConfig::default(); + start_cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = false; do_test_get_initial_channel_type( - UserConfig::default(), + start_cfg, InitFeatures::empty(), ChannelTypeFeatures::only_static_remote_key(), |cfg: &mut UserConfig| { @@ -225,13 +227,15 @@ fn do_test_supports_channel_type(config: UserConfig, expected_channel_type: Chan let node_id_b = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[2; 32]).unwrap()); + let mut non_anchors_config = UserConfig::default(); + non_anchors_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = false; // Assert that we get `static_remotekey` when no custom config is negotiated. let channel_a = OutboundV1Channel::<&TestKeysInterface>::new( &fee_estimator, &&keys_provider, &&keys_provider, node_id_b, - &channelmanager::provided_init_features(&UserConfig::default()), + &channelmanager::provided_init_features(&non_anchors_config), 10000000, 100000, 42, diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 10c77505408..607ce8659ef 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -1567,10 +1567,10 @@ where pub(super) channel_by_id: HashMap>, /// `temporary_channel_id` -> `InboundChannelRequest`. /// - /// When manual channel acceptance is enabled, this holds all unaccepted inbound channels where - /// the peer is the counterparty. If the channel is accepted, then the entry in this table is - /// removed, and an InboundV1Channel is created and placed in the `inbound_v1_channel_by_id` table. If - /// the channel is rejected, then the entry is simply removed. + /// Holds all unaccepted inbound channels where the peer is the counterparty. + /// If the channel is accepted, then the entry in this table is removed and a Channel is + /// created and placed in the `channel_by_id` table. If the channel is rejected, then + /// the entry is simply removed. pub(super) inbound_channel_request_by_id: HashMap, /// The latest `InitFeatures` we heard from the peer. latest_features: InitFeatures, @@ -2053,7 +2053,7 @@ where /// /// ## Opening Channels /// -/// To an open a channel with a peer, call [`create_channel`]. This will initiate the process of +/// To open a channel with a peer, call [`create_channel`]. This will initiate the process of /// opening an outbound channel, which requires self-funding when handling /// [`Event::FundingGenerationReady`]. /// @@ -2117,9 +2117,8 @@ where /// /// ## Accepting Channels /// -/// Inbound channels are initiated by peers and are automatically accepted unless [`ChannelManager`] -/// has [`UserConfig::manually_accept_inbound_channels`] set. In that case, the channel may be -/// either accepted or rejected when handling [`Event::OpenChannelRequest`]. +/// Inbound channels are initiated by peers and must be manually accepted or rejected when +/// handling [`Event::OpenChannelRequest`]. /// /// ``` /// # use bitcoin::secp256k1::PublicKey; @@ -5395,7 +5394,7 @@ where /// using [`ChannelMonitorUpdateStatus::InProgress`]), the payment may be lost on restart. See /// [`ChannelManager::list_recent_payments`] for more information. /// - /// Routes are automatically found using the [`Router] provided on startup. To fix a route for a + /// Routes are automatically found using the [`Router`] provided on startup. To fix a route for a /// particular payment, use [`Self::send_payment_with_route`] or match the [`PaymentId`] passed to /// [`Router::find_route_with_id`]. /// @@ -10341,7 +10340,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ ) } - /// Accepts a request to open a channel after a [`events::Event::OpenChannelRequest`], treating + /// Accepts a request to open a channel after a [`Event::OpenChannelRequest`], treating /// it as confirmed immediately. /// /// The `user_channel_id` parameter will be provided back in @@ -10528,7 +10527,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ // If this peer already has some channels, a new channel won't increase our number of peers // with unfunded channels, so as long as we aren't over the maximum number of unfunded // channels per-peer we can accept channels from a peer with existing ones. - if is_only_peer_channel && peers_without_funded_channels >= MAX_UNFUNDED_CHANNEL_PEERS { + if is_only_peer_channel && peers_without_funded_channels > MAX_UNFUNDED_CHANNEL_PEERS { let send_msg_err_event = MessageSendEvent::HandleError { node_id: channel.context().get_counterparty_node_id(), action: msgs::ErrorAction::SendErrorMessage { @@ -10631,8 +10630,9 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ num_unfunded_channels + peer.inbound_channel_request_by_id.len() } - #[rustfmt::skip] - fn internal_open_channel(&self, counterparty_node_id: &PublicKey, msg: OpenChannelMessageRef<'_>) -> Result<(), MsgHandleErrInternal> { + fn internal_open_channel( + &self, counterparty_node_id: &PublicKey, msg: OpenChannelMessageRef<'_>, + ) -> Result<(), MsgHandleErrInternal> { let common_fields = match msg { OpenChannelMessageRef::V1(msg) => &msg.common_fields, OpenChannelMessageRef::V2(msg) => &msg.common_fields, @@ -10643,49 +10643,37 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ // Note that the ChannelManager is NOT re-persisted on disk after this, so any changes are // likely to be lost on restart! if common_fields.chain_hash != self.chain_hash { - return Err(MsgHandleErrInternal::send_err_msg_no_close("Unknown genesis block hash".to_owned(), - common_fields.temporary_channel_id)); + return Err(MsgHandleErrInternal::send_err_msg_no_close( + "Unknown genesis block hash".to_owned(), + common_fields.temporary_channel_id, + )); } if !self.config.read().unwrap().accept_inbound_channels { - return Err(MsgHandleErrInternal::send_err_msg_no_close("No inbound channels accepted".to_owned(), - common_fields.temporary_channel_id)); + return Err(MsgHandleErrInternal::send_err_msg_no_close( + "No inbound channels accepted".to_owned(), + common_fields.temporary_channel_id, + )); } - // Get the number of peers with channels, but without funded ones. We don't care too much - // about peers that never open a channel, so we filter by peers that have at least one - // channel, and then limit the number of those with unfunded channels. - let channeled_peers_without_funding = - self.peers_without_funded_channels(|node| node.total_channel_count() > 0); - let per_peer_state = self.per_peer_state.read().unwrap(); - let peer_state_mutex = per_peer_state.get(counterparty_node_id) - .ok_or_else(|| { - debug_assert!(false); - MsgHandleErrInternal::send_err_msg_no_close( + let peer_state_mutex = per_peer_state.get(counterparty_node_id).ok_or_else(|| { + debug_assert!(false); + MsgHandleErrInternal::send_err_msg_no_close( format!("Can't find a peer matching the passed counterparty node_id {counterparty_node_id}"), common_fields.temporary_channel_id) - })?; + })?; let mut peer_state_lock = peer_state_mutex.lock().unwrap(); let peer_state = &mut *peer_state_lock; - // If this peer already has some channels, a new channel won't increase our number of peers - // with unfunded channels, so as long as we aren't over the maximum number of unfunded - // channels per-peer we can accept channels from a peer with existing ones. - if peer_state.total_channel_count() == 0 && - channeled_peers_without_funding >= MAX_UNFUNDED_CHANNEL_PEERS && - !self.config.read().unwrap().manually_accept_inbound_channels - { - return Err(MsgHandleErrInternal::send_err_msg_no_close( - "Have too many peers with unfunded channels, not accepting new ones".to_owned(), - common_fields.temporary_channel_id)); - } - let best_block_height = self.best_block.read().unwrap().height; - if Self::unfunded_channel_count(peer_state, best_block_height) >= MAX_UNFUNDED_CHANS_PER_PEER { + if Self::unfunded_channel_count(peer_state, best_block_height) + >= MAX_UNFUNDED_CHANS_PER_PEER + { return Err(MsgHandleErrInternal::send_err_msg_no_close( format!("Refusing more than {} unfunded channels.", MAX_UNFUNDED_CHANS_PER_PEER), - common_fields.temporary_channel_id)); + common_fields.temporary_channel_id, + )); } let channel_id = common_fields.temporary_channel_id; @@ -10693,20 +10681,22 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ if channel_exists { return Err(MsgHandleErrInternal::send_err_msg_no_close( "temporary_channel_id collision for the same peer!".to_owned(), - common_fields.temporary_channel_id)); + common_fields.temporary_channel_id, + )); } // We can get the channel type at this point already as we'll need it immediately in both the // manual and the automatic acceptance cases. - let channel_type = channel::channel_type_from_open_channel( - common_fields, &self.channel_type_features() - ).map_err(|e| MsgHandleErrInternal::from_chan_no_close(e, common_fields.temporary_channel_id))?; + let channel_type = + channel::channel_type_from_open_channel(common_fields, &self.channel_type_features()) + .map_err(|e| { + MsgHandleErrInternal::from_chan_no_close(e, common_fields.temporary_channel_id) + })?; - // If we're doing manual acceptance checks on the channel, then defer creation until we're sure we want to accept. - if self.config.read().unwrap().manually_accept_inbound_channels { - let mut pending_events = self.pending_events.lock().unwrap(); - let is_announced = (common_fields.channel_flags & 1) == 1; - pending_events.push_back((events::Event::OpenChannelRequest { + let mut pending_events = self.pending_events.lock().unwrap(); + let is_announced = (common_fields.channel_flags & 1) == 1; + pending_events.push_back(( + events::Event::OpenChannelRequest { temporary_channel_id: common_fields.temporary_channel_id, counterparty_node_id: *counterparty_node_id, funding_satoshis: common_fields.funding_satoshis, @@ -10717,67 +10707,19 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ channel_type, is_announced, params: common_fields.channel_parameters(), - }, None)); - peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest { + }, + None, + )); + peer_state.inbound_channel_request_by_id.insert( + channel_id, + InboundChannelRequest { open_channel_msg: match msg { OpenChannelMessageRef::V1(msg) => OpenChannelMessage::V1(msg.clone()), OpenChannelMessageRef::V2(msg) => OpenChannelMessage::V2(msg.clone()), }, ticks_remaining: UNACCEPTED_INBOUND_CHANNEL_AGE_LIMIT_TICKS, - }); - return Ok(()); - } - - // Otherwise create the channel right now. - let mut random_bytes = [0u8; 16]; - random_bytes.copy_from_slice(&self.entropy_source.get_secure_random_bytes()[..16]); - let user_channel_id = u128::from_be_bytes(random_bytes); - - if channel_type.requires_zero_conf() { - return Err(MsgHandleErrInternal::send_err_msg_no_close("No zero confirmation channels accepted".to_owned(), common_fields.temporary_channel_id)); - } - if channel_type.requires_anchors_zero_fee_htlc_tx() || channel_type.requires_anchor_zero_fee_commitments() { - return Err(MsgHandleErrInternal::send_err_msg_no_close("No channels with anchor outputs accepted".to_owned(), common_fields.temporary_channel_id)); - } - - let (mut channel, message_send_event) = match msg { - OpenChannelMessageRef::V1(msg) => { - let mut channel = InboundV1Channel::new( - &self.fee_estimator, &self.entropy_source, &self.signer_provider, *counterparty_node_id, - &self.channel_type_features(), &peer_state.latest_features, msg, user_channel_id, - &self.config.read().unwrap(), best_block_height, &self.logger, /*is_0conf=*/false - ).map_err(|e| MsgHandleErrInternal::from_chan_no_close(e, msg.common_fields.temporary_channel_id))?; - let logger = WithChannelContext::from(&self.logger, &channel.context, None); - let message_send_event = channel.accept_inbound_channel(&&logger).map(|msg| { - MessageSendEvent::SendAcceptChannel { - node_id: *counterparty_node_id, - msg, - } - }); - (Channel::from(channel), message_send_event) }, - OpenChannelMessageRef::V2(msg) => { - let channel = PendingV2Channel::new_inbound( - &self.fee_estimator, &self.entropy_source, &self.signer_provider, - self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(), - &peer_state.latest_features, msg, user_channel_id, - &self.config.read().unwrap(), best_block_height, &self.logger, - ).map_err(|e| MsgHandleErrInternal::from_chan_no_close(e, msg.common_fields.temporary_channel_id))?; - let message_send_event = MessageSendEvent::SendAcceptChannelV2 { - node_id: *counterparty_node_id, - msg: channel.accept_inbound_dual_funded_channel(), - }; - (Channel::from(channel), Some(message_send_event)) - }, - }; - - let outbound_scid_alias = self.create_and_insert_outbound_scid_alias(); - channel.context_mut().set_outbound_scid_alias(outbound_scid_alias); - - if let Some(message_send_event) = message_send_event { - peer_state.pending_msg_events.push(message_send_event); - } - peer_state.channel_by_id.insert(channel.context().channel_id(), channel); + ); Ok(()) } @@ -20108,7 +20050,7 @@ mod tests { let mut funding_tx = None; for idx in 0..super::MAX_UNFUNDED_CHANS_PER_PEER { - nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg); + handle_and_accept_open_channel(&nodes[1], nodes[0].node.get_our_node_id(), &open_channel_msg); let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); if idx == 0 { @@ -20182,11 +20124,23 @@ mod tests { // open channels. assert!(peer_pks.len() > super::MAX_UNFUNDED_CHANNEL_PEERS - 1); for i in 0..super::MAX_UNFUNDED_CHANNEL_PEERS - 1 { - nodes[1].node.handle_open_channel(peer_pks[i], &open_channel_msg); + handle_and_accept_open_channel(&nodes[1], peer_pks[i], &open_channel_msg); get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, peer_pks[i]); open_channel_msg.common_fields.temporary_channel_id = ChannelId::temporary_from_entropy_source(&nodes[0].keys_manager); } + nodes[1].node.handle_open_channel(last_random_pk, &open_channel_msg); + let events = nodes[1].node.get_and_clear_pending_events(); + match events[0] { + Event::OpenChannelRequest { temporary_channel_id, .. } => { + assert!(nodes[1] + .node + .accept_inbound_channel(&temporary_channel_id, &last_random_pk, 23, None,) + .is_err()) + }, + _ => panic!("Unexpected event"), + } + assert_eq!(get_err_msg(&nodes[1], &last_random_pk).channel_id, open_channel_msg.common_fields.temporary_channel_id); @@ -20204,7 +20158,7 @@ mod tests { // Further, because the first channel was funded, we can open another channel with // last_random_pk. - nodes[1].node.handle_open_channel(last_random_pk, &open_channel_msg); + handle_and_accept_open_channel(&nodes[1], last_random_pk, &open_channel_msg); get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, last_random_pk); } diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 2cf5ea96acb..fa8947673e8 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -30,7 +30,7 @@ use crate::ln::channelmanager::{ RAACommitmentOrder, RecipientOnionFields, MIN_CLTV_EXPIRY_DELTA, }; use crate::ln::funding::FundingTxInput; -use crate::ln::msgs; +use crate::ln::msgs::{self, OpenChannel}; use crate::ln::msgs::{ BaseMessageHandler, ChannelMessageHandler, MessageSendEvent, RoutingMessageHandler, }; @@ -1551,7 +1551,6 @@ pub fn sign_funding_transaction<'a, 'b, 'c>( tx } -// Receiver must have been initialized with manually_accept_inbound_channels set to true. pub fn open_zero_conf_channel<'a, 'b, 'c, 'd>( initiator: &'a Node<'b, 'c, 'd>, receiver: &'a Node<'b, 'c, 'd>, initiator_config: Option, @@ -1599,7 +1598,6 @@ pub fn exchange_open_accept_zero_conf_chan<'a, 'b, 'c, 'd>( accept_channel.common_fields.temporary_channel_id } -// Receiver must have been initialized with manually_accept_inbound_channels set to true. pub fn open_zero_conf_channel_with_value<'a, 'b, 'c, 'd>( initiator: &'a Node<'b, 'c, 'd>, receiver: &'a Node<'b, 'c, 'd>, initiator_config: Option, channel_value_sat: u64, push_msat: u64, @@ -1698,17 +1696,17 @@ pub fn exchange_open_accept_chan<'a, 'b, 'c>( 42 ); node_b.node.handle_open_channel(node_a_id, &open_channel_msg); - if node_b.node.get_current_config().manually_accept_inbound_channels { - let events = node_b.node.get_and_clear_pending_events(); - assert_eq!(events.len(), 1); - match &events[0] { - Event::OpenChannelRequest { temporary_channel_id, counterparty_node_id, .. } => node_b - .node - .accept_inbound_channel(temporary_channel_id, counterparty_node_id, 42, None) - .unwrap(), - _ => panic!("Unexpected event"), - }; - } + + let events = node_b.node.get_and_clear_pending_events(); + assert_eq!(events.len(), 1); + match &events[0] { + Event::OpenChannelRequest { temporary_channel_id, counterparty_node_id, .. } => node_b + .node + .accept_inbound_channel(temporary_channel_id, counterparty_node_id, 42, None) + .unwrap(), + _ => panic!("Unexpected event"), + }; + let accept_channel_msg = get_event_msg!(node_b, MessageSendEvent::SendAcceptChannel, node_a_id); assert_eq!(accept_channel_msg.common_fields.temporary_channel_id, create_chan_id); node_a.node.handle_accept_channel(node_b_id, &accept_channel_msg); @@ -1990,6 +1988,19 @@ pub fn create_unannounced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>( .unwrap(); let open_channel = get_event_msg!(nodes[a], MessageSendEvent::SendOpenChannel, node_b_id); nodes[b].node.handle_open_channel(node_a_id, &open_channel); + + let events = nodes[b].node.get_and_clear_pending_events(); + assert_eq!(events.len(), 1); + match &events[0] { + Event::OpenChannelRequest { temporary_channel_id, counterparty_node_id, .. } => { + nodes[b] + .node + .accept_inbound_channel(temporary_channel_id, counterparty_node_id, 42, None) + .unwrap(); + }, + _ => panic!("Unexpected event"), + }; + let accept_channel = get_event_msg!(nodes[b], MessageSendEvent::SendAcceptChannel, node_a_id); nodes[a].node.handle_accept_channel(node_b_id, &accept_channel); @@ -2057,6 +2068,20 @@ pub fn create_unannounced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>( (as_channel_ready, tx) } +pub fn handle_and_accept_open_channel(node: &Node, counterparty_id: PublicKey, msg: &OpenChannel) { + node.node.handle_open_channel(counterparty_id, &msg); + let events = node.node.get_and_clear_pending_events(); + assert_eq!(events.len(), 1); + match &events[0] { + Event::OpenChannelRequest { temporary_channel_id, counterparty_node_id, .. } => { + node.node + .accept_inbound_channel(temporary_channel_id, counterparty_node_id, 42, None) + .unwrap(); + }, + _ => panic!("Unexpected event"), + }; +} + pub fn update_nodes_with_chan_announce<'a, 'b, 'c, 'd>( nodes: &'a Vec>, a: usize, b: usize, ann: &msgs::ChannelAnnouncement, upd_1: &msgs::ChannelUpdate, upd_2: &msgs::ChannelUpdate, @@ -4530,6 +4555,8 @@ pub fn create_node_cfgs_with_node_id_message_router<'a>( pub fn test_default_channel_config() -> UserConfig { let mut default_config = UserConfig::default(); + default_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = false; + // Set cltv_expiry_delta slightly lower to keep the final CLTV values inside one byte in our // tests so that our script-length checks don't fail (see ACCEPTED_HTLC_SCRIPT_WEIGHT). default_config.channel_config.cltv_expiry_delta = MIN_CLTV_EXPIRY_DELTA; @@ -4547,10 +4574,9 @@ pub fn test_default_channel_config() -> UserConfig { default_config } -pub fn test_default_anchors_channel_config() -> UserConfig { +pub fn test_anchors_channel_config() -> UserConfig { let mut config = test_default_channel_config(); config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - config.manually_accept_inbound_channels = true; config } @@ -5558,7 +5584,8 @@ pub fn create_batch_channel_funding<'a, 'b, 'c>( .unwrap(); let open_channel_msg = get_event_msg!(funding_node, MessageSendEvent::SendOpenChannel, other_node_id); - other_node.node.handle_open_channel(funding_node_id, &open_channel_msg); + handle_and_accept_open_channel(other_node, funding_node_id, &open_channel_msg); + let accept_channel_msg = get_event_msg!(other_node, MessageSendEvent::SendAcceptChannel, funding_node_id); funding_node.node.handle_accept_channel(other_node_id, &accept_channel_msg); diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index fcb348c690d..eb330b61068 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -1163,7 +1163,6 @@ pub fn do_test_multiple_package_conflicts(p2a_anchor: bool) { // transaction. user_cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; user_cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; - user_cfg.manually_accept_inbound_channels = true; let configs = [Some(user_cfg.clone()), Some(user_cfg.clone()), Some(user_cfg)]; let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &configs); @@ -2505,7 +2504,7 @@ pub fn test_peer_disconnected_before_funding_broadcasted() { let expected_temporary_channel_id = nodes[0].node.create_channel(node_b_id, 1_000_000, 500_000_000, 42, None, None).unwrap(); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); - nodes[1].node.handle_open_channel(node_a_id, &open_channel); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel); let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); nodes[0].node.handle_accept_channel(node_b_id, &accept_channel); @@ -6364,11 +6363,11 @@ pub fn test_bump_penalty_txn_on_revoked_htlcs() { assert_eq!( node_txn[1].input[0].previous_output, - revoked_htlc_txn[1].input[0].previous_output + revoked_htlc_txn[0].input[0].previous_output ); assert_eq!( node_txn[1].input[1].previous_output, - revoked_htlc_txn[0].input[0].previous_output + revoked_htlc_txn[1].input[0].previous_output ); // node_txn[3] spends the revoked outputs from the revoked_htlc_txn (which only have one @@ -6786,7 +6785,7 @@ pub fn test_override_0msat_htlc_minimum() { let res = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); assert_eq!(res.common_fields.htlc_minimum_msat, 1); - nodes[1].node.handle_open_channel(node_a_id, &res); + handle_and_accept_open_channel(&nodes[1], node_a_id, &res); let res = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); assert_eq!(res.common_fields.htlc_minimum_msat, 1); } @@ -7565,7 +7564,7 @@ pub fn test_pre_lockin_no_chan_closed_update() { // Create an initial channel nodes[0].node.create_channel(node_b_id, 100000, 10001, 42, None, None).unwrap(); let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); - nodes[1].node.handle_open_channel(node_a_id, &open_chan_msg); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_chan_msg); let accept_chan_msg = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); nodes[0].node.handle_accept_channel(node_b_id, &accept_chan_msg); @@ -7884,9 +7883,8 @@ pub fn test_peer_funding_sidechannel() { let node_b_id = nodes[1].node.get_our_node_id(); let temp_chan_id_ab = exchange_open_accept_chan(&nodes[0], &nodes[1], 1_000_000, 0); - let temp_chan_id_ca = exchange_open_accept_chan(&nodes[1], &nodes[0], 1_000_000, 0); - let (_, tx, funding_output) = create_funding_transaction(&nodes[0], &node_b_id, 1_000_000, 42); + let temp_chan_id_ba = exchange_open_accept_chan(&nodes[1], &nodes[0], 1_000_000, 0); let cs_funding_events = nodes[1].node.get_and_clear_pending_events(); assert_eq!(cs_funding_events.len(), 1); @@ -7898,7 +7896,7 @@ pub fn test_peer_funding_sidechannel() { let output_idx = funding_output.index; nodes[1] .node - .funding_transaction_generated_unchecked(temp_chan_id_ca, node_a_id, tx.clone(), output_idx) + .funding_transaction_generated_unchecked(temp_chan_id_ba, node_a_id, tx.clone(), output_idx) .unwrap(); let funding_created_msg = get_event_msg!(nodes[1], MessageSendEvent::SendFundingCreated, node_a_id); @@ -8602,7 +8600,7 @@ fn do_test_max_dust_htlc_exposure( if on_holder_tx { open_channel.common_fields.dust_limit_satoshis = 546; } - nodes[1].node.handle_open_channel(node_a_id, &open_channel); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel); let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); nodes[0].node.handle_accept_channel(node_b_id, &accept_channel); @@ -9157,7 +9155,6 @@ fn do_test_nondust_htlc_fees_dust_exposure_delta(features: ChannelTypeFeatures) if features == ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies() { default_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; // in addition to the one above, this setting is also needed to create an anchor channel - default_config.manually_accept_inbound_channels = true; } // Set node 1's max dust htlc exposure to 1msat below `expected_dust_exposure_msat` @@ -9565,7 +9562,8 @@ pub fn test_remove_expired_outbound_unfunded_channels() { nodes[0].node.create_channel(node_b_id, 100_000, 0, 42, None, None).unwrap(); let open_channel_message = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); - nodes[1].node.handle_open_channel(node_a_id, &open_channel_message); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel_message); + let accept_channel_message = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); nodes[0].node.handle_accept_channel(node_b_id, &accept_channel_message); @@ -9629,7 +9627,8 @@ pub fn test_remove_expired_inbound_unfunded_channels() { nodes[0].node.create_channel(node_b_id, 100_000, 0, 42, None, None).unwrap(); let open_channel_message = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); - nodes[1].node.handle_open_channel(node_a_id, &open_channel_message); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel_message); + let accept_channel_message = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); nodes[0].node.handle_accept_channel(node_b_id, &accept_channel_message); @@ -9688,9 +9687,6 @@ fn do_test_manual_broadcast_skips_commitment_until_funding( let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let mut chan_config = test_default_channel_config(); - if zero_conf_open { - chan_config.manually_accept_inbound_channels = true; - } let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(chan_config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); diff --git a/lightning/src/ln/htlc_reserve_unit_tests.rs b/lightning/src/ln/htlc_reserve_unit_tests.rs index 4c4fbada7dd..e719f5efa74 100644 --- a/lightning/src/ln/htlc_reserve_unit_tests.rs +++ b/lightning/src/ln/htlc_reserve_unit_tests.rs @@ -59,7 +59,7 @@ fn do_test_counterparty_no_reserve(send_from_initiator: bool) { open_channel_message.channel_reserve_satoshis = 0; open_channel_message.common_fields.max_htlc_value_in_flight_msat = 100_000_000; } - nodes[1].node.handle_open_channel(node_a_id, &open_channel_message); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel_message); // Extract the channel accept message from node1 to node0 let mut accept_channel_message = @@ -785,7 +785,6 @@ fn test_fee_spike_violation_fails_htlc() { fn test_zero_fee_commitments_no_fee_spike_buffer() { let mut cfg = test_default_channel_config(); cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true; - cfg.manually_accept_inbound_channels = true; do_test_fee_spike_buffer(Some(cfg), false) } @@ -2144,7 +2143,6 @@ pub fn do_test_dust_limit_fee_accounting(can_afford: bool) { let mut default_config = test_default_channel_config(); default_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - default_config.manually_accept_inbound_channels = true; let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = diff --git a/lightning/src/ln/invoice_utils.rs b/lightning/src/ln/invoice_utils.rs index e72ea4518a4..9da27a23f5c 100644 --- a/lightning/src/ln/invoice_utils.rs +++ b/lightning/src/ln/invoice_utils.rs @@ -1061,7 +1061,8 @@ mod test { .create_channel(node_a_id, 1_000_000, 500_000_000, 42, None, Some(private_chan_cfg)) .unwrap(); let open_channel = get_event_msg!(nodes[2], MessageSendEvent::SendOpenChannel, node_a_id); - nodes[0].node.handle_open_channel(node_c_id, &open_channel); + handle_and_accept_open_channel(&nodes[0], node_c_id, &open_channel); + let accept_channel = get_event_msg!(nodes[0], MessageSendEvent::SendAcceptChannel, node_c_id); nodes[2].node.handle_accept_channel(node_a_id, &accept_channel); @@ -1591,7 +1592,7 @@ mod test { .create_channel(node_d_id, 1_000_000, 500_000_000, 42, None, Some(private_chan_cfg)) .unwrap(); let open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, node_d_id); - nodes[3].node.handle_open_channel(nodes[1].node.get_our_node_id(), &open_channel); + handle_and_accept_open_channel(&nodes[3], node_b_id, &open_channel); let accept_channel = get_event_msg!(nodes[3], MessageSendEvent::SendAcceptChannel, node_b_id); nodes[1].node.handle_accept_channel(nodes[3].node.get_our_node_id(), &accept_channel); diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index 04915affa20..439f4c3fded 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -318,10 +318,8 @@ fn do_chanmon_claim_value_coop_close(keyed_anchors: bool, p2a_anchor: bool) { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let mut user_config = test_default_channel_config(); user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - user_config.manually_accept_inbound_channels = true; user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = keyed_anchors; user_config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; - user_config.manually_accept_inbound_channels = keyed_anchors || p2a_anchor; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(user_config.clone()), Some(user_config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -472,7 +470,6 @@ fn do_test_claim_value_force_close(keyed_anchors: bool, p2a_anchor: bool, prev_c let mut user_config = test_default_channel_config(); user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = keyed_anchors; user_config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; - user_config.manually_accept_inbound_channels = keyed_anchors || p2a_anchor; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(user_config.clone()), Some(user_config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -871,7 +868,6 @@ fn do_test_balances_on_local_commitment_htlcs(keyed_anchors: bool, p2a_anchor: b let mut user_config = test_default_channel_config(); user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = keyed_anchors; user_config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; - user_config.manually_accept_inbound_channels = keyed_anchors || p2a_anchor; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(user_config.clone()), Some(user_config)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -1165,6 +1161,7 @@ fn test_no_preimage_inbound_htlc_balances() { // HTLC output is spent. let commitment_tx_fee = chan_feerate * (chan_utils::commitment_tx_base_weight(&channel_type_features) + 2 * chan_utils::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000; + assert_eq!(sorted_vec(vec![Balance::ClaimableOnChannelClose { balance_candidates: vec![HolderCommitmentTransactionBalance { amount_satoshis: 1_000_000 - 500_000 - 10_000 - commitment_tx_fee, @@ -1382,7 +1379,6 @@ fn do_test_revoked_counterparty_commitment_balances(keyed_anchors: bool, p2a_anc let mut user_config = test_default_channel_config(); user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = keyed_anchors; user_config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; - user_config.manually_accept_inbound_channels = keyed_anchors || p2a_anchor; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(user_config.clone()), Some(user_config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -1686,7 +1682,6 @@ fn do_test_revoked_counterparty_htlc_tx_balances(keyed_anchors: bool, p2a_anchor let mut user_config = test_default_channel_config(); user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = keyed_anchors; user_config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; - user_config.manually_accept_inbound_channels = keyed_anchors || p2a_anchor; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(user_config.clone()), Some(user_config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -1976,7 +1971,6 @@ fn do_test_revoked_counterparty_aggregated_claims(keyed_anchors: bool, p2a_ancho let mut user_config = test_default_channel_config(); user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = keyed_anchors; user_config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; - user_config.manually_accept_inbound_channels = keyed_anchors || p2a_anchor; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(user_config.clone()), Some(user_config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -2253,7 +2247,6 @@ fn do_test_claimable_balance_correct_while_payment_pending(outbound_payment: boo let mut user_config = test_default_channel_config(); user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = keyed_anchors; user_config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; - user_config.manually_accept_inbound_channels = keyed_anchors || p2a_anchor; let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[Some(user_config.clone()), Some(user_config.clone()), Some(user_config)]); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); @@ -2401,7 +2394,6 @@ fn do_test_monitor_rebroadcast_pending_claims(keyed_anchors: bool, p2a_anchor: b let mut config = test_default_channel_config(); config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = keyed_anchors; config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; - config.manually_accept_inbound_channels = keyed_anchors || p2a_anchor; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config.clone()), Some(config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -2527,7 +2519,6 @@ fn do_test_yield_anchors_events(have_htlcs: bool, p2a_anchor: bool) { anchors_config.channel_handshake_config.announce_for_forwarding = true; anchors_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; anchors_config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; - anchors_config.manually_accept_inbound_channels = true; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(anchors_config.clone()), Some(anchors_config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -2729,7 +2720,6 @@ fn do_test_anchors_aggregated_revoked_htlc_tx(p2a_anchor: bool) { let mut anchors_config = test_default_channel_config(); anchors_config.channel_handshake_config.announce_for_forwarding = true; - anchors_config.manually_accept_inbound_channels = true; anchors_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; anchors_config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(anchors_config.clone()), Some(anchors_config.clone())]); @@ -3036,7 +3026,6 @@ fn do_test_anchors_monitor_fixes_counterparty_payment_script_on_reload(confirm_c let chain_monitor; let mut user_config = test_default_channel_config(); user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - user_config.manually_accept_inbound_channels = true; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(user_config.clone()), Some(user_config.clone())]); let node_deserialized; let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -3127,7 +3116,6 @@ fn do_test_monitor_claims_with_random_signatures(keyed_anchors: bool, p2a_anchor let mut user_config = test_default_channel_config(); user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = keyed_anchors; user_config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; - user_config.manually_accept_inbound_channels = keyed_anchors || p2a_anchor; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(user_config.clone()), Some(user_config)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -3418,7 +3406,6 @@ fn do_test_lost_preimage_monitor_events(on_counterparty_tx: bool, p2a_anchor: bo // Here we test that losing `MonitorEvent`s that contain HTLC resolution preimages does not // cause us to lose funds or miss a `PaymentSent` event. let mut cfg = test_default_channel_config(); - cfg.manually_accept_inbound_channels = true; cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; let cfgs = [Some(cfg.clone()), Some(cfg.clone()), Some(cfg.clone())]; @@ -3600,7 +3587,6 @@ fn do_test_lost_timeout_monitor_events(confirm_tx: CommitmentType, dust_htlcs: b // Here we test that losing `MonitorEvent`s that contain HTLC resolution via timeouts does not // cause us to lose a `PaymentFailed` event. let mut cfg = test_default_channel_config(); - cfg.manually_accept_inbound_channels = true; cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; let cfgs = [Some(cfg.clone()), Some(cfg.clone()), Some(cfg.clone())]; diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index 8f209c88e25..5e0ef767a64 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -1018,7 +1018,6 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let mut manually_accept_config = test_default_channel_config(); - manually_accept_config.manually_accept_inbound_channels = true; let persist_1; let chain_monitor_1; @@ -2208,7 +2207,6 @@ fn do_test_intercepted_payment(test: InterceptTest) { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let mut zero_conf_chan_config = test_default_channel_config(); - zero_conf_chan_config.manually_accept_inbound_channels = true; let mut intercept_forwards_config = test_default_channel_config(); intercept_forwards_config.accept_intercept_htlcs = true; @@ -4951,7 +4949,6 @@ fn test_htlc_forward_considers_anchor_outputs_value() { // balance to dip below the reserve when considering the value of anchor outputs. let mut config = test_default_channel_config(); config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - config.manually_accept_inbound_channels = true; config.channel_config.forwarding_fee_base_msat = 0; config.channel_config.forwarding_fee_proportional_millionths = 0; diff --git a/lightning/src/ln/priv_short_conf_tests.rs b/lightning/src/ln/priv_short_conf_tests.rs index 83aaca24203..f305ac461fb 100644 --- a/lightning/src/ln/priv_short_conf_tests.rs +++ b/lightning/src/ln/priv_short_conf_tests.rs @@ -447,7 +447,7 @@ fn test_scid_privacy_negotiation() { .as_ref() .unwrap() .supports_scid_privacy()); - nodes[1].node.handle_open_channel(node_a_id, &second_open_channel); + handle_and_accept_open_channel(&nodes[1], node_a_id, &second_open_channel); nodes[0].node.handle_accept_channel( node_b_id, &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id), @@ -500,7 +500,8 @@ fn test_inbound_scid_privacy() { assert!(open_channel.common_fields.channel_type.as_ref().unwrap().requires_scid_privacy()); - nodes[2].node.handle_open_channel(node_b_id, &open_channel); + handle_and_accept_open_channel(&nodes[2], node_b_id, &open_channel); + let accept_channel = get_event_msg!(nodes[2], MessageSendEvent::SendAcceptChannel, node_b_id); nodes[1].node.handle_accept_channel(node_c_id, &accept_channel); @@ -780,7 +781,6 @@ fn test_simple_0conf_channel() { let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let mut chan_config = test_default_channel_config(); - chan_config.manually_accept_inbound_channels = true; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(chan_config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -799,7 +799,6 @@ fn test_0conf_channel_with_async_monitor() { let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let mut chan_config = test_default_channel_config(); - chan_config.manually_accept_inbound_channels = true; let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, Some(chan_config.clone()), None]); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); @@ -996,7 +995,6 @@ fn test_0conf_close_no_early_chan_update() { let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let mut chan_config = test_default_channel_config(); - chan_config.manually_accept_inbound_channels = true; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(chan_config.clone())]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -1023,7 +1021,6 @@ fn test_public_0conf_channel() { let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let mut chan_config = test_default_channel_config(); - chan_config.manually_accept_inbound_channels = true; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(chan_config.clone())]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -1085,7 +1082,6 @@ fn test_0conf_channel_reorg() { let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let mut chan_config = test_default_channel_config(); - chan_config.manually_accept_inbound_channels = true; let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, Some(chan_config.clone())]); @@ -1313,7 +1309,7 @@ fn test_zero_conf_accept_reject() { let mut channel_type_features = ChannelTypeFeatures::only_static_remote_key(); channel_type_features.set_zero_conf_required(); - // 1. Check we reject zero conf channels by default + // Check we can accept zero conf channels via the right method let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); @@ -1321,6 +1317,7 @@ fn test_zero_conf_accept_reject() { let node_a_id = nodes[0].node.get_our_node_id(); let node_b_id = nodes[1].node.get_our_node_id(); + // 1. First try the non-0conf method to manually accept nodes[0].node.create_channel(node_b_id, 100000, 10001, 42, None, None).unwrap(); let mut open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); @@ -1329,41 +1326,6 @@ fn test_zero_conf_accept_reject() { nodes[1].node.handle_open_channel(node_a_id, &open_channel_msg); - let msg_events = nodes[1].node.get_and_clear_pending_msg_events(); - match msg_events[0] { - MessageSendEvent::HandleError { - action: ErrorAction::SendErrorMessage { ref msg, .. }, - .. - } => { - assert_eq!(msg.data, "No zero confirmation channels accepted".to_owned()); - }, - _ => panic!(), - } - - // 2. Check we can manually accept zero conf channels via the right method - let mut manually_accept_conf = UserConfig::default(); - manually_accept_conf.manually_accept_inbound_channels = true; - - let chanmon_cfgs = create_chanmon_cfgs(2); - let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = - create_node_chanmgrs(2, &node_cfgs, &[None, Some(manually_accept_conf.clone())]); - let 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(); - - // 2.1 First try the non-0conf method to manually accept - nodes[0] - .node - .create_channel(node_b_id, 100000, 10001, 42, None, Some(manually_accept_conf.clone())) - .unwrap(); - let mut open_channel_msg = - get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); - - open_channel_msg.common_fields.channel_type = Some(channel_type_features.clone()); - - nodes[1].node.handle_open_channel(node_a_id, &open_channel_msg); - // Assert that `nodes[1]` has no `MessageSendEvent::SendAcceptChannel` in the `msg_events`. assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -1391,11 +1353,8 @@ fn test_zero_conf_accept_reject() { _ => panic!(), } - // 2.2 Try again with the 0conf method to manually accept - nodes[0] - .node - .create_channel(node_b_id, 100000, 10001, 42, None, Some(manually_accept_conf)) - .unwrap(); + // 2. Try again with the 0conf method to manually accept + nodes[0].node.create_channel(node_b_id, 100000, 10001, 42, None, None).unwrap(); let mut open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); @@ -1438,7 +1397,6 @@ fn test_connect_before_funding() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let mut manually_accept_conf = test_default_channel_config(); - manually_accept_conf.manually_accept_inbound_channels = true; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(manually_accept_conf)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -1491,7 +1449,6 @@ fn test_0conf_ann_sigs_racing_conf() { let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let mut chan_config = test_default_channel_config(); - chan_config.manually_accept_inbound_channels = true; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(chan_config.clone())]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); diff --git a/lightning/src/ln/reload_tests.rs b/lightning/src/ln/reload_tests.rs index a38262e6952..22ab4c4b231 100644 --- a/lightning/src/ln/reload_tests.rs +++ b/lightning/src/ln/reload_tests.rs @@ -253,7 +253,7 @@ fn test_manager_serialize_deserialize_events() { let node_a = nodes.remove(0); let node_b = nodes.remove(0); node_a.node.create_channel(node_b.node.get_our_node_id(), channel_value, push_msat, 42, None, None).unwrap(); - node_b.node.handle_open_channel(node_a.node.get_our_node_id(), &get_event_msg!(node_a, MessageSendEvent::SendOpenChannel, node_b.node.get_our_node_id())); + handle_and_accept_open_channel(&node_b, node_a.node.get_our_node_id(), &get_event_msg!(node_a, MessageSendEvent::SendOpenChannel, node_b.node.get_our_node_id())); node_a.node.handle_accept_channel(node_b.node.get_our_node_id(), &get_event_msg!(node_b, MessageSendEvent::SendAcceptChannel, node_a.node.get_our_node_id())); let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&node_a, &node_b.node.get_our_node_id(), channel_value, 42); diff --git a/lightning/src/ln/reorg_tests.rs b/lightning/src/ln/reorg_tests.rs index b56caf96008..f4c562d928d 100644 --- a/lightning/src/ln/reorg_tests.rs +++ b/lightning/src/ln/reorg_tests.rs @@ -404,7 +404,12 @@ fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool, use_funding_ nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &Init { + features: nodes[0].node.init_features(), networks: None, remote_network_address: None + }, true).unwrap(); } + let _ = nodes[1].node.get_and_clear_pending_msg_events(); + create_announced_chan_between_nodes(&nodes, 0, 1); send_payment(&nodes[0], &[&nodes[1]], 8000000); } @@ -828,7 +833,6 @@ fn do_test_retries_own_commitment_broadcast_after_reorg(keyed_anchors: bool, p2a let mut config = test_default_channel_config(); config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = keyed_anchors; config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; - config.manually_accept_inbound_channels = keyed_anchors || p2a_anchor; let persister; let new_chain_monitor; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config.clone()), Some(config.clone())]); @@ -985,7 +989,6 @@ fn do_test_split_htlc_expiry_tracking(use_third_htlc: bool, reorg_out: bool, p2a // This test relies on being able to consolidate HTLC claims into a single transaction, which // requires anchors: let mut config = test_default_channel_config(); - config.manually_accept_inbound_channels = true; config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor; diff --git a/lightning/src/ln/shutdown_tests.rs b/lightning/src/ln/shutdown_tests.rs index 192bc6399e4..70f24276196 100644 --- a/lightning/src/ln/shutdown_tests.rs +++ b/lightning/src/ln/shutdown_tests.rs @@ -991,6 +991,17 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() { let mut open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); open_channel.common_fields.shutdown_scriptpubkey = Some(anysegwit_shutdown_script.clone()); nodes[1].node.handle_open_channel(node_a_id, &open_channel); + let events = nodes[1].node.get_and_clear_pending_events(); + assert_eq!(events.len(), 1); + match &events[0] { + Event::OpenChannelRequest { temporary_channel_id, counterparty_node_id, .. } => { + assert!(nodes[1] + .node + .accept_inbound_channel(temporary_channel_id, counterparty_node_id, 42, None,) + .is_err()); + }, + _ => panic!("Unexpected event"), + }; let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -1019,7 +1030,8 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() { // Check script when handling an accept_channel message nodes[0].node.create_channel(node_b_id, 100000, 10001, 42, None, None).unwrap(); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); - nodes[1].node.handle_open_channel(node_a_id, &open_channel); + handle_and_accept_open_channel(&nodes[1], node_a_id, &open_channel); + let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id); accept_channel.common_fields.shutdown_scriptpubkey = Some(anysegwit_shutdown_script.clone()); @@ -1057,6 +1069,17 @@ fn test_invalid_upfront_shutdown_script() { open_channel.common_fields.shutdown_scriptpubkey = Some(Builder::new().push_int(0).push_slice(&[0, 0]).into_script()); nodes[1].node.handle_open_channel(node_a_id, &open_channel); + let events = nodes[1].node.get_and_clear_pending_events(); + assert_eq!(events.len(), 1); + match &events[0] { + Event::OpenChannelRequest { temporary_channel_id, counterparty_node_id, .. } => { + assert!(nodes[1] + .node + .accept_inbound_channel(temporary_channel_id, counterparty_node_id, 42, None,) + .is_err()); + }, + _ => panic!("Unexpected event"), + }; let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); diff --git a/lightning/src/ln/splicing_tests.rs b/lightning/src/ln/splicing_tests.rs index db6680d963c..fc87f0297d9 100644 --- a/lightning/src/ln/splicing_tests.rs +++ b/lightning/src/ln/splicing_tests.rs @@ -1064,7 +1064,7 @@ fn do_test_splice_commitment_broadcast(splice_status: SpliceStatus, claim_htlcs: // Tests that we're able to enforce HTLCs onchain during the different stages of a splice. let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let config = test_default_anchors_channel_config(); + let config = test_anchors_channel_config(); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config.clone()), Some(config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -1527,7 +1527,6 @@ fn do_test_propose_splice_while_disconnected(reload: bool, use_0conf: bool) { let (chain_monitor_0a, chain_monitor_0b, chain_monitor_1a, chain_monitor_1b); let mut config = test_default_channel_config(); if use_0conf { - config.manually_accept_inbound_channels = true; config.channel_handshake_limits.trust_own_funding_0conf = true; } let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config.clone()), Some(config)]); @@ -1822,7 +1821,7 @@ fn do_test_propose_splice_while_disconnected(reload: bool, use_0conf: bool) { fn disconnect_on_unexpected_interactive_tx_message() { let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let config = test_default_anchors_channel_config(); + let config = test_anchors_channel_config(); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config.clone()), Some(config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -1862,7 +1861,7 @@ fn disconnect_on_unexpected_interactive_tx_message() { fn fail_splice_on_interactive_tx_error() { let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let config = test_default_anchors_channel_config(); + let config = test_anchors_channel_config(); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config.clone()), Some(config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -1968,7 +1967,7 @@ fn fail_splice_on_interactive_tx_error() { fn fail_splice_on_tx_abort() { let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let config = test_default_anchors_channel_config(); + let config = test_anchors_channel_config(); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config.clone()), Some(config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -2022,7 +2021,7 @@ fn fail_splice_on_tx_abort() { fn fail_splice_on_channel_close() { let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let config = test_default_anchors_channel_config(); + let config = test_anchors_channel_config(); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config.clone()), Some(config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -2073,7 +2072,8 @@ fn fail_splice_on_channel_close() { fn fail_quiescent_action_on_channel_close() { let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let config = test_default_anchors_channel_config(); + let config = test_anchors_channel_config(); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config.clone()), Some(config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); diff --git a/lightning/src/ln/update_fee_tests.rs b/lightning/src/ln/update_fee_tests.rs index 67a07325ad6..69890fb001c 100644 --- a/lightning/src/ln/update_fee_tests.rs +++ b/lightning/src/ln/update_fee_tests.rs @@ -388,8 +388,6 @@ pub fn do_test_update_fee_that_funder_cannot_afford(channel_type_features: Chann let mut default_config = test_default_channel_config(); if channel_type_features == ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies() { default_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - // this setting is also needed to create an anchor channel - default_config.manually_accept_inbound_channels = true; } let node_chanmgrs = create_node_chanmgrs( @@ -898,6 +896,17 @@ pub fn test_chan_init_feerate_unaffordability() { get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id); open_channel_msg.push_msat += 1; nodes[1].node.handle_open_channel(node_a_id, &open_channel_msg); + let events = nodes[1].node.get_and_clear_pending_events(); + assert_eq!(events.len(), 1); + match &events[0] { + Event::OpenChannelRequest { temporary_channel_id, counterparty_node_id, .. } => { + assert!(nodes[1] + .node + .accept_inbound_channel(temporary_channel_id, counterparty_node_id, 42, None,) + .is_err()); + }, + _ => panic!("Unexpected event"), + } let msg_events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(msg_events.len(), 1); @@ -1029,7 +1038,6 @@ pub fn do_cannot_afford_on_holding_cell_release( 100; if channel_type_features.supports_anchors_zero_fee_htlc_tx() { default_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - default_config.manually_accept_inbound_channels = true; } let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); @@ -1372,7 +1380,6 @@ pub fn test_zero_fee_commitments_no_update_fee() { // they'll disconnect and warn if they receive them. let mut cfg = test_default_channel_config(); cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true; - cfg.manually_accept_inbound_channels = true; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); diff --git a/lightning/src/ln/zero_fee_commitment_tests.rs b/lightning/src/ln/zero_fee_commitment_tests.rs index 2503ad81cde..d287b6e3de1 100644 --- a/lightning/src/ln/zero_fee_commitment_tests.rs +++ b/lightning/src/ln/zero_fee_commitment_tests.rs @@ -18,7 +18,6 @@ fn test_p2a_anchor_values_under_trims_and_rounds() { let mut user_cfg = test_default_channel_config(); user_cfg.channel_handshake_config.our_htlc_minimum_msat = 1; user_cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true; - user_cfg.manually_accept_inbound_channels = true; let configs = [Some(user_cfg.clone()), Some(user_cfg)]; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &configs); @@ -125,7 +124,6 @@ fn test_htlc_claim_chunking() { user_cfg.channel_handshake_config.our_htlc_minimum_msat = 1; user_cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true; user_cfg.channel_handshake_config.our_max_accepted_htlcs = 114; - user_cfg.manually_accept_inbound_channels = true; let configs = [Some(user_cfg.clone()), Some(user_cfg)]; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &configs); @@ -314,7 +312,6 @@ fn test_anchor_tx_too_big() { user_cfg.channel_handshake_config.our_htlc_minimum_msat = 1; user_cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true; user_cfg.channel_handshake_config.our_max_accepted_htlcs = 114; - user_cfg.manually_accept_inbound_channels = true; let configs = [Some(user_cfg.clone()), Some(user_cfg)]; let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &configs); diff --git a/lightning/src/util/config.rs b/lightning/src/util/config.rs index dd1aaa40424..b8f668ade5e 100644 --- a/lightning/src/util/config.rs +++ b/lightning/src/util/config.rs @@ -30,14 +30,14 @@ pub struct ChannelHandshakeConfig { /// both parties have exchanged `splice_locked`. /// /// A lower-bound of `1` is applied, requiring all channels to have a confirmed commitment - /// transaction before operation. If you wish to accept channels with zero confirmations, see - /// [`UserConfig::manually_accept_inbound_channels`] and + /// transaction before operation. If you wish to accept channels with zero confirmations, + /// manually accept them via [`Event::OpenChannelRequest`] using /// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`]. /// /// Default value: `6` /// - /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel /// [`ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf + /// [`Event::OpenChannelRequest`]: crate::events::Event::OpenChannelRequest pub minimum_depth: u32, /// Set to the number of blocks we require our counterparty to wait to claim their money (ie /// the number of blocks we have to punish our counterparty if they broadcast a revoked @@ -162,15 +162,15 @@ pub struct ChannelHandshakeConfig { /// will be treated as one million instead, although channel negotiations will /// fail in that case.) pub their_channel_reserve_proportional_millionths: u32, - /// If set, we attempt to negotiate the `anchors_zero_fee_htlc_tx`option for all future + /// If set, we attempt to negotiate the `anchors_zero_fee_htlc_tx` option for all future /// channels. This feature requires having a reserve of onchain funds readily available to bump /// transactions in the event of a channel force close to avoid the possibility of losing funds. /// - /// Note that if you wish accept inbound channels with anchor outputs, you must enable - /// [`UserConfig::manually_accept_inbound_channels`] and manually accept them with - /// [`ChannelManager::accept_inbound_channel`]. This is done to give you the chance to check - /// whether your reserve of onchain funds is enough to cover the fees for all existing and new - /// channels featuring anchor outputs in the event of a force close. + /// Note that all inbound channel requests will be surfaced via [`Event::OpenChannelRequest`] + /// and you must manually accept them with [`ChannelManager::accept_inbound_channel`]. This + /// is done to give you the chance to check whether your reserve of onchain funds is enough + /// to cover the fees for all existing and new channels featuring anchor outputs in the event + /// of a force close. /// /// If this option is set, channels may be created that will not be readable by LDK versions /// prior to 0.0.116, causing [`ChannelManager`]'s read method to return a @@ -180,11 +180,12 @@ pub struct ChannelHandshakeConfig { /// counterparties that do not support the `anchors_zero_fee_htlc_tx` option; we will simply /// fall back to a `static_remote_key` channel. /// - /// Default value: `false` (This value is likely to change to `true` in the future.) + /// Default value: `true` /// /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel /// [`DecodeError::InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue + /// [`Event::OpenChannelRequest`]: crate::events::Event::OpenChannelRequest pub negotiate_anchors_zero_fee_htlc_tx: bool, /// If set, we attempt to negotiate the `zero_fee_commitments` option for all future channels. @@ -198,11 +199,11 @@ pub struct ChannelHandshakeConfig { /// funds readily available to bump transactions in the event of a channel force close to avoid /// the possibility of losing funds. /// - /// Note that if you wish accept inbound channels with anchor outputs, you must enable - /// [`UserConfig::manually_accept_inbound_channels`] and manually accept them with - /// [`ChannelManager::accept_inbound_channel`]. This is done to give you the chance to check - /// whether your reserve of onchain funds is enough to cover the fees for all existing and new - /// channels featuring anchor outputs in the event of a force close. + /// Note that all inbound channel requests will be surfaced via [`Event::OpenChannelRequest`] + /// and you must manually accept them with [`ChannelManager::accept_inbound_channel`]. This + /// is done to give you the chance to check whether your reserve of onchain funds is enough + /// to cover the fees for all existing and new channels featuring anchor outputs in the event + /// of a force close. /// /// If this option is set, channels may be created that will not be readable by LDK versions /// prior to 0.2, causing [`ChannelManager`]'s read method to return a @@ -224,6 +225,7 @@ pub struct ChannelHandshakeConfig { /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel /// [`DecodeError::InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue + /// [`Event::OpenChannelRequest`]: crate::events::Event::OpenChannelRequest pub negotiate_anchor_zero_fee_commitments: bool, /// The maximum number of HTLCs in-flight from our counterparty towards us at the same time. @@ -254,7 +256,7 @@ impl Default for ChannelHandshakeConfig { announce_for_forwarding: false, commit_upfront_shutdown_pubkey: true, their_channel_reserve_proportional_millionths: 10_000, - negotiate_anchors_zero_fee_htlc_tx: false, + negotiate_anchors_zero_fee_htlc_tx: true, negotiate_anchor_zero_fee_commitments: false, our_max_accepted_htlcs: 50, } @@ -893,20 +895,6 @@ pub struct UserConfig { /// /// Default value: `true` pub accept_inbound_channels: bool, - /// If this is set to `true`, the user needs to manually accept inbound requests to open a new - /// channel. - /// - /// When set to `true`, [`Event::OpenChannelRequest`] will be triggered once a request to open a - /// new inbound channel is received through a [`msgs::OpenChannel`] message. In that case, a - /// [`msgs::AcceptChannel`] message will not be sent back to the counterparty node unless the - /// user explicitly chooses to accept the request. - /// - /// Default value: `false` - /// - /// [`Event::OpenChannelRequest`]: crate::events::Event::OpenChannelRequest - /// [`msgs::OpenChannel`]: crate::ln::msgs::OpenChannel - /// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel - pub manually_accept_inbound_channels: bool, /// If this is set to `true`, LDK will intercept HTLCs that are attempting to be forwarded over /// fake short channel ids generated via [`ChannelManager::get_intercept_scid`]. Upon HTLC /// intercept, LDK will generate an [`Event::HTLCIntercepted`] which MUST be handled by the user. @@ -983,7 +971,6 @@ impl Default for UserConfig { channel_config: ChannelConfig::default(), accept_forwards_to_priv_channels: false, accept_inbound_channels: true, - manually_accept_inbound_channels: false, accept_intercept_htlcs: false, manually_handle_bolt12_invoices: false, enable_dual_funded_channels: false, @@ -1006,7 +993,6 @@ impl Readable for UserConfig { channel_config: Readable::read(reader)?, accept_forwards_to_priv_channels: Readable::read(reader)?, accept_inbound_channels: Readable::read(reader)?, - manually_accept_inbound_channels: Readable::read(reader)?, accept_intercept_htlcs: Readable::read(reader)?, manually_handle_bolt12_invoices: Readable::read(reader)?, enable_dual_funded_channels: Readable::read(reader)?, diff --git a/pending_changelog/4337-manual-channel-accept-default-anchors.txt b/pending_changelog/4337-manual-channel-accept-default-anchors.txt new file mode 100644 index 00000000000..98720987ef2 --- /dev/null +++ b/pending_changelog/4337-manual-channel-accept-default-anchors.txt @@ -0,0 +1,16 @@ + # API Updates + + * `ChannelHandshakeConfig::negotiate_anchors_zero_fee_htlc_tx` + now defaults to `true` (previously `false`). This means anchor output channels + will be negotiated by default for all new channels, requiring users to + maintain an on-chain reserve for fee bumping in the event of force-closes. + + * All inbound channels now require manual acceptance. + `UserConfig::manually_accept_inbound_channels` has been removed, and + `Event::OpenChannelRequest` will now always be generated for inbound channel + requests. Users must handle this event and call either + `ChannelManager::accept_inbound_channel` (or + `accept_inbound_channel_from_trusted_peer_0conf` for zero-conf channels) to + accept the channel, or `ChannelManager::force_close_broadcasting_latest_txn` + to reject it. This ensures users can verify they have sufficient on-chain + funds before accepting channels with anchor outputs.