@@ -11775,10 +11775,11 @@ mod tests {
1177511775 use crate::types::payment::{PaymentHash, PaymentPreimage};
1177611776 use crate::ln::channel_keys::{RevocationKey, RevocationBasepoint};
1177711777 use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
11778- use crate::ln::channel::InitFeatures;
1177911778 use crate::ln::channel::{AwaitingChannelReadyFlags, ChannelState, FundedChannel, InboundHTLCOutput, OutboundV1Channel, InboundV1Channel, OutboundHTLCOutput, InboundHTLCState, OutboundHTLCState, HTLCCandidate, HTLCInitiator, HTLCUpdateAwaitingACK, commit_tx_fee_sat};
1178011779 use crate::ln::channel::{MAX_FUNDING_SATOSHIS_NO_WUMBO, TOTAL_BITCOIN_SUPPLY_SATOSHIS, MIN_THEIR_CHAN_RESERVE_SATOSHIS};
11781- use crate::types::features::{ChannelFeatures, ChannelTypeFeatures, NodeFeatures};
11780+ use crate::types::features::{ChannelFeatures, NodeFeatures};
11781+ #[cfg(ldk_test_vectors)]
11782+ use crate::types::features::ChannelTypeFeatures;
1178211783 use crate::ln::msgs;
1178311784 use crate::ln::msgs::{ChannelUpdate, UnsignedChannelUpdate, MAX_VALUE_MSAT};
1178411785 use crate::ln::script::ShutdownScript;
@@ -13230,192 +13231,6 @@ mod tests {
1323013231 SecretKey::from_slice(&<Vec<u8>>::from_hex("d09ffff62ddb2297ab000cc85bcb4283fdeb6aa052affbc9dddcf33b61078110").unwrap()[..]).unwrap());
1323113232 }
1323213233
13233- #[test]
13234- fn test_zero_conf_channel_type_support() {
13235- let test_est = TestFeeEstimator::new(15000);
13236- let feeest = LowerBoundedFeeEstimator::new(&test_est);
13237- let secp_ctx = Secp256k1::new();
13238- let seed = [42; 32];
13239- let network = Network::Testnet;
13240- let keys_provider = TestKeysInterface::new(&seed, network);
13241- let logger = TestLogger::new();
13242-
13243- let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
13244- let config = UserConfig::default();
13245- let mut node_a_chan = OutboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider,
13246- node_b_node_id, &channelmanager::provided_init_features(&config), 10000000, 100000, 42, &config, 0, 42, None, &logger).unwrap();
13247-
13248- let mut channel_type_features = ChannelTypeFeatures::only_static_remote_key();
13249- channel_type_features.set_zero_conf_required();
13250-
13251- let mut open_channel_msg = node_a_chan.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
13252- open_channel_msg.common_fields.channel_type = Some(channel_type_features);
13253- let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());
13254- let res = InboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider,
13255- node_b_node_id, &channelmanager::provided_channel_type_features(&config),
13256- &channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false);
13257- assert!(res.is_ok());
13258- }
13259-
13260- #[test]
13261- fn test_supports_anchors_zero_htlc_tx_fee() {
13262- // Tests that if both sides support and negotiate `anchors_zero_fee_htlc_tx`, it is the
13263- // resulting `channel_type`.
13264- let secp_ctx = Secp256k1::new();
13265- let test_est = TestFeeEstimator::new(15000);
13266- let fee_estimator = LowerBoundedFeeEstimator::new(&test_est);
13267- let network = Network::Testnet;
13268- let keys_provider = TestKeysInterface::new(&[42; 32], network);
13269- let logger = TestLogger::new();
13270-
13271- let node_id_a = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[1; 32]).unwrap());
13272- let node_id_b = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[2; 32]).unwrap());
13273-
13274- let mut config = UserConfig::default();
13275- config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
13276-
13277- // It is not enough for just the initiator to signal `option_anchors_zero_fee_htlc_tx`, both
13278- // need to signal it.
13279- let channel_a = OutboundV1Channel::<&TestKeysInterface>::new(
13280- &fee_estimator, &&keys_provider, &&keys_provider, node_id_b,
13281- &channelmanager::provided_init_features(&UserConfig::default()), 10000000, 100000, 42,
13282- &config, 0, 42, None, &logger
13283- ).unwrap();
13284- assert!(!channel_a.funding.get_channel_type().supports_anchors_zero_fee_htlc_tx());
13285-
13286- let mut expected_channel_type = ChannelTypeFeatures::empty();
13287- expected_channel_type.set_static_remote_key_required();
13288- expected_channel_type.set_anchors_zero_fee_htlc_tx_required();
13289-
13290- let mut channel_a = OutboundV1Channel::<&TestKeysInterface>::new(
13291- &fee_estimator, &&keys_provider, &&keys_provider, node_id_b,
13292- &channelmanager::provided_init_features(&config), 10000000, 100000, 42, &config, 0, 42,
13293- None, &logger
13294- ).unwrap();
13295-
13296- let open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
13297- let channel_b = InboundV1Channel::<&TestKeysInterface>::new(
13298- &fee_estimator, &&keys_provider, &&keys_provider, node_id_a,
13299- &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config),
13300- &open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
13301- ).unwrap();
13302-
13303- assert_eq!(channel_a.funding.get_channel_type(), &expected_channel_type);
13304- assert_eq!(channel_b.funding.get_channel_type(), &expected_channel_type);
13305- }
13306-
13307- #[test]
13308- fn test_rejects_implicit_simple_anchors() {
13309- // Tests that if `option_anchors` is being negotiated implicitly through the intersection of
13310- // each side's `InitFeatures`, it is rejected.
13311- let secp_ctx = Secp256k1::new();
13312- let test_est = TestFeeEstimator::new(15000);
13313- let fee_estimator = LowerBoundedFeeEstimator::new(&test_est);
13314- let network = Network::Testnet;
13315- let keys_provider = TestKeysInterface::new(&[42; 32], network);
13316- let logger = TestLogger::new();
13317-
13318- let node_id_a = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[1; 32]).unwrap());
13319- let node_id_b = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[2; 32]).unwrap());
13320-
13321- let config = UserConfig::default();
13322-
13323- // See feature bit assignments: https://github.com/lightning/bolts/blob/master/09-features.md
13324- let static_remote_key_required: u64 = 1 << 12;
13325- let simple_anchors_required: u64 = 1 << 20;
13326- let raw_init_features = static_remote_key_required | simple_anchors_required;
13327- let init_features_with_simple_anchors = InitFeatures::from_le_bytes(raw_init_features.to_le_bytes().to_vec());
13328-
13329- let mut channel_a = OutboundV1Channel::<&TestKeysInterface>::new(
13330- &fee_estimator, &&keys_provider, &&keys_provider, node_id_b,
13331- &channelmanager::provided_init_features(&config), 10000000, 100000, 42, &config, 0, 42,
13332- None, &logger
13333- ).unwrap();
13334-
13335- // Set `channel_type` to `None` to force the implicit feature negotiation.
13336- let mut open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
13337- open_channel_msg.common_fields.channel_type = None;
13338-
13339- // Since A supports both `static_remote_key` and `option_anchors`, but B only accepts
13340- // `static_remote_key`, it will fail the channel.
13341- let channel_b = InboundV1Channel::<&TestKeysInterface>::new(
13342- &fee_estimator, &&keys_provider, &&keys_provider, node_id_a,
13343- &channelmanager::provided_channel_type_features(&config), &init_features_with_simple_anchors,
13344- &open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
13345- );
13346- assert!(channel_b.is_err());
13347- }
13348-
13349- #[test]
13350- fn test_rejects_simple_anchors_channel_type() {
13351- // Tests that if `option_anchors` is being negotiated through the `channel_type` feature,
13352- // it is rejected.
13353- let secp_ctx = Secp256k1::new();
13354- let test_est = TestFeeEstimator::new(15000);
13355- let fee_estimator = LowerBoundedFeeEstimator::new(&test_est);
13356- let network = Network::Testnet;
13357- let keys_provider = TestKeysInterface::new(&[42; 32], network);
13358- let logger = TestLogger::new();
13359-
13360- let node_id_a = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[1; 32]).unwrap());
13361- let node_id_b = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[2; 32]).unwrap());
13362-
13363- let config = UserConfig::default();
13364-
13365- // See feature bit assignments: https://github.com/lightning/bolts/blob/master/09-features.md
13366- let static_remote_key_required: u64 = 1 << 12;
13367- let simple_anchors_required: u64 = 1 << 20;
13368- let simple_anchors_raw_features = static_remote_key_required | simple_anchors_required;
13369- let simple_anchors_init = InitFeatures::from_le_bytes(simple_anchors_raw_features.to_le_bytes().to_vec());
13370- let simple_anchors_channel_type = ChannelTypeFeatures::from_le_bytes(simple_anchors_raw_features.to_le_bytes().to_vec());
13371- assert!(!simple_anchors_init.requires_unknown_bits());
13372- assert!(!simple_anchors_channel_type.requires_unknown_bits());
13373-
13374- // First, we'll try to open a channel between A and B where A requests a channel type for
13375- // the original `option_anchors` feature (non zero fee htlc tx). This should be rejected by
13376- // B as it's not supported by LDK.
13377- let mut channel_a = OutboundV1Channel::<&TestKeysInterface>::new(
13378- &fee_estimator, &&keys_provider, &&keys_provider, node_id_b,
13379- &channelmanager::provided_init_features(&config), 10000000, 100000, 42, &config, 0, 42,
13380- None, &logger
13381- ).unwrap();
13382-
13383- let mut open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
13384- open_channel_msg.common_fields.channel_type = Some(simple_anchors_channel_type.clone());
13385-
13386- let res = InboundV1Channel::<&TestKeysInterface>::new(
13387- &fee_estimator, &&keys_provider, &&keys_provider, node_id_a,
13388- &channelmanager::provided_channel_type_features(&config), &simple_anchors_init,
13389- &open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
13390- );
13391- assert!(res.is_err());
13392-
13393- // Then, we'll try to open another channel where A requests a channel type for
13394- // `anchors_zero_fee_htlc_tx`. B is malicious and tries to downgrade the channel type to the
13395- // original `option_anchors` feature, which should be rejected by A as it's not supported by
13396- // LDK.
13397- let mut channel_a = OutboundV1Channel::<&TestKeysInterface>::new(
13398- &fee_estimator, &&keys_provider, &&keys_provider, node_id_b, &simple_anchors_init,
13399- 10000000, 100000, 42, &config, 0, 42, None, &logger
13400- ).unwrap();
13401-
13402- let open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
13403-
13404- let mut channel_b = InboundV1Channel::<&TestKeysInterface>::new(
13405- &fee_estimator, &&keys_provider, &&keys_provider, node_id_a,
13406- &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config),
13407- &open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
13408- ).unwrap();
13409-
13410- let mut accept_channel_msg = channel_b.get_accept_channel_message(&&logger).unwrap();
13411- accept_channel_msg.common_fields.channel_type = Some(simple_anchors_channel_type.clone());
13412-
13413- let res = channel_a.accept_channel(
13414- &accept_channel_msg, &config.channel_handshake_limits, &simple_anchors_init
13415- );
13416- assert!(res.is_err());
13417- }
13418-
1341913234 #[test]
1342013235 fn test_waiting_for_batch() {
1342113236 let test_est = TestFeeEstimator::new(15000);
0 commit comments