@@ -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 ( ) ,
@@ -941,17 +933,19 @@ impl Router {
941
933
942
934
for chan_id in $node. channels. iter( ) {
943
935
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) ;
936
+ if !chan. features. requires_unknown_bits( ) {
937
+ if chan. one_to_two. src_node_id == * $node_id {
938
+ // ie $node is one, ie next hop in A* is two, via the two_to_one channel
939
+ if first_hops. is_none( ) || chan. two_to_one. src_node_id != network. our_node_id {
940
+ if chan. two_to_one. enabled {
941
+ add_entry!( chan_id, chan. one_to_two. src_node_id, chan. two_to_one, $fee_to_target_msat) ;
942
+ }
949
943
}
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 ) ;
944
+ } else {
945
+ if first_hops . is_none ( ) || chan . one_to_two . src_node_id != network . our_node_id {
946
+ if chan. one_to_two. enabled {
947
+ add_entry! ( chan_id , chan. two_to_one . src_node_id , chan . one_to_two , $fee_to_target_msat ) ;
948
+ }
955
949
}
956
950
}
957
951
}
@@ -1015,7 +1009,7 @@ mod tests {
1015
1009
use chain:: chaininterface;
1016
1010
use ln:: channelmanager;
1017
1011
use ln:: router:: { Router , NodeInfo , NetworkMap , ChannelInfo , DirectionalChannelInfo , RouteHint } ;
1018
- use ln:: msgs:: { Features , FeatureContextChannel , FeatureContextNode } ;
1012
+ use ln:: msgs:: { Features , FeatureContextChannel , FeatureContextNode , LightningError , ErrorAction } ;
1019
1013
use util:: test_utils;
1020
1014
use util:: test_utils:: TestVecWriter ;
1021
1015
use util:: logger:: Logger ;
@@ -1441,6 +1435,49 @@ mod tests {
1441
1435
assert_eq ! ( route. hops[ 1 ] . cltv_expiry_delta, 42 ) ;
1442
1436
}
1443
1437
1438
+ { // Disable 4 and 12 by requiring unknown feature bits
1439
+ let mut network = router. network_map . write ( ) . unwrap ( ) ;
1440
+ network. channels . get_mut ( & NetworkMap :: get_key ( 4 , zero_hash. clone ( ) ) ) . unwrap ( ) . features . set_require_unknown_bits ( ) ;
1441
+ network. channels . get_mut ( & NetworkMap :: get_key ( 12 , zero_hash. clone ( ) ) ) . unwrap ( ) . features . set_require_unknown_bits ( ) ;
1442
+ }
1443
+
1444
+ { // If all the channels require some features we don't understand, route should fail
1445
+ if let Err ( LightningError { err, action : ErrorAction :: IgnoreError } ) = router. get_route ( & node3, None , & Vec :: new ( ) , 100 , 42 ) {
1446
+ assert_eq ! ( err, "Failed to find a path to the given destination" ) ;
1447
+ } else { panic ! ( ) ; }
1448
+ }
1449
+
1450
+ { // If we specify a channel to node8, that overrides our local channel view and that gets used
1451
+ let our_chans = vec ! [ channelmanager:: ChannelDetails {
1452
+ channel_id: [ 0 ; 32 ] ,
1453
+ short_channel_id: Some ( 42 ) ,
1454
+ remote_network_id: node8. clone( ) ,
1455
+ channel_value_satoshis: 0 ,
1456
+ user_id: 0 ,
1457
+ outbound_capacity_msat: 0 ,
1458
+ inbound_capacity_msat: 0 ,
1459
+ is_live: true ,
1460
+ } ] ;
1461
+ let route = router. get_route ( & node3, Some ( & our_chans) , & Vec :: new ( ) , 100 , 42 ) . unwrap ( ) ;
1462
+ assert_eq ! ( route. hops. len( ) , 2 ) ;
1463
+
1464
+ assert_eq ! ( route. hops[ 0 ] . pubkey, node8) ;
1465
+ assert_eq ! ( route. hops[ 0 ] . short_channel_id, 42 ) ;
1466
+ assert_eq ! ( route. hops[ 0 ] . fee_msat, 200 ) ;
1467
+ assert_eq ! ( route. hops[ 0 ] . cltv_expiry_delta, ( 13 << 8 ) | 1 ) ;
1468
+
1469
+ assert_eq ! ( route. hops[ 1 ] . pubkey, node3) ;
1470
+ assert_eq ! ( route. hops[ 1 ] . short_channel_id, 13 ) ;
1471
+ assert_eq ! ( route. hops[ 1 ] . fee_msat, 100 ) ;
1472
+ assert_eq ! ( route. hops[ 1 ] . cltv_expiry_delta, 42 ) ;
1473
+ }
1474
+
1475
+ { // Re-enable 4 and 12 by wiping the unknown feature bits
1476
+ let mut network = router. network_map . write ( ) . unwrap ( ) ;
1477
+ network. channels . get_mut ( & NetworkMap :: get_key ( 4 , zero_hash. clone ( ) ) ) . unwrap ( ) . features . clear_require_unknown_bits ( ) ;
1478
+ network. channels . get_mut ( & NetworkMap :: get_key ( 12 , zero_hash. clone ( ) ) ) . unwrap ( ) . features . clear_require_unknown_bits ( ) ;
1479
+ }
1480
+
1444
1481
{ // Route to 1 via 2 and 3 because our channel to 1 is disabled
1445
1482
let route = router. get_route ( & node1, None , & Vec :: new ( ) , 100 , 42 ) . unwrap ( ) ;
1446
1483
assert_eq ! ( route. hops. len( ) , 3 ) ;
0 commit comments