@@ -2179,7 +2179,10 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
2179
2179
shadow_ctlv_expiry_delta_offset = cmp:: min ( shadow_ctlv_expiry_delta_offset, max_path_offset) ;
2180
2180
2181
2181
// Add 'shadow' CLTV offset to the final hop
2182
- if let Some ( last_hop) = path. hops . last_mut ( ) {
2182
+ if let Some ( tail) = path. blinded_tail . as_mut ( ) {
2183
+ tail. final_cltv_expiry_delta = tail. final_cltv_expiry_delta
2184
+ . checked_add ( shadow_ctlv_expiry_delta_offset) . unwrap_or ( tail. final_cltv_expiry_delta ) ;
2185
+ } else if let Some ( last_hop) = path. hops . last_mut ( ) {
2183
2186
last_hop. cltv_expiry_delta = last_hop. cltv_expiry_delta
2184
2187
. checked_add ( shadow_ctlv_expiry_delta_offset) . unwrap_or ( last_hop. cltv_expiry_delta ) ;
2185
2188
}
@@ -5871,6 +5874,49 @@ mod tests {
5871
5874
assert_eq ! ( * inflight_htlcs. 0 . get( & ( 42 , true ) ) . unwrap( ) , 301 ) ;
5872
5875
assert_eq ! ( * inflight_htlcs. 0 . get( & ( 43 , false ) ) . unwrap( ) , 201 ) ;
5873
5876
}
5877
+
5878
+ #[ test]
5879
+ fn blinded_path_cltv_shadow_offset ( ) {
5880
+ // Make sure we add a shadow offset when sending to blinded paths.
5881
+ let blinded_path = BlindedPath {
5882
+ introduction_node_id : ln_test_utils:: pubkey ( 43 ) ,
5883
+ blinding_point : ln_test_utils:: pubkey ( 44 ) ,
5884
+ blinded_hops : vec ! [
5885
+ BlindedHop { blinded_node_id: ln_test_utils:: pubkey( 45 ) , encrypted_payload: Vec :: new( ) } ,
5886
+ BlindedHop { blinded_node_id: ln_test_utils:: pubkey( 46 ) , encrypted_payload: Vec :: new( ) }
5887
+ ] ,
5888
+ } ;
5889
+ let mut route = Route { paths : vec ! [ Path {
5890
+ hops: vec![ RouteHop {
5891
+ pubkey: ln_test_utils:: pubkey( 42 ) ,
5892
+ node_features: NodeFeatures :: empty( ) ,
5893
+ short_channel_id: 42 ,
5894
+ channel_features: ChannelFeatures :: empty( ) ,
5895
+ fee_msat: 100 ,
5896
+ cltv_expiry_delta: 0 ,
5897
+ } ,
5898
+ RouteHop {
5899
+ pubkey: blinded_path. introduction_node_id,
5900
+ node_features: NodeFeatures :: empty( ) ,
5901
+ short_channel_id: 43 ,
5902
+ channel_features: ChannelFeatures :: empty( ) ,
5903
+ fee_msat: 1 ,
5904
+ cltv_expiry_delta: 0 ,
5905
+ }
5906
+ ] ,
5907
+ blinded_tail: Some ( BlindedTail {
5908
+ hops: blinded_path. blinded_hops,
5909
+ blinding_point: blinded_path. blinding_point,
5910
+ final_cltv_expiry_delta: 0 ,
5911
+ final_value_msat: 200 ,
5912
+ } ) ,
5913
+ } ] , payment_params : None } ;
5914
+
5915
+ let payment_params = PaymentParameters :: from_node_id ( ln_test_utils:: pubkey ( 47 ) , 18 ) ;
5916
+ let ( _, network_graph, _, _, _) = build_line_graph ( ) ;
5917
+ add_random_cltv_offset ( & mut route, & payment_params, & network_graph. read_only ( ) , & [ 0 ; 32 ] ) ;
5918
+ assert_eq ! ( route. paths[ 0 ] . blinded_tail. as_ref( ) . unwrap( ) . final_cltv_expiry_delta, 40 ) ;
5919
+ }
5874
5920
}
5875
5921
5876
5922
#[ cfg( all( test, not( feature = "no-std" ) ) ) ]
0 commit comments