Skip to content

Commit b525e38

Browse files
committed
f - feature bit in fuzz test and test case for rejecting channel
1 parent 70be9bc commit b525e38

File tree

2 files changed

+75
-6
lines changed

2 files changed

+75
-6
lines changed

fuzz/src/full_stack.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
10671067
// inbound read from peer id 0 of len 32
10681068
ext_from_hex("030020", &mut test);
10691069
// init message (type 16) with static_remotekey required, no anchors/taproot, and other bits optional and mac
1070-
ext_from_hex("0010 00021aaa 0008aaa218aa2a0a9aaa 03000000000000000000000000000000", &mut test);
1070+
ext_from_hex("0010 00021aaa 0008aaa210aa2a0a9aaa 03000000000000000000000000000000", &mut test);
10711071

10721072
// inbound read from peer id 0 of len 18
10731073
ext_from_hex("030012", &mut test);
@@ -1168,7 +1168,7 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
11681168
// inbound read from peer id 1 of len 32
11691169
ext_from_hex("030120", &mut test);
11701170
// init message (type 16) with static_remotekey required, no anchors/taproot, and other bits optional and mac
1171-
ext_from_hex("0010 00021aaa 0008aaa218aa2a0a9aaa 01000000000000000000000000000000", &mut test);
1171+
ext_from_hex("0010 00021aaa 0008aaa210aa2a0a9aaa 01000000000000000000000000000000", &mut test);
11721172

11731173
// create outbound channel to peer 1 for 50k sat
11741174
ext_from_hex(
@@ -1582,8 +1582,8 @@ fn gossip_exchange_seed() -> Vec<u8> {
15821582
ext_from_hex("0010 03000000000000000000000000000000", &mut test);
15831583
// inbound read from peer id 0 of len 32
15841584
ext_from_hex("030020", &mut test);
1585-
// init message (type 16) with static_remotekey required, no channel_type/anchors/taproot, and other bits optional and mac
1586-
ext_from_hex("0010 00021aaa 0008aaa218aa2a0a9aaa 03000000000000000000000000000000", &mut test);
1585+
// init message (type 16) with static_remotekey required, no anchors/taproot, and other bits optional and mac
1586+
ext_from_hex("0010 00021aaa 0008aaa210aa2a0a9aaa 03000000000000000000000000000000", &mut test);
15871587

15881588
// new inbound connection with id 1
15891589
ext_from_hex("01", &mut test);
@@ -1602,8 +1602,8 @@ fn gossip_exchange_seed() -> Vec<u8> {
16021602
ext_from_hex("0010 01000000000000000000000000000000", &mut test);
16031603
// inbound read from peer id 1 of len 32
16041604
ext_from_hex("030120", &mut test);
1605-
// init message (type 16) with static_remotekey required, no channel_type/anchors/taproot, and other bits optional and mac
1606-
ext_from_hex("0010 00021aaa 0008aaa218aa2a0a9aaa 01000000000000000000000000000000", &mut test);
1605+
// init message (type 16) with static_remotekey required, no anchors/taproot, and other bits optional and mac
1606+
ext_from_hex("0010 00021aaa 0008aaa210aa2a0a9aaa 01000000000000000000000000000000", &mut test);
16071607

16081608
// inbound read from peer id 0 of len 18
16091609
ext_from_hex("030012", &mut test);

lightning/src/ln/channel_type_tests.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,75 @@ fn test_rejects_if_channel_type_not_set() {
380380
assert!(res.is_err());
381381
}
382382

383+
#[test]
384+
fn test_rejects_if_channel_type_differ() {
385+
// Tests that if the `channel_type` in `accept_channel` does not match the one set in
386+
// `open_channel` it rejects the channel.
387+
let secp_ctx = Secp256k1::new();
388+
let test_est = TestFeeEstimator::new(15000);
389+
let fee_estimator = LowerBoundedFeeEstimator::new(&test_est);
390+
let network = Network::Testnet;
391+
let keys_provider = TestKeysInterface::new(&[42; 32], network);
392+
let logger = TestLogger::new();
393+
394+
let node_id_a =
395+
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[1; 32]).unwrap());
396+
let node_id_b =
397+
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[2; 32]).unwrap());
398+
399+
let config = UserConfig::default();
400+
401+
let mut channel_a = OutboundV1Channel::<&TestKeysInterface>::new(
402+
&fee_estimator,
403+
&&keys_provider,
404+
&&keys_provider,
405+
node_id_b,
406+
&channelmanager::provided_init_features(&config),
407+
10000000,
408+
100000,
409+
42,
410+
&config,
411+
0,
412+
42,
413+
None,
414+
&logger,
415+
)
416+
.unwrap();
417+
418+
let open_channel_msg =
419+
channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
420+
421+
let mut channel_b = InboundV1Channel::<&TestKeysInterface>::new(
422+
&fee_estimator,
423+
&&keys_provider,
424+
&&keys_provider,
425+
node_id_a,
426+
&channelmanager::provided_channel_type_features(&config),
427+
&channelmanager::provided_init_features(&config),
428+
&open_channel_msg,
429+
7,
430+
&config,
431+
0,
432+
&&logger,
433+
/*is_0conf=*/ false,
434+
)
435+
.unwrap();
436+
437+
// Change the `channel_type` in `accept_channel` msg to make it different from the one set in
438+
// `open_channel` to cause failure.
439+
let mut accept_channel_msg = channel_b.get_accept_channel_message(&&logger).unwrap();
440+
let mut channel_type = channelmanager::provided_channel_type_features(&config);
441+
channel_type.set_zero_conf_required();
442+
accept_channel_msg.common_fields.channel_type = Some(channel_type.clone());
443+
444+
let res = channel_a.accept_channel(
445+
&accept_channel_msg,
446+
&config.channel_handshake_limits,
447+
&channelmanager::provided_init_features(&config),
448+
);
449+
assert!(res.is_err());
450+
}
451+
383452
#[test]
384453
fn test_rejects_simple_anchors_channel_type() {
385454
// Tests that if `option_anchors` is being negotiated through the `channel_type` feature,

0 commit comments

Comments
 (0)