@@ -1132,3 +1132,54 @@ fn min_htlc() {
1132
1132
expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false ,
1133
1133
PaymentFailedConditions :: new ( ) . expected_htlc_error_data ( INVALID_ONION_BLINDING , & [ 0 ; 32 ] ) ) ;
1134
1134
}
1135
+
1136
+ #[ test]
1137
+ fn conditionally_round_fwd_amt ( ) {
1138
+ // Previously, the (rng-found) feerates below caught a bug where an intermediate node would
1139
+ // calculate an amt_to_forward that underpaid them by 1 msat, caused by rounding up the outbound
1140
+ // amount on top of an already rounded-up total routing fee. Ensure that we'll conditionally round
1141
+ // down intermediate nodes' outbound amounts based on whether rounding up will result in
1142
+ // undercharging for relay.
1143
+ let chanmon_cfgs = create_chanmon_cfgs ( 5 ) ;
1144
+ let node_cfgs = create_node_cfgs ( 5 , & chanmon_cfgs) ;
1145
+
1146
+ let mut node_1_cfg = test_default_channel_config ( ) ;
1147
+ node_1_cfg. channel_config . forwarding_fee_base_msat = 247371 ;
1148
+ node_1_cfg. channel_config . forwarding_fee_proportional_millionths = 86552 ;
1149
+
1150
+ let mut node_2_cfg = test_default_channel_config ( ) ;
1151
+ node_2_cfg. channel_config . forwarding_fee_base_msat = 198921 ;
1152
+ node_2_cfg. channel_config . forwarding_fee_proportional_millionths = 681759 ;
1153
+
1154
+ let mut node_3_cfg = test_default_channel_config ( ) ;
1155
+ node_3_cfg. channel_config . forwarding_fee_base_msat = 132845 ;
1156
+ node_3_cfg. channel_config . forwarding_fee_proportional_millionths = 552561 ;
1157
+
1158
+ let node_chanmgrs = create_node_chanmgrs ( 5 , & node_cfgs, & [ None , Some ( node_1_cfg) , Some ( node_2_cfg) , Some ( node_3_cfg) , None ] ) ;
1159
+ let nodes = create_network ( 5 , & node_cfgs, & node_chanmgrs) ;
1160
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
1161
+ let chan_1_2 = create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
1162
+ let chan_2_3 = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 1_000_000 , 0 ) ;
1163
+ let chan_3_4 = create_announced_chan_between_nodes_with_value ( & nodes, 3 , 4 , 1_000_000 , 0 ) ;
1164
+
1165
+ let amt_msat = 100_000 ;
1166
+ let ( payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 4 ] , Some ( amt_msat) , None ) ;
1167
+ let mut route_params = get_blinded_route_parameters ( amt_msat, payment_secret,
1168
+ chan_1_2. 1 . contents . htlc_minimum_msat , chan_1_2. 1 . contents . htlc_maximum_msat ,
1169
+ vec ! [ nodes[ 1 ] . node. get_our_node_id( ) , nodes[ 2 ] . node. get_our_node_id( ) ,
1170
+ nodes[ 3 ] . node. get_our_node_id( ) , nodes[ 4 ] . node. get_our_node_id( ) ] ,
1171
+ & [ & chan_1_2. 0 . contents , & chan_2_3. 0 . contents , & chan_3_4. 0 . contents ] ,
1172
+ & chanmon_cfgs[ 4 ] . keys_manager ) ;
1173
+ route_params. max_total_routing_fee_msat = None ;
1174
+
1175
+ nodes[ 0 ] . node . send_payment ( payment_hash, RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( payment_hash. 0 ) , route_params, Retry :: Attempts ( 0 ) ) . unwrap ( ) ;
1176
+ check_added_monitors ( & nodes[ 0 ] , 1 ) ;
1177
+ pass_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] ] ] , amt_msat, payment_hash, payment_secret) ;
1178
+ nodes[ 4 ] . node . claim_funds ( payment_preimage) ;
1179
+ let expected_path = & [ & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] ] ;
1180
+ let expected_route = & [ & expected_path[ ..] ] ;
1181
+ let mut args = ClaimAlongRouteArgs :: new ( & nodes[ 0 ] , & expected_route[ ..] , payment_preimage)
1182
+ . allow_1_msat_fee_overpay ( ) ;
1183
+ let expected_fee = pass_claimed_payment_along_route ( args) ;
1184
+ expect_payment_sent ( & nodes[ 0 ] , payment_preimage, Some ( Some ( expected_fee) ) , true , true ) ;
1185
+ }
0 commit comments