@@ -7925,6 +7925,78 @@ fn test_can_not_accept_unknown_inbound_channel() {
7925
7925
}
7926
7926
}
7927
7927
7928
+ fn do_test_overshoot_mpp ( msat_amounts : & [ u64 ] , total_msat : u64 ) {
7929
+
7930
+ let routing_node_count = msat_amounts. len ( ) ;
7931
+ let node_count = routing_node_count + 2 ;
7932
+
7933
+ let chanmon_cfgs = create_chanmon_cfgs ( node_count) ;
7934
+ let node_cfgs = create_node_cfgs ( node_count, & chanmon_cfgs) ;
7935
+ let node_chanmgrs = create_node_chanmgrs ( node_count, & node_cfgs, & vec ! [ None ; node_count] ) ;
7936
+ let nodes = create_network ( node_count, & node_cfgs, & node_chanmgrs) ;
7937
+
7938
+ let src_idx = 0 ;
7939
+ let dst_idx = 1 ;
7940
+
7941
+ // Create channels for each amount
7942
+ let mut expected_paths = Vec :: with_capacity ( routing_node_count) ;
7943
+ let mut src_chan_ids = Vec :: with_capacity ( routing_node_count) ;
7944
+ let mut dst_chan_ids = Vec :: with_capacity ( routing_node_count) ;
7945
+ for i in 0 ..routing_node_count {
7946
+ let routing_node = 2 + i;
7947
+ let src_chan_id = create_announced_chan_between_nodes ( & nodes, src_idx, routing_node) . 0 . contents . short_channel_id ;
7948
+ src_chan_ids. push ( src_chan_id) ;
7949
+ let dst_chan_id = create_announced_chan_between_nodes ( & nodes, routing_node, dst_idx) . 0 . contents . short_channel_id ;
7950
+ dst_chan_ids. push ( dst_chan_id) ;
7951
+ let path = vec ! [ & nodes[ routing_node] , & nodes[ dst_idx] ] ;
7952
+ expected_paths. push ( path) ;
7953
+ }
7954
+ let expected_paths: Vec < & [ & Node ] > = expected_paths. iter ( ) . map ( |route| route. as_slice ( ) ) . collect ( ) ;
7955
+
7956
+ // Create a route for each amount
7957
+ let example_amount = 100000 ;
7958
+ let ( mut route, our_payment_hash, our_payment_preimage, our_payment_secret) = get_route_and_payment_hash ! ( & nodes[ src_idx] , nodes[ dst_idx] , example_amount) ;
7959
+ let sample_path = route. paths . pop ( ) . unwrap ( ) ;
7960
+ for i in 0 ..routing_node_count {
7961
+ let routing_node = 2 + i;
7962
+ let mut path = sample_path. clone ( ) ;
7963
+ path[ 0 ] . pubkey = nodes[ routing_node] . node . get_our_node_id ( ) ;
7964
+ path[ 0 ] . short_channel_id = src_chan_ids[ i] ;
7965
+ path[ 1 ] . pubkey = nodes[ dst_idx] . node . get_our_node_id ( ) ;
7966
+ path[ 1 ] . short_channel_id = dst_chan_ids[ i] ;
7967
+ path[ 1 ] . fee_msat = msat_amounts[ i] ;
7968
+ route. paths . push ( path) ;
7969
+ }
7970
+
7971
+ // Send payment with manually set total_msat
7972
+ let payment_id = PaymentId ( nodes[ src_idx] . keys_manager . backing . get_secure_random_bytes ( ) ) ;
7973
+ let onion_session_privs = nodes[ src_idx] . node . test_add_new_pending_payment ( our_payment_hash, Some ( our_payment_secret) , payment_id, & route) . unwrap ( ) ;
7974
+ nodes[ src_idx] . node . test_send_payment_internal ( & route, our_payment_hash, & Some ( our_payment_secret) , None , payment_id, Some ( total_msat) , onion_session_privs) . unwrap ( ) ;
7975
+ check_added_monitors ! ( nodes[ src_idx] , expected_paths. len( ) ) ;
7976
+
7977
+ // pass_along_route except it can expect PaymentClaimable before final path
7978
+ let mut events = nodes[ src_idx] . node . get_and_clear_pending_msg_events ( ) ;
7979
+ assert_eq ! ( events. len( ) , expected_paths. len( ) ) ;
7980
+ let mut amount_received = 0 ;
7981
+ for ( path_idx, expected_path) in expected_paths. iter ( ) . enumerate ( ) {
7982
+ let ev = remove_first_msg_event_to_node ( & expected_path[ 0 ] . node . get_our_node_id ( ) , & mut events) ;
7983
+
7984
+ let current_path_amount = msat_amounts[ path_idx] ;
7985
+ amount_received += current_path_amount;
7986
+ let became_claimable_now = amount_received >= total_msat && amount_received - current_path_amount < total_msat;
7987
+ pass_along_path ( & nodes[ src_idx] , expected_path, total_msat, our_payment_hash. clone ( ) , Some ( our_payment_secret) , ev, became_claimable_now, None ) ;
7988
+ }
7989
+
7990
+ claim_payment_along_route ( & nodes[ src_idx] , & expected_paths, false , our_payment_preimage) ;
7991
+ }
7992
+
7993
+ #[ test]
7994
+ fn test_overshoot_mpp ( ) {
7995
+ do_test_overshoot_mpp ( & [ 100_000 , 101_000 ] , 200_000 ) ;
7996
+ do_test_overshoot_mpp ( & [ 100_000 , 10_000 , 100_000 ] , 200_000 ) ;
7997
+ do_test_overshoot_mpp ( & [ 100_000 , 100_000 ] , 100_000 ) ;
7998
+ }
7999
+
7928
8000
#[ test]
7929
8001
fn test_simple_mpp ( ) {
7930
8002
// Simple test of sending a multi-path payment.
0 commit comments