@@ -1625,7 +1625,18 @@ impl ChannelMessageHandler for ChannelManager {
1625
1625
hmac : next_hop_data. hmac . clone ( ) ,
1626
1626
} ;
1627
1627
1628
- //TODO: Check amt_to_forward and outgoing_cltv_value are within acceptable ranges!
1628
+ let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1629
+ let chan = channel_state. by_id . get ( & msg. channel_id ) . unwrap ( ) ;
1630
+ let fee = chan. get_our_fee_base_msat ( & * self . fee_estimator ) + ( next_hop_data. data . amt_to_forward * self . fee_proportional_millionths as u64 / 1000000 ) as u32 ;
1631
+ if ( msg. amount_msat - fee as u64 ) < next_hop_data. data . amt_to_forward {
1632
+ log_debug ! ( self , "HTLC {} incorrect amount: in {} out {} fee required {}" , msg. htlc_id, msg. amount_msat, next_hop_data. data. amt_to_forward, fee) ;
1633
+ //TODO: give back a "channel_update" in failure onion packet ?
1634
+ return_err ! ( "Prior hop has deviated from specified parameters" , 0x1000 | 12 , & [ 0 ; 0 ] ) ;
1635
+ }
1636
+ if ( msg. cltv_expiry - CLTV_EXPIRY_DELTA as u32 ) < next_hop_data. data . outgoing_cltv_value {
1637
+ log_debug ! ( self , "HTLC {} incorrect CLTV: in {} out {} delta required {}" , msg. htlc_id, msg. cltv_expiry, next_hop_data. data. outgoing_cltv_value, CLTV_EXPIRY_DELTA ) ;
1638
+ return_err ! ( "Forwarding node has tampered with the intended HTLC values or origin node has an obsolete cltv_expiry_delta" , 0x1000 | 13 , & [ 0 ; 0 ] ) ;
1639
+ }
1629
1640
1630
1641
PendingForwardHTLCInfo {
1631
1642
onion_packet : Some ( outgoing_packet) ,
@@ -2595,7 +2606,6 @@ mod tests {
2595
2606
for ( node, hop) in expected_route. iter ( ) . zip ( route. hops . iter ( ) ) {
2596
2607
assert_eq ! ( hop. pubkey, node. node. get_our_node_id( ) ) ;
2597
2608
}
2598
-
2599
2609
send_along_route ( origin_node, route, expected_route, recv_value)
2600
2610
}
2601
2611
@@ -2804,15 +2814,15 @@ mod tests {
2804
2814
pubkey : nodes[ 2 ] . node . get_our_node_id ( ) ,
2805
2815
short_channel_id : chan_3. 0 . contents . short_channel_id ,
2806
2816
fee_msat : 0 ,
2807
- cltv_expiry_delta : chan_2. 1 . contents . cltv_expiry_delta as u32
2817
+ cltv_expiry_delta : chan_2. 0 . contents . cltv_expiry_delta as u32
2808
2818
} ) ;
2809
2819
hops. push ( RouteHop {
2810
2820
pubkey : nodes[ 1 ] . node . get_our_node_id ( ) ,
2811
2821
short_channel_id : chan_2. 0 . contents . short_channel_id ,
2812
2822
fee_msat : 1000000 ,
2813
2823
cltv_expiry_delta : TEST_FINAL_CLTV ,
2814
2824
} ) ;
2815
- hops[ 1 ] . fee_msat = chan_2. 1 . contents . fee_base_msat as u64 + chan_2. 1 . contents . fee_proportional_millionths as u64 * hops[ 2 ] . fee_msat as u64 / 1000000 ;
2825
+ hops[ 1 ] . fee_msat = chan_2. 0 . contents . fee_base_msat as u64 + chan_2. 0 . contents . fee_proportional_millionths as u64 * hops[ 2 ] . fee_msat as u64 / 1000000 ;
2816
2826
hops[ 0 ] . fee_msat = chan_3. 1 . contents . fee_base_msat as u64 + chan_3. 1 . contents . fee_proportional_millionths as u64 * hops[ 1 ] . fee_msat as u64 / 1000000 ;
2817
2827
let payment_hash_2 = send_along_route ( & nodes[ 1 ] , Route { hops } , & vec ! ( & nodes[ 3 ] , & nodes[ 2 ] , & nodes[ 1 ] ) [ ..] , 1000000 ) . 1 ;
2818
2828
0 commit comments