@@ -8529,13 +8529,26 @@ mod tests {
8529
8529
8530
8530
#[ test]
8531
8531
fn test_keysend_dup_payment_hash ( ) {
8532
+ do_test_keysend_dup_payment_hash ( false ) ;
8533
+ do_test_keysend_dup_payment_hash ( true ) ;
8534
+ }
8535
+
8536
+ fn do_test_keysend_dup_payment_hash ( accept_mpp_keysend : bool ) {
8532
8537
// (1): Test that a keysend payment with a duplicate payment hash to an existing pending
8533
8538
// outbound regular payment fails as expected.
8534
8539
// (2): Test that a regular payment with a duplicate payment hash to an existing keysend payment
8535
8540
// fails as expected.
8541
+ // (3): Test that a keysend payment with a duplicate payment hash to an existing keysend
8542
+ // payment fails as expected. When `accept_mpp_keysend` is false, this tests that we
8543
+ // reject MPP keysend payments, since in this case where the payment has no payment
8544
+ // secret, a keysend payment with a duplicate hash is basically an MPP keysend. If
8545
+ // `accept_mpp_keysend` is true, this tests that we only accept MPP keysends with
8546
+ // payment secrets and reject otherwise.
8536
8547
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
8537
8548
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
8538
- let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
8549
+ let mut mpp_keysend_cfg = test_default_channel_config ( ) ;
8550
+ mpp_keysend_cfg. accept_mpp_keysend = accept_mpp_keysend;
8551
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , Some ( mpp_keysend_cfg) ] ) ;
8539
8552
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
8540
8553
create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
8541
8554
let scorer = test_utils:: TestScorer :: new ( ) ;
@@ -8624,6 +8637,53 @@ mod tests {
8624
8637
8625
8638
// Finally, succeed the keysend payment.
8626
8639
claim_payment ( & nodes[ 0 ] , & expected_route, payment_preimage) ;
8640
+
8641
+ // To start (3), send a keysend payment but don't claim it.
8642
+ let payment_id_1 = PaymentId ( [ 44 ; 32 ] ) ;
8643
+ let payment_hash = nodes[ 0 ] . node . send_spontaneous_payment ( & route, Some ( payment_preimage) ,
8644
+ RecipientOnionFields :: spontaneous_empty ( ) , payment_id_1) . unwrap ( ) ;
8645
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
8646
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
8647
+ assert_eq ! ( events. len( ) , 1 ) ;
8648
+ let event = events. pop ( ) . unwrap ( ) ;
8649
+ let path = vec ! [ & nodes[ 1 ] ] ;
8650
+ pass_along_path ( & nodes[ 0 ] , & path, 100_000 , payment_hash, None , event, true , Some ( payment_preimage) ) ;
8651
+
8652
+ // Next, attempt a keysend payment and make sure it fails.
8653
+ let route_params = RouteParameters {
8654
+ payment_params : PaymentParameters :: for_keysend ( expected_route. last ( ) . unwrap ( ) . node . get_our_node_id ( ) , TEST_FINAL_CLTV , false ) ,
8655
+ final_value_msat : 100_000 ,
8656
+ } ;
8657
+ let route = find_route (
8658
+ & nodes[ 0 ] . node . get_our_node_id ( ) , & route_params, & nodes[ 0 ] . network_graph ,
8659
+ None , nodes[ 0 ] . logger , & scorer, & ( ) , & random_seed_bytes
8660
+ ) . unwrap ( ) ;
8661
+ let payment_id_2 = PaymentId ( [ 45 ; 32 ] ) ;
8662
+ nodes[ 0 ] . node . send_spontaneous_payment ( & route, Some ( payment_preimage) ,
8663
+ RecipientOnionFields :: spontaneous_empty ( ) , payment_id_2) . unwrap ( ) ;
8664
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
8665
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
8666
+ assert_eq ! ( events. len( ) , 1 ) ;
8667
+ let ev = events. drain ( ..) . next ( ) . unwrap ( ) ;
8668
+ let payment_event = SendEvent :: from_event ( ev) ;
8669
+ nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
8670
+ check_added_monitors ! ( nodes[ 1 ] , 0 ) ;
8671
+ commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , payment_event. commitment_msg, false ) ;
8672
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
8673
+ expect_pending_htlcs_forwardable_and_htlc_handling_failed ! ( nodes[ 1 ] , vec![ HTLCDestination :: FailedPayment { payment_hash } ] ) ;
8674
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
8675
+ let updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
8676
+ assert ! ( updates. update_add_htlcs. is_empty( ) ) ;
8677
+ assert ! ( updates. update_fulfill_htlcs. is_empty( ) ) ;
8678
+ assert_eq ! ( updates. update_fail_htlcs. len( ) , 1 ) ;
8679
+ assert ! ( updates. update_fail_malformed_htlcs. is_empty( ) ) ;
8680
+ assert ! ( updates. update_fee. is_none( ) ) ;
8681
+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & updates. update_fail_htlcs [ 0 ] ) ;
8682
+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , updates. commitment_signed, true , true ) ;
8683
+ expect_payment_failed ! ( nodes[ 0 ] , payment_hash, true ) ;
8684
+
8685
+ // Finally, claim the original payment.
8686
+ claim_payment ( & nodes[ 0 ] , & expected_route, payment_preimage) ;
8627
8687
}
8628
8688
8629
8689
#[ test]
0 commit comments