@@ -790,6 +790,45 @@ fn test_onion_failure_stale_channel_update() {
790790 do_test_onion_failure_stale_channel_update ( true ) ;
791791}
792792
793+ #[ test]
794+ fn test_always_create_onion_payload_tlv_format ( ) {
795+ let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
796+ let mut node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
797+
798+ // Set `node[1]` config to `InitFeatures::empty()` which return `false` for
799+ // `supports_variable_length_onion()`
800+ let mut node_1_cfg = & mut node_cfgs[ 1 ] ;
801+ node_1_cfg. features = InitFeatures :: empty ( ) ;
802+
803+ let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
804+ let mut nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
805+
806+ create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: empty ( ) , InitFeatures :: empty ( ) ) ;
807+ create_announced_chan_between_nodes ( & nodes, 1 , 2 , InitFeatures :: empty ( ) , InitFeatures :: empty ( ) ) ;
808+
809+ let ( route, _payment_hash, _payment_preimage, _payment_secret) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , 40000 ) ;
810+
811+ let hops = & route. paths [ 0 ] ;
812+ // Asserts that the first hop to `node[1]` returns `false` for
813+ // `node_features.supports_variable_length_onion()`
814+ assert ! ( !hops[ 0 ] . node_features. supports_variable_length_onion( ) ) ;
815+ // Asserts that the second hop to `node[2]` returns `true` for
816+ // `node_features.supports_variable_length_onion()`
817+ assert ! ( hops[ 1 ] . node_features. supports_variable_length_onion( ) ) ;
818+
819+ let cur_height = nodes[ 0 ] . best_block_info ( ) . 1 + 1 ;
820+ let ( onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils:: build_onion_payloads ( & route. paths [ 0 ] , 40000 , & None , cur_height, & None ) . unwrap ( ) ;
821+
822+ for onion_payload in onion_payloads. iter ( ) {
823+ match onion_payload. format {
824+ msgs:: OnionHopDataFormat :: Legacy { ..} => {
825+ panic ! ( "`onion_utils::build_onion_payloads` generated a `msgs::OnionHopDataFormat::Legacy` payload" ) ;
826+ }
827+ _ => { }
828+ }
829+ }
830+ }
831+
793832macro_rules! get_phantom_route {
794833 ( $nodes: expr, $amt: expr, $channel: expr) => { {
795834 let secp_ctx = Secp256k1 :: new( ) ;
0 commit comments