@@ -2105,6 +2105,8 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
2105
2105
let network_nodes = network_graph. nodes ( ) ;
2106
2106
2107
2107
for path in route. paths . iter_mut ( ) {
2108
+ if path. blinded_tail . as_ref ( ) . map_or ( false , |tail| tail. path . blinded_hops . len ( ) > 1 ) { continue }
2109
+
2108
2110
let mut shadow_ctlv_expiry_delta_offset: u32 = 0 ;
2109
2111
2110
2112
// Remember the last three nodes of the random walk and avoid looping back on them.
@@ -2173,7 +2175,10 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
2173
2175
shadow_ctlv_expiry_delta_offset = cmp:: min ( shadow_ctlv_expiry_delta_offset, max_path_offset) ;
2174
2176
2175
2177
// Add 'shadow' CLTV offset to the final hop
2176
- if let Some ( last_hop) = path. hops . last_mut ( ) {
2178
+ if let Some ( tail) = path. blinded_tail . as_mut ( ) {
2179
+ tail. cltv_expiry_delta = tail. cltv_expiry_delta
2180
+ . checked_add ( shadow_ctlv_expiry_delta_offset) . unwrap_or ( tail. cltv_expiry_delta ) ;
2181
+ } else if let Some ( last_hop) = path. hops . last_mut ( ) {
2177
2182
last_hop. cltv_expiry_delta = last_hop. cltv_expiry_delta
2178
2183
. checked_add ( shadow_ctlv_expiry_delta_offset) . unwrap_or ( last_hop. cltv_expiry_delta ) ;
2179
2184
}
@@ -5801,6 +5806,45 @@ mod tests {
5801
5806
assert_eq ! ( * inflight_htlcs. 0 . get( & ( 42 , true ) ) . unwrap( ) , 301 ) ;
5802
5807
assert_eq ! ( * inflight_htlcs. 0 . get( & ( 43 , false ) ) . unwrap( ) , 201 ) ;
5803
5808
}
5809
+
5810
+ #[ test]
5811
+ fn blinded_path_cltv_shadow_offset ( ) {
5812
+ // Don't add a shadow offset to blinded paths with more than 1 hop.
5813
+ let mut route = Route { paths : vec ! [ Path {
5814
+ hops: vec![ RouteHop {
5815
+ pubkey: ln_test_utils:: pubkey( 42 ) ,
5816
+ node_features: NodeFeatures :: empty( ) ,
5817
+ short_channel_id: 42 ,
5818
+ channel_features: ChannelFeatures :: empty( ) ,
5819
+ fee_msat: 100 ,
5820
+ cltv_expiry_delta: 0 ,
5821
+ } ] ,
5822
+ blinded_tail: Some ( BlindedTail {
5823
+ path: BlindedPath {
5824
+ introduction_node_id: ln_test_utils:: pubkey( 43 ) ,
5825
+ blinding_point: ln_test_utils:: pubkey( 44 ) ,
5826
+ blinded_hops: vec![
5827
+ BlindedHop { blinded_node_id: ln_test_utils:: pubkey( 45 ) , encrypted_payload: Vec :: new( ) } ,
5828
+ BlindedHop { blinded_node_id: ln_test_utils:: pubkey( 46 ) , encrypted_payload: Vec :: new( ) }
5829
+ ] ,
5830
+ } ,
5831
+ intro_node_scid: 43 ,
5832
+ fee_msat: 1 ,
5833
+ cltv_expiry_delta: 0 ,
5834
+ final_value_msat: 200 ,
5835
+ } ) ,
5836
+ } ] , payment_params : None } ;
5837
+
5838
+ let payment_params = PaymentParameters :: from_node_id ( ln_test_utils:: pubkey ( 47 ) , 18 ) ;
5839
+ let ( _, network_graph, _, _, _) = build_line_graph ( ) ;
5840
+ add_random_cltv_offset ( & mut route, & payment_params, & network_graph. read_only ( ) , & [ 0 ; 32 ] ) ;
5841
+ assert_eq ! ( route. paths[ 0 ] . blinded_tail. as_ref( ) . unwrap( ) . cltv_expiry_delta, 0 ) ;
5842
+
5843
+ // Add a shadow offset if we're sending to a 1-hop blinded path.
5844
+ route. paths [ 0 ] . blinded_tail . as_mut ( ) . unwrap ( ) . path . blinded_hops . pop ( ) ;
5845
+ add_random_cltv_offset ( & mut route, & payment_params, & network_graph. read_only ( ) , & [ 0 ; 32 ] ) ;
5846
+ assert_eq ! ( route. paths[ 0 ] . blinded_tail. as_ref( ) . unwrap( ) . cltv_expiry_delta, 40 ) ;
5847
+ }
5804
5848
}
5805
5849
5806
5850
#[ cfg( all( test, not( feature = "no-std" ) ) ) ]
0 commit comments