@@ -414,10 +414,6 @@ impl RoutingMessageHandler for Router {
414
414
let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. contents. encode( ) [ ..] ) [ ..] ) ;
415
415
secp_verify_sig ! ( self . secp_ctx, & msg_hash, & msg. signature, & msg. contents. node_id) ;
416
416
417
- if msg. contents . features . requires_unknown_bits ( ) {
418
- panic ! ( "Unknown-required-features NodeAnnouncements should never deserialize!" ) ;
419
- }
420
-
421
417
let mut network = self . network_map . write ( ) . unwrap ( ) ;
422
418
match network. nodes . get_mut ( & msg. contents . node_id ) {
423
419
None => Err ( LightningError { err : "No existing channels for node_announcement" , action : ErrorAction :: IgnoreError } ) ,
@@ -432,7 +428,7 @@ impl RoutingMessageHandler for Router {
432
428
node. alias = msg. contents . alias ;
433
429
node. addresses = msg. contents . addresses . clone ( ) ;
434
430
435
- let should_relay = msg. contents . excess_data . is_empty ( ) && msg. contents . excess_address_data . is_empty ( ) && !msg . contents . features . supports_unknown_bits ( ) ;
431
+ let should_relay = msg. contents . excess_data . is_empty ( ) && msg. contents . excess_address_data . is_empty ( ) ;
436
432
node. announcement_message = if should_relay { Some ( msg. clone ( ) ) } else { None } ;
437
433
Ok ( should_relay)
438
434
}
@@ -450,10 +446,6 @@ impl RoutingMessageHandler for Router {
450
446
secp_verify_sig ! ( self . secp_ctx, & msg_hash, & msg. bitcoin_signature_1, & msg. contents. bitcoin_key_1) ;
451
447
secp_verify_sig ! ( self . secp_ctx, & msg_hash, & msg. bitcoin_signature_2, & msg. contents. bitcoin_key_2) ;
452
448
453
- if msg. contents . features . requires_unknown_bits ( ) {
454
- panic ! ( "Unknown-required-features ChannelAnnouncements should never deserialize!" ) ;
455
- }
456
-
457
449
let checked_utxo = match self . chain_monitor . get_chain_utxo ( msg. contents . chain_hash , msg. contents . short_channel_id ) {
458
450
Ok ( ( script_pubkey, _value) ) => {
459
451
let expected_script = Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHNUM_2 )
@@ -483,7 +475,7 @@ impl RoutingMessageHandler for Router {
483
475
let mut network_lock = self . network_map . write ( ) . unwrap ( ) ;
484
476
let network = network_lock. borrow_parts ( ) ;
485
477
486
- let should_relay = msg. contents . excess_data . is_empty ( ) && !msg . contents . features . supports_unknown_bits ( ) ;
478
+ let should_relay = msg. contents . excess_data . is_empty ( ) ;
487
479
488
480
let chan_info = ChannelInfo {
489
481
features : msg. contents . features . clone ( ) ,
@@ -939,19 +931,23 @@ impl Router {
939
931
}
940
932
}
941
933
942
- for chan_id in $node. channels. iter( ) {
943
- let chan = network. channels. get( chan_id) . unwrap( ) ;
944
- if chan. one_to_two. src_node_id == * $node_id {
945
- // ie $node is one, ie next hop in A* is two, via the two_to_one channel
946
- if first_hops. is_none( ) || chan. two_to_one. src_node_id != network. our_node_id {
947
- if chan. two_to_one. enabled {
948
- add_entry!( chan_id, chan. one_to_two. src_node_id, chan. two_to_one, $fee_to_target_msat) ;
949
- }
950
- }
951
- } else {
952
- if first_hops. is_none( ) || chan. one_to_two. src_node_id != network. our_node_id {
953
- if chan. one_to_two. enabled {
954
- add_entry!( chan_id, chan. two_to_one. src_node_id, chan. one_to_two, $fee_to_target_msat) ;
934
+ if !$node. features. requires_unknown_bits( ) {
935
+ for chan_id in $node. channels. iter( ) {
936
+ let chan = network. channels. get( chan_id) . unwrap( ) ;
937
+ if !chan. features. requires_unknown_bits( ) {
938
+ if chan. one_to_two. src_node_id == * $node_id {
939
+ // ie $node is one, ie next hop in A* is two, via the two_to_one channel
940
+ if first_hops. is_none( ) || chan. two_to_one. src_node_id != network. our_node_id {
941
+ if chan. two_to_one. enabled {
942
+ add_entry!( chan_id, chan. one_to_two. src_node_id, chan. two_to_one, $fee_to_target_msat) ;
943
+ }
944
+ }
945
+ } else {
946
+ if first_hops. is_none( ) || chan. one_to_two. src_node_id != network. our_node_id {
947
+ if chan. one_to_two. enabled {
948
+ add_entry!( chan_id, chan. two_to_one. src_node_id, chan. one_to_two, $fee_to_target_msat) ;
949
+ }
950
+ }
955
951
}
956
952
}
957
953
}
@@ -1015,7 +1011,7 @@ mod tests {
1015
1011
use chain:: chaininterface;
1016
1012
use ln:: channelmanager;
1017
1013
use ln:: router:: { Router , NodeInfo , NetworkMap , ChannelInfo , DirectionalChannelInfo , RouteHint } ;
1018
- use ln:: msgs:: { ChannelFeatures , NodeFeatures } ;
1014
+ use ln:: msgs:: { ChannelFeatures , NodeFeatures , LightningError , ErrorAction } ;
1019
1015
use util:: test_utils;
1020
1016
use util:: test_utils:: TestVecWriter ;
1021
1017
use util:: logger:: Logger ;
@@ -1441,6 +1437,98 @@ mod tests {
1441
1437
assert_eq ! ( route. hops[ 1 ] . cltv_expiry_delta, 42 ) ;
1442
1438
}
1443
1439
1440
+ { // Disable 4 and 12 by requiring unknown feature bits
1441
+ let mut network = router. network_map . write ( ) . unwrap ( ) ;
1442
+ network. channels . get_mut ( & NetworkMap :: get_key ( 4 , zero_hash. clone ( ) ) ) . unwrap ( ) . features . set_require_unknown_bits ( ) ;
1443
+ network. channels . get_mut ( & NetworkMap :: get_key ( 12 , zero_hash. clone ( ) ) ) . unwrap ( ) . features . set_require_unknown_bits ( ) ;
1444
+ }
1445
+
1446
+ { // If all the channels require some features we don't understand, route should fail
1447
+ if let Err ( LightningError { err, action : ErrorAction :: IgnoreError } ) = router. get_route ( & node3, None , & Vec :: new ( ) , 100 , 42 ) {
1448
+ assert_eq ! ( err, "Failed to find a path to the given destination" ) ;
1449
+ } else { panic ! ( ) ; }
1450
+ }
1451
+
1452
+ { // If we specify a channel to node8, that overrides our local channel view and that gets used
1453
+ let our_chans = vec ! [ channelmanager:: ChannelDetails {
1454
+ channel_id: [ 0 ; 32 ] ,
1455
+ short_channel_id: Some ( 42 ) ,
1456
+ remote_network_id: node8. clone( ) ,
1457
+ channel_value_satoshis: 0 ,
1458
+ user_id: 0 ,
1459
+ outbound_capacity_msat: 0 ,
1460
+ inbound_capacity_msat: 0 ,
1461
+ is_live: true ,
1462
+ } ] ;
1463
+ let route = router. get_route ( & node3, Some ( & our_chans) , & Vec :: new ( ) , 100 , 42 ) . unwrap ( ) ;
1464
+ assert_eq ! ( route. hops. len( ) , 2 ) ;
1465
+
1466
+ assert_eq ! ( route. hops[ 0 ] . pubkey, node8) ;
1467
+ assert_eq ! ( route. hops[ 0 ] . short_channel_id, 42 ) ;
1468
+ assert_eq ! ( route. hops[ 0 ] . fee_msat, 200 ) ;
1469
+ assert_eq ! ( route. hops[ 0 ] . cltv_expiry_delta, ( 13 << 8 ) | 1 ) ;
1470
+
1471
+ assert_eq ! ( route. hops[ 1 ] . pubkey, node3) ;
1472
+ assert_eq ! ( route. hops[ 1 ] . short_channel_id, 13 ) ;
1473
+ assert_eq ! ( route. hops[ 1 ] . fee_msat, 100 ) ;
1474
+ assert_eq ! ( route. hops[ 1 ] . cltv_expiry_delta, 42 ) ;
1475
+ }
1476
+
1477
+ { // Re-enable 4 and 12 by wiping the unknown feature bits
1478
+ let mut network = router. network_map . write ( ) . unwrap ( ) ;
1479
+ network. channels . get_mut ( & NetworkMap :: get_key ( 4 , zero_hash. clone ( ) ) ) . unwrap ( ) . features . clear_require_unknown_bits ( ) ;
1480
+ network. channels . get_mut ( & NetworkMap :: get_key ( 12 , zero_hash. clone ( ) ) ) . unwrap ( ) . features . clear_require_unknown_bits ( ) ;
1481
+ }
1482
+
1483
+ { // Disable nodes 1, 2, and 8 by requiring unknown feature bits
1484
+ let mut network = router. network_map . write ( ) . unwrap ( ) ;
1485
+ network. nodes . get_mut ( & node1) . unwrap ( ) . features . set_require_unknown_bits ( ) ;
1486
+ network. nodes . get_mut ( & node2) . unwrap ( ) . features . set_require_unknown_bits ( ) ;
1487
+ network. nodes . get_mut ( & node8) . unwrap ( ) . features . set_require_unknown_bits ( ) ;
1488
+ }
1489
+
1490
+ { // If all nodes require some features we don't understand, route should fail
1491
+ if let Err ( LightningError { err, action : ErrorAction :: IgnoreError } ) = router. get_route ( & node3, None , & Vec :: new ( ) , 100 , 42 ) {
1492
+ assert_eq ! ( err, "Failed to find a path to the given destination" ) ;
1493
+ } else { panic ! ( ) ; }
1494
+ }
1495
+
1496
+ { // If we specify a channel to node8, that overrides our local channel view and that gets used
1497
+ let our_chans = vec ! [ channelmanager:: ChannelDetails {
1498
+ channel_id: [ 0 ; 32 ] ,
1499
+ short_channel_id: Some ( 42 ) ,
1500
+ remote_network_id: node8. clone( ) ,
1501
+ channel_value_satoshis: 0 ,
1502
+ user_id: 0 ,
1503
+ outbound_capacity_msat: 0 ,
1504
+ inbound_capacity_msat: 0 ,
1505
+ is_live: true ,
1506
+ } ] ;
1507
+ let route = router. get_route ( & node3, Some ( & our_chans) , & Vec :: new ( ) , 100 , 42 ) . unwrap ( ) ;
1508
+ assert_eq ! ( route. hops. len( ) , 2 ) ;
1509
+
1510
+ assert_eq ! ( route. hops[ 0 ] . pubkey, node8) ;
1511
+ assert_eq ! ( route. hops[ 0 ] . short_channel_id, 42 ) ;
1512
+ assert_eq ! ( route. hops[ 0 ] . fee_msat, 200 ) ;
1513
+ assert_eq ! ( route. hops[ 0 ] . cltv_expiry_delta, ( 13 << 8 ) | 1 ) ;
1514
+
1515
+ assert_eq ! ( route. hops[ 1 ] . pubkey, node3) ;
1516
+ assert_eq ! ( route. hops[ 1 ] . short_channel_id, 13 ) ;
1517
+ assert_eq ! ( route. hops[ 1 ] . fee_msat, 100 ) ;
1518
+ assert_eq ! ( route. hops[ 1 ] . cltv_expiry_delta, 42 ) ;
1519
+ }
1520
+
1521
+ { // Re-enable nodes 1, 2, and 8
1522
+ let mut network = router. network_map . write ( ) . unwrap ( ) ;
1523
+ network. nodes . get_mut ( & node1) . unwrap ( ) . features . clear_require_unknown_bits ( ) ;
1524
+ network. nodes . get_mut ( & node2) . unwrap ( ) . features . clear_require_unknown_bits ( ) ;
1525
+ network. nodes . get_mut ( & node8) . unwrap ( ) . features . clear_require_unknown_bits ( ) ;
1526
+ }
1527
+
1528
+ // Note that we don't test disabling node 3 and failing to route to it, as we (somewhat
1529
+ // naively) assume that the user checked the feature bits on the invoice, which override
1530
+ // the node_announcement.
1531
+
1444
1532
{ // Route to 1 via 2 and 3 because our channel to 1 is disabled
1445
1533
let route = router. get_route ( & node1, None , & Vec :: new ( ) , 100 , 42 ) . unwrap ( ) ;
1446
1534
assert_eq ! ( route. hops. len( ) , 3 ) ;
0 commit comments