diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 5fb07431b17..530f90efb3a 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/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index 600335b5083..3bcc9fcb9df 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -42,15 +42,13 @@ use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Listen}; use lightning::events::bump_transaction::sync::WalletSourceSync; use lightning::events::Event; use lightning::ln::channel_state::ChannelDetails; -use lightning::ln::channelmanager::{ - ChainParameters, ChannelManager, InterceptId, PaymentId, -}; +use lightning::ln::channelmanager::{ChainParameters, ChannelManager, InterceptId, PaymentId}; use lightning::ln::functional_test_utils::*; use lightning::ln::inbound_payment::ExpandedKey; +use lightning::ln::outbound_payment::{RecipientOnionFields, Retry}; use lightning::ln::peer_handler::{ IgnoringMessageHandler, MessageHandler, PeerManager, SocketDescriptor, }; -use lightning::ln::outbound_payment::{RecipientOnionFields, Retry}; use lightning::ln::script::ShutdownScript; use lightning::ln::types::ChannelId; use lightning::offers::invoice::UnsignedBolt12Invoice; @@ -1122,6 +1120,17 @@ pub fn do_test(mut data: &[u8], logger: &Arc) { Event::SpliceFailed { .. } => { // Splice failed, inputs can be re-spent }, + Event::OpenChannelRequest { + temporary_channel_id, counterparty_node_id, .. + } => { + let _ = loss_detector.manager.accept_inbound_channel( + &temporary_channel_id, + &counterparty_node_id, + 0, + None, + ); + loss_detector.handler.process_events(); + }, _ => {}, } } @@ -1159,7 +1168,7 @@ fn two_peer_forwarding_seed() -> Vec { // our network key ext_from_hex("0100000000000000000000000000000000000000000000000000000000000000", &mut test); // config - ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff000100000000000000", &mut test); + ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000000000", &mut test); // new outbound connection with id 0 ext_from_hex("00", &mut test); @@ -1613,7 +1622,7 @@ fn gossip_exchange_seed() -> Vec { // our network key ext_from_hex("0100000000000000000000000000000000000000000000000000000000000000", &mut test); // config - ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff000100000000000000", &mut test); + ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000000000", &mut test); // new outbound connection with id 0 ext_from_hex("00", &mut test); @@ -1695,7 +1704,7 @@ fn splice_seed() -> Vec { // our network key ext_from_hex("0100000000000000000000000000000000000000000000000000000000000000", &mut test); // config - ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff000100000000000000", &mut test); + ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000000000", &mut test); // new outbound connection with id 0 ext_from_hex("00", &mut test); diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index bb99d65e6b5..94be01420ad 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -2447,6 +2447,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), @@ -2457,7 +2459,7 @@ mod tests { Arc::clone(&keys_manager), Arc::clone(&keys_manager), Arc::clone(&keys_manager), - UserConfig::default(), + config, params, genesis_block.header.time, )); @@ -2610,6 +2612,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 312199e19ec..33a6dd697cf 100644 --- a/lightning-liquidity/tests/lsps2_integration_tests.rs +++ b/lightning-liquidity/tests/lsps2_integration_tests.rs @@ -1155,7 +1155,6 @@ fn client_trusts_lsp_end_to_end_test() { service_node_config.htlc_interception_flags = HTLCInterceptionFlags::ToInterceptSCIDs as u8; 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, @@ -1627,7 +1626,6 @@ fn late_payment_forwarded_and_safe_after_force_close_does_not_broadcast() { service_node_config.htlc_interception_flags = HTLCInterceptionFlags::ToInterceptSCIDs as u8; 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( @@ -1817,7 +1815,6 @@ fn htlc_timeout_before_client_claim_results_in_handling_failed() { service_node_config.htlc_interception_flags = HTLCInterceptionFlags::ToInterceptSCIDs as u8; 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( @@ -2152,7 +2149,6 @@ fn client_trusts_lsp_partial_fee_does_not_trigger_broadcast() { service_node_config.htlc_interception_flags = HTLCInterceptionFlags::ToInterceptSCIDs as u8; 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-persister/src/test_utils.rs b/lightning-persister/src/test_utils.rs index 55208c61491..48b383ad1ea 100644 --- a/lightning-persister/src/test_utils.rs +++ b/lightning-persister/src/test_utils.rs @@ -132,7 +132,9 @@ pub(crate) fn do_test_store(store_0: &K, store_1: &K) { ); node_cfgs[0].chain_monitor = chain_mon_0; node_cfgs[1].chain_monitor = chain_mon_1; - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_b_id = nodes[1].node.get_our_node_id(); diff --git a/lightning/src/chain/chainmonitor.rs b/lightning/src/chain/chainmonitor.rs index 17693f8ca7a..7db1b697c2b 100644 --- a/lightning/src/chain/chainmonitor.rs +++ b/lightning/src/chain/chainmonitor.rs @@ -1687,7 +1687,12 @@ mod tests { fn test_chainsync_triggers_distributed_monitor_persistence() { 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)], + ); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index c7dd579967a..3e1138c6470 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -6808,7 +6808,8 @@ mod tests { // updates is handled correctly in such conditions. 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); let channel = create_announced_chan_between_nodes(&nodes, 0, 1); create_announced_chan_between_nodes(&nodes, 1, 2); diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index 3d860e9f363..60d934cf199 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -245,9 +245,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`] for inbound channels. /// /// 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 @@ -255,7 +253,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, @@ -765,14 +762,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 @@ -1404,13 +1398,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. /// @@ -1444,13 +1435,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, @@ -1466,11 +1454,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 @@ -1480,15 +1467,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, @@ -1532,13 +1516,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, @@ -1565,13 +1546,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, @@ -1604,14 +1582,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. @@ -1619,7 +1595,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. /// @@ -1861,11 +1836,11 @@ 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. + /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound + /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels. /// - /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels + /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel + /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel 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 528cec44c00..8a991b1d98d 100644 --- a/lightning/src/ln/async_payments_tests.rs +++ b/lightning/src/ln/async_payments_tests.rs @@ -3057,7 +3057,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 53187c14168..adaf976c7d9 100644 --- a/lightning/src/ln/async_signer_tests.rs +++ b/lightning/src/ln/async_signer_tests.rs @@ -37,12 +37,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(); @@ -89,8 +86,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 = { @@ -131,7 +135,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( @@ -208,7 +212,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( @@ -365,7 +369,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); @@ -999,7 +1002,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 3fa2073d5ba..4475def5427 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -2129,10 +2129,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), @@ -3218,7 +3216,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 = @@ -3328,7 +3325,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 = @@ -3783,7 +3779,12 @@ fn do_test_durable_preimages_on_closed_channel( let chain_mon; let node_b_reload; - let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), None], + ); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -3978,7 +3979,8 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) { let chain_mon; let node_b_reload; - let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[Some(legacy_cfg), None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); let node_b_id = nodes[1].node.get_our_node_id(); @@ -4466,7 +4468,9 @@ fn test_claim_to_closed_channel_blocks_forwarded_preimage_removal() { // This tests that behavior. 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(3, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg), None]); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -4547,7 +4551,8 @@ fn test_claim_to_closed_channel_blocks_claimed_event() { // This tests that behavior. 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg), None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 042b388e1a1..bcfd6fd9368 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -16026,7 +16026,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 @@ -16116,7 +16117,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; @@ -17516,7 +17518,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..30276cadadb 100644 --- a/lightning/src/ln/channel_open_tests.rs +++ b/lightning/src/ln/channel_open_tests.rs @@ -62,7 +62,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 +90,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 +107,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 +172,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 anchors_cfg = test_default_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), @@ -205,8 +191,6 @@ fn test_inbound_anchors_manual_acceptance_overridden() { }; let mut anchors_cfg = test_default_channel_config(); - anchors_cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - 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 +210,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 +224,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 +246,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 +267,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 +291,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![ @@ -344,11 +306,9 @@ fn test_zero_fee_commitments_downgrade_to_static_remote() { // are supported (but not accepted), but not legacy anchors. let mut initiator_cfg = test_default_channel_config(); initiator_cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true; - initiator_cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - let mut receiver_cfg = test_default_channel_config(); + let mut receiver_cfg = test_legacy_channel_config(); receiver_cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true; - receiver_cfg.manually_accept_inbound_channels = true; let start_type = ChannelTypeFeatures::anchors_zero_fee_commitments(); let end_type = ChannelTypeFeatures::only_static_remote_key(); @@ -406,10 +366,8 @@ fn do_test_channel_type_downgrade( fn test_no_channel_downgrade() { // Tests that the local node will not retry when a `option_static_remote` channel is // rejected by a peer that advertises support for the feature. - let initiator_cfg = test_default_channel_config(); + let initiator_cfg = test_legacy_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 +427,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); @@ -499,11 +457,11 @@ fn test_channel_resumption_fail_post_funding() { pub fn test_insane_channel_opens() { // Stand up a network of 2 nodes use crate::ln::channel::TOTAL_BITCOIN_SUPPLY_SATOSHIS; - let mut cfg = UserConfig::default(); - cfg.channel_handshake_limits.max_funding_satoshis = TOTAL_BITCOIN_SUPPLY_SATOSHIS + 1; + let mut legacy_cfg = test_legacy_channel_config(); + legacy_cfg.channel_handshake_limits.max_funding_satoshis = TOTAL_BITCOIN_SUPPLY_SATOSHIS + 1; 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(cfg.clone())]); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(legacy_cfg.clone())]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -513,7 +471,7 @@ pub fn test_insane_channel_opens() { // funding satoshis let channel_value_sat = 31337; // same as funding satoshis let channel_reserve_satoshis = - get_holder_selected_channel_reserve_satoshis(channel_value_sat, &cfg); + get_holder_selected_channel_reserve_satoshis(channel_value_sat, &legacy_cfg); let push_msat = (channel_value_sat - channel_reserve_satoshis) * 1000; // Have node0 initiate a channel to node1 with aforementioned parameters @@ -529,6 +487,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 +599,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 +719,7 @@ 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 +898,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 +1002,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 +1058,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 +1179,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 +1221,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 +1316,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 +1332,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 +1373,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 +1419,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 +1506,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 +1610,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 +1725,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 +1786,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 +1846,7 @@ 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); + 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 +2320,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 +2365,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 +2414,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 86e53ba3262..9f6a4b0c6a6 100644 --- a/lightning/src/ln/channel_state.rs +++ b/lightning/src/ln/channel_state.rs @@ -366,14 +366,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 532514a3ae9..b6c45856af1 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -1582,10 +1582,10 @@ pub(super) struct PeerState { 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, @@ -2028,7 +2028,7 @@ impl< /// /// ## 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`]. /// @@ -2092,9 +2092,8 @@ impl< /// /// ## 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; @@ -5345,7 +5344,7 @@ impl< /// 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`]. /// @@ -10382,7 +10381,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 @@ -10569,7 +10568,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 { @@ -10672,8 +10671,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, @@ -10684,49 +10684,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; @@ -10734,20 +10722,20 @@ 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, @@ -10758,67 +10746,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(()) } @@ -20168,7 +20108,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 { @@ -20242,11 +20182,22 @@ 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); @@ -20264,7 +20215,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); } @@ -20447,7 +20398,7 @@ mod tests { fn test_trigger_lnd_force_close() { let chanmon_cfg = create_chanmon_cfgs(2); let node_cfg = create_node_cfgs(2, &chanmon_cfg); - let user_config = test_default_channel_config(); + let user_config = test_legacy_channel_config(); let node_chanmgr = create_node_chanmgrs(2, &node_cfg, &[Some(user_config.clone()), Some(user_config)]); let nodes = create_network(2, &node_cfg, &node_chanmgr); let message = "Channel force-closed".to_owned(); @@ -20625,6 +20576,16 @@ pub mod bench { }, false).unwrap(); node_a.create_channel(node_b.get_our_node_id(), 8_000_000, 100_000_000, 42, None, None).unwrap(); node_b.handle_open_channel(node_a.get_our_node_id(), &get_event_msg!(node_a_holder, MessageSendEvent::SendOpenChannel, node_b.get_our_node_id())); + let events = node_b.get_and_clear_pending_events(); + assert_eq!(events.len(), 1); + match &events[0] { + Event::OpenChannelRequest { temporary_channel_id, counterparty_node_id, .. } => { + node_b + .accept_inbound_channel(temporary_channel_id, counterparty_node_id, 42, None) + .unwrap(); + }, + _ => panic!("Unexpected event"), + }; node_a.handle_accept_channel(node_b.get_our_node_id(), &get_event_msg!(node_b_holder, MessageSendEvent::SendAcceptChannel, node_a.get_our_node_id())); let tx; diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index e8965752331..2560e77a2ac 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, 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, }; @@ -1552,7 +1552,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, @@ -1600,7 +1599,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,18 +1696,8 @@ pub fn exchange_open_accept_chan<'a, 'b, 'c>( .user_channel_id, 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"), - }; - } + handle_and_accept_open_channel(&node_b, node_a_id, &open_channel_msg); + 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,7 +1978,8 @@ pub fn create_unannounced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>( .create_channel(node_b_id, channel_value, push_msat, 42, None, Some(no_announce_cfg)) .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); + handle_and_accept_open_channel(&nodes[b], node_a_id, &open_channel); + let accept_channel = get_event_msg!(nodes[b], MessageSendEvent::SendAcceptChannel, node_a_id); nodes[a].node.handle_accept_channel(node_b_id, &accept_channel); @@ -2058,6 +2047,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, @@ -4529,8 +4532,9 @@ pub fn create_node_cfgs_with_node_id_message_router<'a>( ) } -pub fn test_default_channel_config() -> UserConfig { +pub fn test_legacy_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; @@ -4548,10 +4552,9 @@ pub fn test_default_channel_config() -> UserConfig { default_config } -pub fn test_default_anchors_channel_config() -> UserConfig { - let mut config = test_default_channel_config(); +pub fn test_default_channel_config() -> UserConfig { + let mut config = test_legacy_channel_config(); config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; - config.manually_accept_inbound_channels = true; config } @@ -5559,7 +5562,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 8e854b31150..1db31a51fd9 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -272,7 +272,9 @@ pub fn test_duplicate_htlc_different_direction_onchain() { // in opposite directions, even with the same payment secret. 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_b_id = nodes[1].node.get_our_node_id(); @@ -399,7 +401,9 @@ pub fn test_duplicate_htlc_different_direction_onchain() { pub fn test_inbound_outbound_capacity_is_not_zero() { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let _ = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000); @@ -437,7 +441,12 @@ fn do_test_fail_back_before_backwards_timeout(post_fail_back_action: PostFailBac // just before the upstream timeout expires 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)], + ); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); for node in nodes.iter() { @@ -563,7 +572,18 @@ pub fn channel_monitor_network_test() { // tests that ChannelMonitor is able to recover from various states. let chanmon_cfgs = create_chanmon_cfgs(5); let node_cfgs = create_node_cfgs(5, &chanmon_cfgs); - let node_chanmgrs = create_node_chanmgrs(5, &node_cfgs, &[None, None, None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 5, + &node_cfgs, + &[ + Some(legacy_cfg.clone()), + Some(legacy_cfg.clone()), + Some(legacy_cfg.clone()), + Some(legacy_cfg.clone()), + Some(legacy_cfg), + ], + ); let nodes = create_network(5, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -796,11 +816,11 @@ pub fn channel_monitor_network_test() { #[xtest(feature = "_externalize_tests")] pub fn test_justice_tx_htlc_timeout() { // Test justice txn built on revoked HTLC-Timeout tx, against both sides - let mut alice_config = test_default_channel_config(); + let mut alice_config = test_legacy_channel_config(); alice_config.channel_handshake_config.announce_for_forwarding = true; alice_config.channel_handshake_limits.force_announced_channel_preference = false; alice_config.channel_handshake_config.our_to_self_delay = 6 * 24 * 5; - let mut bob_config = test_default_channel_config(); + let mut bob_config = test_legacy_channel_config(); bob_config.channel_handshake_config.announce_for_forwarding = true; bob_config.channel_handshake_limits.force_announced_channel_preference = false; bob_config.channel_handshake_config.our_to_self_delay = 6 * 24 * 3; @@ -884,11 +904,11 @@ pub fn test_justice_tx_htlc_timeout() { #[xtest(feature = "_externalize_tests")] pub fn test_justice_tx_htlc_success() { // Test justice txn built on revoked HTLC-Success tx, against both sides - let mut alice_config = test_default_channel_config(); + let mut alice_config = test_legacy_channel_config(); alice_config.channel_handshake_config.announce_for_forwarding = true; alice_config.channel_handshake_limits.force_announced_channel_preference = false; alice_config.channel_handshake_config.our_to_self_delay = 6 * 24 * 5; - let mut bob_config = test_default_channel_config(); + let mut bob_config = test_legacy_channel_config(); bob_config.channel_handshake_config.announce_for_forwarding = true; bob_config.channel_handshake_limits.force_announced_channel_preference = false; bob_config.channel_handshake_config.our_to_self_delay = 6 * 24 * 3; @@ -961,7 +981,9 @@ pub fn revoked_output_claim() { // transaction is broadcast by its counterparty 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -1012,7 +1034,9 @@ fn do_test_forming_justice_tx_from_monitor_updates(broadcast_initial_commitment: WatchtowerPersister::new(destination_script1), ]; let node_cfgs = create_node_cfgs_with_persisters(2, &chanmon_cfgs, persisters.iter().collect()); - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -1075,7 +1099,9 @@ pub fn claim_htlc_outputs() { let mut chanmon_cfgs = create_chanmon_cfgs(2); chanmon_cfgs[0].keys_manager.disable_revocation_policy_check = true; let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -1164,7 +1190,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); @@ -1389,7 +1414,12 @@ pub fn test_htlc_on_chain_success() { 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)], + ); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -1636,7 +1666,12 @@ fn do_test_htlc_on_chain_timeout(connect_style: ConnectStyle) { 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)], + ); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -1887,7 +1922,12 @@ fn do_test_commitment_revoked_fail_backward_exhaustive( // commitment_signed) we will be free to fail/fulfill the HTLC backwards. 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)], + ); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -2306,7 +2346,9 @@ pub fn test_htlc_ignore_latest_remote_commitment() { // ignored if we cannot claim them. This originally tickled an invalid unwrap(). 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -2358,7 +2400,12 @@ pub fn test_force_close_fail_back() { // Check which HTLCs are failed-backwards on channel force-closure 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)], + ); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -2506,7 +2553,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); @@ -3470,7 +3517,9 @@ pub fn test_claim_sizeable_push_msat() { // Incidentally test SpendableOutput event generation due to detection of to_local output on commitment tx 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -3507,7 +3556,9 @@ pub fn test_claim_on_remote_sizeable_push_msat() { // to_remote output is encumbered by a P2WPKH 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -3549,7 +3600,9 @@ pub fn test_claim_on_remote_revoked_sizeable_push_msat() { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -3582,7 +3635,9 @@ pub fn test_claim_on_remote_revoked_sizeable_push_msat() { pub fn test_static_spendable_outputs_preimage_tx() { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -3632,7 +3687,9 @@ pub fn test_static_spendable_outputs_preimage_tx() { pub fn test_static_spendable_outputs_timeout_tx() { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -3743,7 +3800,9 @@ pub fn test_static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx() { let mut chanmon_cfgs = create_chanmon_cfgs(2); chanmon_cfgs[0].keys_manager.disable_revocation_policy_check = true; let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -3822,7 +3881,9 @@ pub fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx() { let mut chanmon_cfgs = create_chanmon_cfgs(2); chanmon_cfgs[1].keys_manager.disable_revocation_policy_check = true; let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -3909,7 +3970,12 @@ pub fn test_onchain_to_onchain_claim() { 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)], + ); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -4055,7 +4121,7 @@ pub fn test_duplicate_payment_hash_one_failure_one_success() { let node_cfgs = create_node_cfgs(5, &chanmon_cfgs); // When this test was written, the default base fee floated based on the HTLC count. // It is now fixed, so we simply set the fee to the expected value here. - let mut config = test_default_channel_config(); + let mut config = test_legacy_channel_config(); config.channel_config.forwarding_fee_base_msat = 196; let configs = [ @@ -4236,7 +4302,9 @@ pub fn test_duplicate_payment_hash_one_failure_one_success() { pub fn test_dynamic_spendable_outputs_local_htlc_success_tx() { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -4305,7 +4373,7 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno let node_cfgs = create_node_cfgs(6, &chanmon_cfgs); // When this test was written, the default base fee floated based on the HTLC count. // It is now fixed, so we simply set the fee to the expected value here. - let mut config = test_default_channel_config(); + let mut config = test_legacy_channel_config(); config.channel_config.forwarding_fee_base_msat = 196; let configs = [ @@ -4723,7 +4791,9 @@ pub fn test_fail_backwards_previous_remote_announce() { pub fn test_dynamic_spendable_outputs_local_htlc_timeout_tx() { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_b_id = nodes[1].node.get_our_node_id(); @@ -4816,7 +4886,12 @@ pub fn test_key_derivation_params() { node_cfgs.remove(0); node_cfgs.insert(0, node); - let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)], + ); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); let node_b_id = nodes[1].node.get_our_node_id(); @@ -4933,7 +5008,9 @@ pub fn test_static_output_closing_tx() { fn do_htlc_claim_local_commitment_only(use_dust: bool) { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -4977,7 +5054,9 @@ fn do_htlc_claim_local_commitment_only(use_dust: bool) { fn do_htlc_claim_current_remote_commitment_only(use_dust: bool) { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_b_id = nodes[1].node.get_our_node_id(); @@ -5016,7 +5095,12 @@ fn do_htlc_claim_current_remote_commitment_only(use_dust: bool) { fn do_htlc_claim_previous_remote_commitment_only(use_dust: bool, check_revoke_no_close: bool) { 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)], + ); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -5108,7 +5192,9 @@ pub fn htlc_claim_single_commitment_only_b() { pub fn test_fail_holding_cell_htlc_upon_free() { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -5207,7 +5293,9 @@ pub fn test_fail_holding_cell_htlc_upon_free() { pub fn test_free_and_fail_holding_cell_htlcs() { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -5350,7 +5438,7 @@ pub fn test_fail_holding_cell_htlc_upon_free_multihop() { let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); // Avoid having to include routing fees in calculations - let mut config = test_default_channel_config(); + let mut config = test_legacy_channel_config(); config.channel_config.forwarding_fee_base_msat = 0; config.channel_config.forwarding_fee_proportional_millionths = 0; let node_chanmgrs = create_node_chanmgrs( @@ -5717,7 +5805,9 @@ fn do_test_failure_delay_dust_htlc_local_commitment(announce_latest: bool) { let mut chanmon_cfgs = create_chanmon_cfgs(2); chanmon_cfgs[0].keys_manager.disable_revocation_policy_check = true; let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -5825,7 +5915,12 @@ fn do_test_sweep_outbound_htlc_failure_update(revoked: bool, local: bool) { 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)], + ); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); let node_b_id = nodes[1].node.get_our_node_id(); @@ -6131,7 +6226,9 @@ pub fn test_bump_penalty_txn_on_revoked_commitment() { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -6238,7 +6335,9 @@ pub fn test_bump_penalty_txn_on_revoked_htlcs() { let mut chanmon_cfgs = create_chanmon_cfgs(2); chanmon_cfgs[1].keys_manager.disable_revocation_policy_check = true; let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -6365,11 +6464,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 @@ -6440,7 +6539,9 @@ pub fn test_bump_penalty_txn_on_remote_commitment() { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let remote_txn = { @@ -6787,7 +6888,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); } @@ -7361,7 +7462,9 @@ pub fn test_concurrent_monitor_claim() { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -7566,7 +7669,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); @@ -7603,7 +7706,9 @@ pub fn test_htlc_no_detection() { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_b_id = nodes[1].node.get_our_node_id(); @@ -7670,7 +7775,12 @@ fn do_test_onchain_htlc_settlement_after_close( // 6) Bob claims the offered output on the broadcasted commitment. 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)], + ); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -7885,9 +7995,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); @@ -7899,7 +8008,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); @@ -7979,7 +8088,12 @@ pub fn test_error_chans_closed() { // we can test various edge cases around it to ensure we don't regress. 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)], + ); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); let node_b_id = nodes[1].node.get_our_node_id(); @@ -8078,7 +8192,12 @@ fn do_test_tx_confirmed_skipping_blocks_immediate_broadcast(test_height_before_t // aren't broadcasting transactions too early (ie not broadcasting them at all). 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)], + ); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); *nodes[0].connect_style.borrow_mut() = ConnectStyle::BestBlockFirstSkippingBlocks; @@ -8553,7 +8672,7 @@ fn do_test_max_dust_htlc_exposure( // might be available again for HTLC processing once the dust bandwidth has cleared up. let chanmon_cfgs = create_chanmon_cfgs(2); - let mut config = test_default_channel_config(); + let mut config = test_legacy_channel_config(); // We hard-code the feerate values here but they're re-calculated furter down and asserted. // If the values ever change below these constants should simply be updated. @@ -8603,7 +8722,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); @@ -8939,7 +9058,7 @@ pub fn test_nondust_htlc_excess_fees_are_dust() { } let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); - let mut config = test_default_channel_config(); + let mut config = test_legacy_channel_config(); // Set the dust limit to the default value config.channel_config.max_dust_htlc_exposure = MaxDustHTLCExposure::FeeRateMultiplier(10_000); // Make sure the HTLC limits don't get in the way @@ -9154,11 +9273,10 @@ fn do_test_nondust_htlc_fees_dust_exposure_delta(features: ChannelTypeFeatures) assert_eq!(expected_dust_exposure_msat, 528_492); } - let mut default_config = test_default_channel_config(); + let mut default_config = test_legacy_channel_config(); 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` @@ -9566,7 +9684,7 @@ 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); @@ -9630,7 +9748,7 @@ 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,10 +9806,7 @@ fn do_test_manual_broadcast_skips_commitment_until_funding( // forced to broadcast using `ChannelMonitor::broadcast_latest_holder_commitment_txn`. 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 mut chan_config = test_legacy_channel_config(); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(chan_config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -9919,7 +10034,7 @@ pub fn test_dust_exposure_holding_cell_assertion() { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); // Configure nodes with specific dust limits - let mut config = test_default_channel_config(); + let mut config = test_legacy_channel_config(); // Use a fixed dust exposure limit to make the test simpler const DUST_HTLC_VALUE_MSAT: u64 = 500_000; config.channel_config.max_dust_htlc_exposure = MaxDustHTLCExposure::FixedLimitMsat(5_000_000); diff --git a/lightning/src/ln/htlc_reserve_unit_tests.rs b/lightning/src/ln/htlc_reserve_unit_tests.rs index 4c4fbada7dd..5b2ffca5fd4 100644 --- a/lightning/src/ln/htlc_reserve_unit_tests.rs +++ b/lightning/src/ln/htlc_reserve_unit_tests.rs @@ -33,7 +33,9 @@ fn do_test_counterparty_no_reserve(send_from_initiator: bool) { // in normal testing, we test it explicitly here. 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -59,7 +61,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 = @@ -121,7 +123,7 @@ pub fn test_channel_reserve_holding_cell_htlcs() { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); // When this test was written, the default base fee floated based on the HTLC count. // It is now fixed, so we simply set the fee to the expected value here. - let mut config = test_default_channel_config(); + let mut config = test_legacy_channel_config(); config.channel_config.forwarding_fee_base_msat = 239; let configs = [Some(config.clone()), Some(config.clone()), Some(config.clone())]; @@ -749,7 +751,9 @@ pub fn holding_cell_htlc_counting() { pub fn test_basic_channel_reserve() { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000); @@ -778,14 +782,14 @@ pub fn test_basic_channel_reserve() { #[xtest(feature = "_externalize_tests")] fn test_fee_spike_violation_fails_htlc() { - do_test_fee_spike_buffer(None, true) + let cfg = test_legacy_channel_config(); + do_test_fee_spike_buffer(Some(cfg), true) } #[test] 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) } @@ -988,7 +992,9 @@ pub fn test_chan_reserve_violation_outbound_htlc_inbound_chan() { // this situation. let feerate_per_kw = *chanmon_cfgs[0].fee_estimator.sat_per_kw.lock().unwrap(); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let default_config = UserConfig::default(); @@ -1026,7 +1032,9 @@ pub fn test_chan_reserve_violation_inbound_htlc_outbound_channel() { let mut chanmon_cfgs = create_chanmon_cfgs(2); let feerate_per_kw = *chanmon_cfgs[0].fee_estimator.sat_per_kw.lock().unwrap(); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_b_id = nodes[1].node.get_our_node_id(); @@ -1105,7 +1113,9 @@ pub fn test_chan_reserve_dust_inbound_htlcs_outbound_chan() { let feerate_per_kw = *chanmon_cfgs[0].fee_estimator.sat_per_kw.lock().unwrap(); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let default_config = UserConfig::default(); @@ -1154,7 +1164,9 @@ pub fn test_chan_reserve_dust_inbound_htlcs_inbound_chan() { // calculating our counterparty's commitment transaction fee (this was previously broken). 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, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 98000000); @@ -1566,7 +1578,9 @@ pub fn test_update_add_htlc_bolt2_receiver_sender_can_afford_amount_sent() { //BOLT2 Requirement: receiving an amount_msat that the sending node cannot afford at the current feerate_per_kw (while maintaining its channel reserve): SHOULD fail the channel 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -2142,13 +2156,8 @@ pub fn do_test_dust_limit_fee_accounting(can_afford: bool) { let chanmon_cfgs = create_chanmon_cfgs(2); - 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 = - create_node_chanmgrs(2, &node_cfgs, &[Some(default_config.clone()), Some(default_config)]); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); diff --git a/lightning/src/ln/invoice_utils.rs b/lightning/src/ln/invoice_utils.rs index 195eb73595a..1503a9a3a63 100644 --- a/lightning/src/ln/invoice_utils.rs +++ b/lightning/src/ln/invoice_utils.rs @@ -1052,7 +1052,7 @@ 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); @@ -1125,7 +1125,8 @@ mod test { fn test_channels_with_lower_inbound_capacity_than_invoice_amt_hints_filtering() { 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[Some(legacy_cfg), None, None]); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); let chan_1_0 = create_unannounced_chan_between_nodes_with_value(&nodes, 1, 0, 100_000, 0); let chan_2_0 = create_unannounced_chan_between_nodes_with_value(&nodes, 2, 0, 1_000_000, 0); @@ -1583,7 +1584,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); @@ -1731,7 +1732,9 @@ mod test { chanmon_cfgs[1].keys_manager.backing = make_dyn_keys_interface(&seed_1); chanmon_cfgs[2].keys_manager.backing = make_dyn_keys_interface(&seed_2); let node_cfgs = create_node_cfgs(4, &chanmon_cfgs); - let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(4, &node_cfgs, &[Some(legacy_cfg), None, None, None]); let nodes = create_network(4, &node_cfgs, &node_chanmgrs); let chan_0_2 = create_unannounced_chan_between_nodes_with_value(&nodes, 0, 2, 1_000_000, 0); diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index c3266ae317f..cdbd6e669f8 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -175,7 +175,7 @@ fn archive_fully_resolved_monitors() { // Test we archive fully resolved channel monitors at the right time. let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let mut user_config = test_default_channel_config(); + let mut user_config = test_legacy_channel_config(); 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); @@ -319,10 +319,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); @@ -473,7 +471,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); @@ -872,7 +869,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); @@ -1125,7 +1121,8 @@ fn test_no_preimage_inbound_htlc_balances() { // have a preimage. 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 500_000_000); @@ -1383,7 +1380,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); @@ -1687,7 +1683,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); @@ -1977,7 +1972,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); @@ -2254,7 +2248,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); @@ -2325,7 +2318,8 @@ fn do_test_restored_packages_retry(check_old_monitor_retries_after_upgrade: bool let persister; let new_chain_monitor; - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let node_deserialized; let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -2402,7 +2396,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); @@ -2528,7 +2521,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); @@ -2730,7 +2722,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())]); @@ -3037,7 +3028,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); @@ -3128,7 +3118,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); @@ -3419,7 +3408,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())]; @@ -3601,7 +3589,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())]; @@ -3845,7 +3832,8 @@ fn test_ladder_preimage_htlc_claims() { // already claimed) resulting in an invalid claim transaction. 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_id_0 = nodes[0].node.get_our_node_id(); diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index f73c55fd6c6..40fbae5c6ca 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -212,7 +212,7 @@ fn mpp_retry_overpay() { let chanmon_cfgs = create_chanmon_cfgs(4); let node_cfgs = create_node_cfgs(4, &chanmon_cfgs); - let mut user_config = test_default_channel_config(); + let mut user_config = test_legacy_channel_config(); user_config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100; let mut limited_1 = user_config.clone(); limited_1.channel_handshake_config.our_htlc_minimum_msat = 35_000_000; @@ -782,7 +782,12 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let persister; let new_chain_monitor; - let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 3, + &node_cfgs, + &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)], + ); let node_a_reload; let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); @@ -1019,8 +1024,7 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) { let chanmon_cfgs = create_chanmon_cfgs(3); 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 mut legacy_cfg = test_legacy_channel_config(); let persist_1; let chain_monitor_1; @@ -1029,8 +1033,7 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) { let persist_3; let chain_monitor_3; - let node_chanmgrs = - create_node_chanmgrs(3, &node_cfgs, &[None, Some(manually_accept_config), None]); + let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, Some(legacy_cfg), None]); let node_a_1; let node_a_2; let node_a_3; @@ -1255,7 +1258,9 @@ fn do_test_dup_htlc_onchain_doesnt_fail_on_reload( let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let persister; let chain_monitor; - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let node_a_reload; let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -2210,7 +2215,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.htlc_interception_flags = HTLCInterceptionFlags::ToInterceptSCIDs as u8; @@ -2869,7 +2873,9 @@ fn auto_retry_partial_failure() { // Test that we'll retry appropriately on send partial failure and retry partial failure. 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -3114,7 +3120,9 @@ fn auto_retry_partial_failure() { fn auto_retry_zero_attempts_send_error() { 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_b_id = nodes[1].node.get_our_node_id(); @@ -4110,7 +4118,9 @@ fn do_no_missing_sent_on_reload(persist_manager_with_payment: bool, at_midpoint: let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let (persist_a, persist_b, persist_c); let (chain_monitor_a, chain_monitor_b, chain_monitor_c); - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let (node_a_1, node_a_2, node_a_3); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -4251,7 +4261,17 @@ fn do_claim_from_closed_chan(fail_payment: bool) { // CLTVs on the paths to different value resulting in a different claim deadline. let chanmon_cfgs = create_chanmon_cfgs(4); let node_cfgs = create_node_cfgs(4, &chanmon_cfgs); - let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs( + 4, + &node_cfgs, + &[ + Some(legacy_cfg.clone()), + Some(legacy_cfg.clone()), + Some(legacy_cfg.clone()), + Some(legacy_cfg), + ], + ); let mut nodes = create_network(4, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -4959,7 +4979,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; @@ -5142,7 +5161,7 @@ fn test_non_strict_forwarding() { let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); - let mut config = test_default_channel_config(); + let mut config = test_legacy_channel_config(); config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100; let configs = [Some(config.clone()), Some(config.clone()), Some(config)]; diff --git a/lightning/src/ln/priv_short_conf_tests.rs b/lightning/src/ln/priv_short_conf_tests.rs index 2035af15046..9d30d749aa2 100644 --- a/lightning/src/ln/priv_short_conf_tests.rs +++ b/lightning/src/ln/priv_short_conf_tests.rs @@ -448,7 +448,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), @@ -501,7 +501,7 @@ 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); @@ -781,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); @@ -800,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); @@ -997,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); @@ -1024,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); @@ -1086,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())]); @@ -1314,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]); @@ -1322,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); @@ -1330,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()); @@ -1392,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); @@ -1439,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); @@ -1492,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 a8206dfe850..45e454973e6 100644 --- a/lightning/src/ln/reload_tests.rs +++ b/lightning/src/ln/reload_tests.rs @@ -254,7 +254,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); @@ -368,7 +368,8 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() { let persister; let new_chain_monitor; - let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes_0_deserialized; let mut nodes = create_network(4, &node_cfgs, &node_chanmgrs); @@ -523,7 +524,8 @@ fn do_test_data_loss_protect(reconnect_panicing: bool, substantially_old: bool, let persister; let new_chain_monitor; - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes_0_deserialized; let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -931,7 +933,7 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht let persister; let new_chain_monitor; - let mut intercept_forwards_config = test_default_channel_config(); + let mut intercept_forwards_config = test_legacy_channel_config(); intercept_forwards_config.htlc_interception_flags = HTLCInterceptionFlags::ToInterceptSCIDs as u8; let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, Some(intercept_forwards_config), None]); @@ -1109,7 +1111,8 @@ fn removed_payment_no_manager_persistence() { let persister; let new_chain_monitor; - let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes_1_deserialized; let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); @@ -1326,7 +1329,8 @@ fn test_reload_partial_funding_batch() { let new_persister; let new_chain_monitor; - let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg.clone()), Some(legacy_cfg)]); let new_channel_manager; let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); @@ -1461,7 +1465,8 @@ fn test_peer_storage() { let (persister, chain_monitor); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let nodes_0_deserialized; - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -1512,7 +1517,7 @@ fn test_peer_storage() { // TODO: Handle the case where we've completely forgotten about an active channel. reload_node!( nodes[0], - test_default_channel_config(), + test_legacy_channel_config(), &nodes_0_serialized, &[&old_state_monitor[..]], persister, diff --git a/lightning/src/ln/reorg_tests.rs b/lightning/src/ln/reorg_tests.rs index b56caf96008..1a4dab9b925 100644 --- a/lightning/src/ln/reorg_tests.rs +++ b/lightning/src/ln/reorg_tests.rs @@ -49,7 +49,8 @@ fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) { // before they otherwise would and reorg them out, confirming an HTLC-Success tx instead. 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, &[None, None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, Some(legacy_cfg), None]); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); create_announced_chan_between_nodes(&nodes, 0, 1); @@ -182,7 +183,8 @@ fn test_counterparty_revoked_reorg() { // still be claim-from-able after the reorg. 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg), None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 500_000_000); @@ -255,7 +257,8 @@ fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool, use_funding_ let persister; let new_chain_monitor; - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg), None]); let nodes_0_deserialized; let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -316,6 +319,14 @@ fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool, use_funding_ check_added_monitors(&nodes[0], 1); } + let expected_err = "Funding transaction was un-confirmed, originally locked at 6 confs."; + if reload_node && !reorg_after_reload { + handle_announce_close_broadcast_events(&nodes, 0, 1, true, "Channel closed because of an exception: Funding transaction was un-confirmed, originally locked at 6 confs."); + check_added_monitors(&nodes[1], 1); + let reason = ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString(format!("Channel closed because of an exception: {}", expected_err)) }; + check_closed_event(&nodes[1], 1, reason, &[nodes[0].node.get_our_node_id()], 100000); + } + if reload_node { // Since we currently have a background event pending, it's good to test that we survive a // serialization roundtrip. Further, this tests the somewhat awkward edge-case of dropping @@ -386,7 +397,6 @@ fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool, use_funding_ assert_eq!(txn.len(), 1); } - let expected_err = "Funding transaction was un-confirmed, originally locked at 6 confs."; if reorg_after_reload || !reload_node { handle_announce_close_broadcast_events(&nodes, 0, 1, true, "Channel closed because of an exception: Funding transaction was un-confirmed, originally locked at 6 confs."); check_added_monitors(&nodes[1], 1); @@ -404,7 +414,11 @@ 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(); } + create_announced_chan_between_nodes(&nodes, 0, 1); send_payment(&nodes[0], &[&nodes[1]], 8000000); } @@ -455,7 +469,8 @@ fn test_set_outpoints_partial_claiming() { // - disconnect tx, see no tx anymore 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg), None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000); @@ -670,7 +685,8 @@ fn test_htlc_preimage_claim_holder_commitment_after_counterparty_commitment_reor // test that we only claim the currently confirmed commitment. 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, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg), None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes(&nodes, 0, 1); @@ -745,7 +761,8 @@ fn test_htlc_preimage_claim_prev_counterparty_commitment_after_current_counterpa // confirmed commitment. 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, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg), None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes(&nodes, 0, 1); @@ -828,7 +845,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 +1001,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 982dc788f60..d24a4d88d0f 100644 --- a/lightning/src/ln/shutdown_tests.rs +++ b/lightning/src/ln/shutdown_tests.rs @@ -992,6 +992,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); @@ -1020,7 +1031,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()); @@ -1058,6 +1070,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); @@ -1312,7 +1335,8 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) { // it manually. 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]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg), None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); let node_b_id = nodes[1].node.get_our_node_id(); diff --git a/lightning/src/ln/splicing_tests.rs b/lightning/src/ln/splicing_tests.rs index cf93c6243c4..08754799da6 100644 --- a/lightning/src/ln/splicing_tests.rs +++ b/lightning/src/ln/splicing_tests.rs @@ -1066,7 +1066,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_default_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); @@ -1530,7 +1530,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)]); @@ -1819,7 +1818,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_default_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); @@ -1858,7 +1857,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_default_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); @@ -1912,7 +1911,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_default_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); @@ -1966,7 +1965,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_default_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); @@ -2017,7 +2016,7 @@ 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_default_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..24ae8525450 100644 --- a/lightning/src/ln/update_fee_tests.rs +++ b/lightning/src/ln/update_fee_tests.rs @@ -385,18 +385,13 @@ pub fn do_test_update_fee_that_funder_cannot_afford(channel_type_features: Chann let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let mut default_config = test_default_channel_config(); + let mut cfg = test_legacy_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; + cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; } - let node_chanmgrs = create_node_chanmgrs( - 2, - &node_cfgs, - &[Some(default_config.clone()), Some(default_config.clone())], - ); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(cfg.clone()), Some(cfg.clone())]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -413,8 +408,7 @@ pub fn do_test_update_fee_that_funder_cannot_afford(channel_type_features: Chann ); let channel_id = chan.2; let secp_ctx = Secp256k1::new(); - let bs_channel_reserve_sats = - get_holder_selected_channel_reserve_satoshis(channel_value, &default_config); + let bs_channel_reserve_sats = get_holder_selected_channel_reserve_satoshis(channel_value, &cfg); let (anchor_outputs_value_sats, outputs_num_no_htlcs) = if channel_type_features.supports_anchors_zero_fee_htlc_tx() { (ANCHOR_OUTPUT_VALUE_SATOSHI * 2, 4) @@ -548,13 +542,12 @@ pub fn test_update_fee_that_saturates_subs() { // on the commitment transaction that is greater than her balance, we saturate the subtractions, // and force close the channel. - let mut default_config = test_default_channel_config(); + let mut cfg = test_legacy_channel_config(); let secp_ctx = Secp256k1::new(); 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, &[Some(default_config.clone()), Some(default_config)]); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(cfg.clone()), Some(cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -870,7 +863,9 @@ pub fn test_chan_init_feerate_unaffordability() { let mut chanmon_cfgs = create_chanmon_cfgs(2); let feerate_per_kw = *chanmon_cfgs[0].fee_estimator.sat_per_kw.lock().unwrap(); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let node_a_id = nodes[0].node.get_our_node_id(); @@ -898,6 +893,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); @@ -1024,17 +1030,14 @@ pub fn do_cannot_afford_on_holding_cell_release( // update_fee from its holding cell, we do not generate any msg events let chanmon_cfgs = create_chanmon_cfgs(2); - let mut default_config = test_default_channel_config(); - default_config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = - 100; + let mut cfg = test_legacy_channel_config(); + cfg.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 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; + cfg.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true; } let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); - let node_chanmgrs = - create_node_chanmgrs(2, &node_cfgs, &[Some(default_config.clone()), Some(default_config)]); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(cfg.clone()), Some(cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -1211,13 +1214,12 @@ pub fn do_can_afford_given_trimmed_htlcs(inequality_regions: core::cmp::Ordering let chanmon_cfgs = create_chanmon_cfgs(2); - let mut default_config = test_default_channel_config(); - default_config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = - 100; + let mut legacy_cfg = test_legacy_channel_config(); + legacy_cfg.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100; let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = - create_node_chanmgrs(2, &node_cfgs, &[Some(default_config.clone()), Some(default_config)]); + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -1372,7 +1374,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 feb326cfad6..420fad6b1e0 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,13 @@ 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. + /// Upon receiving an [`Event::OpenChannelRequest`] for a channel of this type, you must + /// 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 +178,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 +197,9 @@ 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. + /// Upon receiving an [`Event::OpenChannelRequest`] for a channel of this type, you must + /// 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 +221,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 +252,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, } @@ -998,20 +996,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, /// Flags consisting of OR'd values from [`HTLCInterceptionFlags`] which describe HTLCs /// forwarded over this node to intercept. Any HTLCs which are intercepted will generate an /// [`Event::HTLCIntercepted`] event which must be handled to forward or fail the HTLC. @@ -1092,7 +1076,6 @@ impl Default for UserConfig { channel_config: ChannelConfig::default(), accept_forwards_to_priv_channels: false, accept_inbound_channels: true, - manually_accept_inbound_channels: false, htlc_interception_flags: 0, manually_handle_bolt12_invoices: false, enable_dual_funded_channels: false, @@ -1115,7 +1098,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)?, htlc_interception_flags: Readable::read(reader)?, manually_handle_bolt12_invoices: Readable::read(reader)?, enable_dual_funded_channels: Readable::read(reader)?, diff --git a/lightning/src/util/persist.rs b/lightning/src/util/persist.rs index 1b750c63cd8..cb4bdeb6a51 100644 --- a/lightning/src/util/persist.rs +++ b/lightning/src/util/persist.rs @@ -1657,7 +1657,9 @@ mod tests { ); node_cfgs[0].chain_monitor = chain_mon_0; node_cfgs[1].chain_monitor = chain_mon_1; - let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let legacy_cfg = test_legacy_channel_config(); + let node_chanmgrs = + create_node_chanmgrs(2, &node_cfgs, &[Some(legacy_cfg.clone()), Some(legacy_cfg)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // Check that the persisted channel data is empty before any channels are 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..999b2490939 --- /dev/null +++ b/pending_changelog/4337-manual-channel-accept-default-anchors.txt @@ -0,0 +1,18 @@ +# 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 if the counterparty supports + it, 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. +