@@ -15026,6 +15026,7 @@ where
1502615026mod tests {
1502715027 use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
1502815028 use bitcoin::secp256k1::ecdh::SharedSecret;
15029+ use lightning_types::features::ChannelTypeFeatures;
1502915030 use core::sync::atomic::Ordering;
1503015031 use crate::events::{Event, HTLCHandlingFailureType, ClosureReason};
1503115032 use crate::ln::onion_utils::AttributionData;
@@ -15041,7 +15042,7 @@ mod tests {
1504115042 use crate::util::errors::APIError;
1504215043 use crate::util::ser::Writeable;
1504315044 use crate::util::test_utils;
15044- use crate::util::config::{ChannelConfig, ChannelConfigUpdate, ChannelHandshakeConfigUpdate};
15045+ use crate::util::config::{ChannelConfig, ChannelConfigUpdate, ChannelHandshakeConfigUpdate, UserConfig };
1504515046 use crate::sign::EntropySource;
1504615047
1504715048 #[test]
@@ -16153,22 +16154,28 @@ mod tests {
1615316154 }
1615416155
1615516156 #[test]
16156- fn test_anchors_zero_fee_htlc_tx_fallback () {
16157+ fn test_anchors_zero_fee_htlc_tx_downgrade () {
1615716158 // Tests that if both nodes support anchors, but the remote node does not want to accept
1615816159 // anchor channels at the moment, an error it sent to the local node such that it can retry
1615916160 // the channel without the anchors feature.
16160- let chanmon_cfgs = create_chanmon_cfgs(2);
16161- let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1616216161 let mut anchors_config = test_default_channel_config();
1616316162 anchors_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
1616416163 anchors_config.manually_accept_inbound_channels = true;
16165- let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(anchors_config.clone()), Some(anchors_config.clone())]);
16164+
16165+ do_test_channel_type_downgrade(anchors_config, |features| features.supports_anchors_zero_fee_htlc_tx())
16166+ }
16167+
16168+ fn do_test_channel_type_downgrade<F>(user_cfg: UserConfig, start_type_set: F)
16169+ where F: Fn(&ChannelTypeFeatures) -> bool {
16170+ let chanmon_cfgs = create_chanmon_cfgs(2);
16171+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
16172+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(user_cfg.clone()), Some(user_cfg.clone())]);
1616616173 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1616716174 let error_message = "Channel force-closed";
1616816175
1616916176 nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 0, 0, None, None).unwrap();
1617016177 let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
16171- assert!(open_channel_msg.common_fields.channel_type.as_ref().unwrap().supports_anchors_zero_fee_htlc_tx( ));
16178+ assert!(start_type_set( open_channel_msg.common_fields.channel_type.as_ref().unwrap()));
1617216179
1617316180 nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg);
1617416181 let events = nodes[1].node.get_and_clear_pending_events();
@@ -16183,7 +16190,7 @@ mod tests {
1618316190 nodes[0].node.handle_error(nodes[1].node.get_our_node_id(), &error_msg);
1618416191
1618516192 let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
16186- assert!(!open_channel_msg.common_fields.channel_type.unwrap ().supports_anchors_zero_fee_htlc_tx( ));
16193+ assert!(!start_type_set( open_channel_msg.common_fields.channel_type.as_ref ().unwrap() ));
1618716194
1618816195 // Since nodes[1] should not have accepted the channel, it should
1618916196 // not have generated any events.
0 commit comments