@@ -19,7 +19,7 @@ use ln::channelmanager::{self, ChannelManager, ChannelManagerReadArgs, HTLCForwa
19
19
use ln:: onion_utils;
20
20
use routing:: gossip:: { NetworkUpdate , RoutingFees } ;
21
21
use routing:: router:: { get_route, PaymentParameters , Route , RouteHint , RouteHintHop } ;
22
- use ln:: features:: InitFeatures ;
22
+ use ln:: features:: { InitFeatures , InvoiceFeatures } ;
23
23
use ln:: msgs;
24
24
use ln:: msgs:: { ChannelMessageHandler , ChannelUpdate } ;
25
25
use ln:: wire:: Encode ;
@@ -791,7 +791,10 @@ fn test_onion_failure_stale_channel_update() {
791
791
}
792
792
793
793
#[ test]
794
- fn test_always_create_onion_payload_tlv_format ( ) {
794
+ fn test_always_create_tlv_format_onion_payloads ( ) {
795
+ // Verify that we always generate tlv onion format payloads, even if the features specifically
796
+ // specifies no support for variable length onions, as the legacy payload format has been
797
+ // deprecated in BOLT4.
795
798
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
796
799
let mut node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
797
800
@@ -808,26 +811,32 @@ fn test_always_create_onion_payload_tlv_format() {
808
811
create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: empty ( ) , InitFeatures :: empty ( ) ) ;
809
812
create_announced_chan_between_nodes ( & nodes, 1 , 2 , InitFeatures :: empty ( ) , InitFeatures :: empty ( ) ) ;
810
813
811
- let ( route, _payment_hash, _payment_preimage, _payment_secret) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , 40000 ) ;
814
+ let payment_params = PaymentParameters :: from_node_id ( nodes[ 2 ] . node . get_our_node_id ( ) )
815
+ . with_features ( InvoiceFeatures :: empty ( ) ) ;
816
+ let ( route, _payment_hash, _payment_preimage, _payment_secret) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , payment_params, 40000 , TEST_FINAL_CLTV ) ;
812
817
813
818
let hops = & route. paths [ 0 ] ;
814
- // Asserts that the first hop to `node[1]` returns `false` for
815
- // `node_features.supports_variable_length_onion()`
819
+ // Asserts that the first hop to `node[1]` signals no support for variable length onions.
816
820
assert ! ( !hops[ 0 ] . node_features. supports_variable_length_onion( ) ) ;
817
- // Asserts that the second hop to `node[2]` returns `true` for
818
- // `node_features.supports_variable_length_onion()`
819
- assert ! ( hops[ 1 ] . node_features. supports_variable_length_onion( ) ) ;
821
+ // Asserts that the first hop to `node[1]` signals no support for variable length onions.
822
+ assert ! ( !hops[ 1 ] . node_features. supports_variable_length_onion( ) ) ;
820
823
821
824
let cur_height = nodes[ 0 ] . best_block_info ( ) . 1 + 1 ;
822
825
let ( onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils:: build_onion_payloads ( & route. paths [ 0 ] , 40000 , & None , cur_height, & None ) . unwrap ( ) ;
823
826
824
- for onion_payload in onion_payloads. iter ( ) {
825
- match onion_payload. format {
826
- msgs:: OnionHopDataFormat :: Legacy { ..} => {
827
- panic ! ( "`onion_utils::build_onion_payloads` generated a `msgs::OnionHopDataFormat::Legacy` payload" ) ;
828
- }
829
- _ => { }
830
- }
827
+ match onion_payloads[ 0 ] . format {
828
+ msgs:: OnionHopDataFormat :: NonFinalNode { ..} => { } ,
829
+ _ => { panic ! (
830
+ "Should have generated a `msgs::OnionHopDataFormat::NonFinalNode` payload for `hops[0]`,
831
+ despite that the features signals no support for variable length onions"
832
+ ) }
833
+ }
834
+ match onion_payloads[ 1 ] . format {
835
+ msgs:: OnionHopDataFormat :: FinalNode { ..} => { } ,
836
+ _ => { panic ! (
837
+ "Should have generated a `msgs::OnionHopDataFormat::FinalNode` payload for `hops[1]`,
838
+ despite that the features signals no support for variable length onions"
839
+ ) }
831
840
}
832
841
}
833
842
0 commit comments