@@ -17,9 +17,9 @@ use crate::ln::{PaymentHash, PaymentSecret};
17
17
use crate :: ln:: channel:: EXPIRE_PREV_CONFIG_TICKS ;
18
18
use crate :: ln:: channelmanager:: { self , ChannelManager , ChannelManagerReadArgs , HTLCForwardInfo , CLTV_FAR_FAR_AWAY , MIN_CLTV_EXPIRY_DELTA , PendingHTLCInfo , PendingHTLCRouting } ;
19
19
use crate :: ln:: onion_utils;
20
- use crate :: routing:: gossip:: { NetworkUpdate , RoutingFees , NodeId } ;
20
+ use crate :: routing:: gossip:: { NetworkUpdate , RoutingFees } ;
21
21
use crate :: routing:: router:: { get_route, PaymentParameters , Route , RouteHint , RouteHintHop } ;
22
- use crate :: ln:: features:: { InitFeatures , InvoiceFeatures , NodeFeatures } ;
22
+ use crate :: ln:: features:: InitFeatures ;
23
23
use crate :: ln:: msgs;
24
24
use crate :: ln:: msgs:: { ChannelMessageHandler , ChannelUpdate } ;
25
25
use crate :: ln:: wire:: Encode ;
@@ -790,170 +790,6 @@ fn test_onion_failure_stale_channel_update() {
790
790
do_test_onion_failure_stale_channel_update ( true ) ;
791
791
}
792
792
793
- #[ test]
794
- fn test_default_to_onion_payload_tlv_format ( ) {
795
- // Tests that we default to creating tlv format onion payloads when no `NodeAnnouncementInfo`
796
- // `features` for a node in the `network_graph` exists, or when the node isn't in the
797
- // `network_graph`, and no other known `features` for the node exists.
798
- let mut priv_channels_conf = UserConfig :: default ( ) ;
799
- priv_channels_conf. channel_handshake_config . announced_channel = false ;
800
- let chanmon_cfgs = create_chanmon_cfgs ( 5 ) ;
801
- let node_cfgs = create_node_cfgs ( 5 , & chanmon_cfgs) ;
802
- let node_chanmgrs = create_node_chanmgrs ( 5 , & node_cfgs, & [ None , None , None , None , Some ( priv_channels_conf) ] ) ;
803
- let mut nodes = create_network ( 5 , & node_cfgs, & node_chanmgrs) ;
804
-
805
- create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
806
- create_announced_chan_between_nodes ( & nodes, 1 , 2 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
807
- create_announced_chan_between_nodes ( & nodes, 2 , 3 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
808
- create_unannounced_chan_between_nodes_with_value ( & nodes, 3 , 4 , 100000 , 10001 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
809
-
810
- let payment_params = PaymentParameters :: from_node_id ( nodes[ 3 ] . node . get_our_node_id ( ) ) ;
811
- let origin_node = & nodes[ 0 ] ;
812
- let network_graph = origin_node. network_graph ;
813
-
814
- // Clears all the `NodeAnnouncementInfo` for all nodes of `nodes[0]`'s `network_graph`, so that
815
- // their `features` aren't used when creating the `route`.
816
- network_graph. clear_nodes_announcement_info ( ) ;
817
-
818
- let ( announced_route, _, _, _) = get_route_and_payment_hash ! (
819
- origin_node, nodes[ 3 ] , payment_params, 10_000 , TEST_FINAL_CLTV ) ;
820
-
821
- let hops = & announced_route. paths [ 0 ] ;
822
- // Assert that the hop between `nodes[1]` and `nodes[2]` defaults to supporting variable length
823
- // onions, as `nodes[0]` has no `NodeAnnouncementInfo` `features` for `node[2]`
824
- assert ! ( hops[ 1 ] . node_features. supports_variable_length_onion( ) ) ;
825
- // Assert that the hop between `nodes[2]` and `nodes[3]` defaults to supporting variable length
826
- // onions, as `nodes[0]` has no `NodeAnnouncementInfo` `features` for `node[3]`, and no `InvoiceFeatures`
827
- // for the `payment_params`, which would otherwise have been used.
828
- assert ! ( hops[ 2 ] . node_features. supports_variable_length_onion( ) ) ;
829
- // Note that we do not assert that `hops[0]` (the channel between `nodes[0]` and `nodes[1]`)
830
- // supports variable length onions, as the `InitFeatures` exchanged in the init message
831
- // between the nodes will be used when creating the route. We therefore do not default to
832
- // supporting variable length onions for that hop, as the `InitFeatures` in this case are
833
- // `channelmanager::provided_init_features()`.
834
-
835
- let unannounced_chan = & nodes[ 4 ] . node . list_usable_channels ( ) [ 0 ] ;
836
-
837
- let last_hop = RouteHint ( vec ! [ RouteHintHop {
838
- src_node_id: nodes[ 3 ] . node. get_our_node_id( ) ,
839
- short_channel_id: unannounced_chan. short_channel_id. unwrap( ) ,
840
- fees: RoutingFees {
841
- base_msat: 0 ,
842
- proportional_millionths: 0 ,
843
- } ,
844
- cltv_expiry_delta: 42 ,
845
- htlc_minimum_msat: None ,
846
- htlc_maximum_msat: None ,
847
- } ] ) ;
848
-
849
- let unannounced_chan_params = PaymentParameters :: from_node_id ( nodes[ 4 ] . node . get_our_node_id ( ) ) . with_route_hints ( vec ! [ last_hop] ) ;
850
- let ( unannounced_route, _, _, _) = get_route_and_payment_hash ! (
851
- origin_node, nodes[ 4 ] , unannounced_chan_params, 10_000 , TEST_FINAL_CLTV ) ;
852
-
853
- let unannounced_chan_hop = & unannounced_route. paths [ 0 ] [ 3 ] ;
854
- // Ensure that `nodes[4]` doesn't exist in `nodes[0]`'s `network_graph`, as it's not public.
855
- assert ! ( & network_graph. read_only( ) . nodes( ) . get( & NodeId :: from_pubkey( & nodes[ 4 ] . node. get_our_node_id( ) ) ) . is_none( ) ) ;
856
- // Assert that the hop between `nodes[3]` and `nodes[4]` defaults to supporting variable length
857
- // onions, even though `nodes[4]` as `nodes[0]` doesn't exists in `nodes[0]`'s `network_graph`,
858
- // and no `InvoiceFeatures` for the `payment_params` exists, which would otherwise have been
859
- // used.
860
- assert ! ( unannounced_chan_hop. node_features. supports_variable_length_onion( ) ) ;
861
-
862
- let cur_height = nodes[ 0 ] . best_block_info ( ) . 1 + 1 ;
863
- let ( announced_route_payloads, _htlc_msat, _htlc_cltv) = onion_utils:: build_onion_payloads ( & announced_route. paths [ 0 ] , 40000 , & None , cur_height, & None ) . unwrap ( ) ;
864
- let ( unannounced_route_paylods, _htlc_msat, _htlc_cltv) = onion_utils:: build_onion_payloads ( & unannounced_route. paths [ 0 ] , 40000 , & None , cur_height, & None ) . unwrap ( ) ;
865
-
866
- for onion_payloads in vec ! [ announced_route_payloads, unannounced_route_paylods] {
867
- for onion_payload in onion_payloads. iter ( ) {
868
- match onion_payload. format {
869
- msgs:: OnionHopDataFormat :: Legacy { ..} => {
870
- panic ! ( "Generated a `msgs::OnionHopDataFormat::Legacy` payload, even though that shouldn't have happend." ) ;
871
- }
872
- _ => { }
873
- }
874
- }
875
- }
876
- }
877
-
878
- #[ test]
879
- fn test_do_not_default_to_onion_payload_tlv_format_when_unsupported ( ) {
880
- // Tests that we do not default to creating tlv onions if either of these types features
881
- // exists, which specifies no support for variable length onions for a specific hop, when
882
- // creating a route:
883
- // 1. `InitFeatures` to the counterparty node exchanged with the init message to the node.
884
- // 2. `NodeFeatures` in the `NodeAnnouncementInfo` of a node in sender node's `network_graph`.
885
- // 3. `InvoiceFeatures` specified by the receiving node, when no `NodeAnnouncementInfo`
886
- // `features` exists for the receiver in the sender's `network_graph`.
887
- let chanmon_cfgs = create_chanmon_cfgs ( 4 ) ;
888
- let mut node_cfgs = create_node_cfgs ( 4 , & chanmon_cfgs) ;
889
-
890
- // Set `node[1]` config to `InitFeatures::empty()` + `static_remote_key` which implies
891
- // `!supports_variable_length_onion()` but still supports the required static-remote-key
892
- // feature.
893
- let mut node_1_cfg = & mut node_cfgs[ 1 ] ;
894
- node_1_cfg. features = InitFeatures :: empty ( ) ;
895
- node_1_cfg. features . set_static_remote_key_required ( ) ;
896
-
897
- let node_chanmgrs = create_node_chanmgrs ( 4 , & node_cfgs, & [ None , None , None , None ] ) ;
898
- let mut nodes = create_network ( 4 , & node_cfgs, & node_chanmgrs) ;
899
-
900
- create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
901
- create_announced_chan_between_nodes ( & nodes, 1 , 2 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
902
- create_announced_chan_between_nodes ( & nodes, 2 , 3 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
903
-
904
- let payment_params = PaymentParameters :: from_node_id ( nodes[ 3 ] . node . get_our_node_id ( ) )
905
- . with_features ( InvoiceFeatures :: empty ( ) ) ;
906
- let origin_node = & nodes[ 0 ] ;
907
- let network_graph = origin_node. network_graph ;
908
- network_graph. clear_nodes_announcement_info ( ) ;
909
-
910
- // Set `NodeAnnouncementInfo` `features` which do not support variable length onions for
911
- // `nodes[2]` in `nodes[0]`'s `network_graph`.
912
- let nodes_2_unsigned_node_announcement = msgs:: UnsignedNodeAnnouncement {
913
- features : NodeFeatures :: empty ( ) ,
914
- timestamp : 0 ,
915
- node_id : nodes[ 2 ] . node . get_our_node_id ( ) ,
916
- rgb : [ 32 ; 3 ] ,
917
- alias : [ 16 ; 32 ] ,
918
- addresses : Vec :: new ( ) ,
919
- excess_address_data : Vec :: new ( ) ,
920
- excess_data : Vec :: new ( ) ,
921
- } ;
922
- let _res = network_graph. update_node_from_unsigned_announcement ( & nodes_2_unsigned_node_announcement) ;
923
-
924
- let ( route, _, _, _) = get_route_and_payment_hash ! (
925
- origin_node, nodes[ 3 ] , payment_params, 10_000 , TEST_FINAL_CLTV ) ;
926
-
927
- let hops = & route. paths [ 0 ] ;
928
-
929
- // Assert that the hop between `nodes[0]` and `nodes[1]` doesn't support variable length
930
- // onions, as as the `InitFeatures` exchanged (`InitFeatures::empty()`) in the init message
931
- // between the nodes when setting up the channel is used when creating the `route` and that we
932
- // therefore do not default to supporting variable length onions. Despite `nodes[0]` having no
933
- // `NodeAnnouncementInfo` `features` for `node[1]`.
934
- assert ! ( !hops[ 0 ] . node_features. supports_variable_length_onion( ) ) ;
935
- // Assert that the hop between `nodes[1]` and `nodes[2]` uses the `features` from
936
- // `nodes_2_unsigned_node_announcement` that doesn't support variable length onions.
937
- assert ! ( !hops[ 1 ] . node_features. supports_variable_length_onion( ) ) ;
938
- // Assert that the hop between `nodes[2]` and `nodes[3]` uses the `InvoiceFeatures` set to the
939
- // `payment_params`, that doesn't support variable length onions. We therefore do not end up
940
- // defaulting to supporting variable length onions, despite `nodes[0]` having no
941
- // `NodeAnnouncementInfo` `features` for `node[3]`.
942
- assert ! ( !hops[ 2 ] . node_features. supports_variable_length_onion( ) ) ;
943
-
944
- let cur_height = nodes[ 0 ] . best_block_info ( ) . 1 + 1 ;
945
- let ( onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils:: build_onion_payloads ( & route. paths [ 0 ] , 40000 , & None , cur_height, & None ) . unwrap ( ) ;
946
-
947
- for onion_payload in onion_payloads. iter ( ) {
948
- match onion_payload. format {
949
- msgs:: OnionHopDataFormat :: Legacy { ..} => { }
950
- _ => {
951
- panic ! ( "Should have only have generated `msgs::OnionHopDataFormat::Legacy` payloads" ) ;
952
- }
953
- }
954
- }
955
- }
956
-
957
793
macro_rules! get_phantom_route {
958
794
( $nodes: expr, $amt: expr, $channel: expr) => { {
959
795
let secp_ctx = Secp256k1 :: new( ) ;
0 commit comments