@@ -637,30 +637,29 @@ fn amount_doesnt_match_invreq() {
637
637
638
638
// Replace the invoice request contained within outbound_payments before sending so the invreq
639
639
// amount doesn't match the onion amount when the HTLC gets to the recipient.
640
- let mut outbounds =
641
- nodes[ 0 ] . node . pending_outbound_payments . pending_outbound_payments . lock ( ) . unwrap ( ) ;
642
- let valid_invreq;
643
- match outbounds. get_mut ( & payment_id) {
644
- Some ( PendingOutboundPayment :: StaticInvoiceReceived { invoice_request, .. } ) => {
645
- valid_invreq = invoice_request. clone ( ) ;
646
- * invoice_request = offer
647
- . request_invoice (
648
- & nodes[ 0 ] . keys_manager . get_inbound_payment_key ( ) ,
649
- Nonce :: from_entropy_source ( nodes[ 0 ] . keys_manager ) ,
650
- & secp_ctx,
651
- payment_id,
652
- )
653
- . unwrap ( )
654
- . amount_msats ( amt_msat + 1 )
655
- . unwrap ( )
656
- . chain_hash ( ChainHash :: using_genesis_block ( Network :: Testnet ) )
657
- . unwrap ( )
658
- . build_and_sign ( )
659
- . unwrap ( ) ;
660
- } ,
661
- _ => panic ! ( ) ,
662
- }
663
- core:: mem:: drop ( outbounds) ;
640
+ let mut valid_invreq = None ;
641
+ nodes[ 0 ] . node . test_modify_pending_payment ( & payment_id, |pmt| {
642
+ match pmt {
643
+ PendingOutboundPayment :: StaticInvoiceReceived { invoice_request, .. } => {
644
+ valid_invreq = Some ( invoice_request. clone ( ) ) ;
645
+ * invoice_request = offer
646
+ . request_invoice (
647
+ & nodes[ 0 ] . keys_manager . get_inbound_payment_key ( ) ,
648
+ Nonce :: from_entropy_source ( nodes[ 0 ] . keys_manager ) ,
649
+ & secp_ctx,
650
+ payment_id,
651
+ )
652
+ . unwrap ( )
653
+ . amount_msats ( amt_msat + 1 )
654
+ . unwrap ( )
655
+ . chain_hash ( ChainHash :: using_genesis_block ( Network :: Testnet ) )
656
+ . unwrap ( )
657
+ . build_and_sign ( )
658
+ . unwrap ( ) ;
659
+ } ,
660
+ _ => panic ! ( )
661
+ }
662
+ } ) ;
664
663
665
664
nodes[ 0 ]
666
665
. onion_messenger
@@ -683,15 +682,14 @@ fn amount_doesnt_match_invreq() {
683
682
684
683
// Modify the invoice request stored in our outbounds to be the correct one, to make sure the
685
684
// payment retry will succeed after we finish failing the invalid HTLC back.
686
- let mut outbounds =
687
- nodes[ 0 ] . node . pending_outbound_payments . pending_outbound_payments . lock ( ) . unwrap ( ) ;
688
- match outbounds. get_mut ( & payment_id) {
689
- Some ( PendingOutboundPayment :: Retryable { invoice_request, .. } ) => {
690
- * invoice_request = Some ( valid_invreq) ;
691
- } ,
692
- _ => panic ! ( ) ,
693
- }
694
- core:: mem:: drop ( outbounds) ;
685
+ nodes[ 0 ] . node . test_modify_pending_payment ( & payment_id, |pmt| {
686
+ match pmt {
687
+ PendingOutboundPayment :: Retryable { invoice_request, .. } => {
688
+ * invoice_request = valid_invreq. take ( ) ;
689
+ } ,
690
+ _ => panic ! ( ) ,
691
+ }
692
+ } ) ;
695
693
696
694
fail_blinded_htlc_backwards ( payment_hash, 1 , & [ & nodes[ 0 ] , & nodes[ 1 ] , & nodes[ 3 ] ] , true ) ;
697
695
@@ -720,27 +718,26 @@ fn reject_missing_invreq() {
720
718
|sender, _, payment_id| {
721
719
// Remove the invoice request from our Retryable payment so we don't include it in the onion on
722
720
// retry.
723
- let mut outbounds =
724
- sender. node . pending_outbound_payments . pending_outbound_payments . lock ( ) . unwrap ( ) ;
725
- let valid_invreq_from_outbounds = match outbounds. get_mut ( & payment_id) {
726
- Some ( PendingOutboundPayment :: Retryable { invoice_request, .. } ) => {
727
- assert ! ( invoice_request. is_some( ) ) ;
728
- invoice_request. take ( )
729
- } ,
730
- _ => panic ! ( ) ,
731
- } ;
732
- * valid_invreq. lock ( ) . unwrap ( ) = valid_invreq_from_outbounds;
721
+ sender. node . test_modify_pending_payment ( & payment_id, |pmt| {
722
+ match pmt {
723
+ PendingOutboundPayment :: Retryable { invoice_request, .. } => {
724
+ assert ! ( invoice_request. is_some( ) ) ;
725
+ * valid_invreq. lock ( ) . unwrap ( ) = invoice_request. take ( ) ;
726
+ } ,
727
+ _ => panic ! ( ) ,
728
+ }
729
+ } ) ;
733
730
} ,
734
731
|sender, payment_id| {
735
732
// Re-add the invoice request so we include it in the onion on the next retry.
736
- let mut outbounds =
737
- sender . node . pending_outbound_payments . pending_outbound_payments . lock ( ) . unwrap ( ) ;
738
- match outbounds . get_mut ( & payment_id ) {
739
- Some ( PendingOutboundPayment :: Retryable { invoice_request, .. } ) => {
740
- * invoice_request = valid_invreq . lock ( ) . unwrap ( ) . take ( ) ;
741
- } ,
742
- _ => panic ! ( ) ,
743
- }
733
+ sender . node . test_modify_pending_payment ( & payment_id , |pmt| {
734
+ match pmt {
735
+ PendingOutboundPayment :: Retryable { invoice_request , .. } => {
736
+ * invoice_request = valid_invreq . lock ( ) . unwrap ( ) . take ( ) ;
737
+ } ,
738
+ _ => panic ! ( ) ,
739
+ }
740
+ } ) ;
744
741
} ,
745
742
) ;
746
743
}
@@ -773,35 +770,34 @@ fn reject_bad_payment_secret() {
773
770
}
774
771
775
772
// Modify the outbound payment parameters to use payment paths with an invalid payment secret.
776
- let mut outbounds =
777
- sender. node . pending_outbound_payments . pending_outbound_payments . lock ( ) . unwrap ( ) ;
778
- let valid_params_from_outbounds = match outbounds. get_mut ( & payment_id) {
779
- Some ( PendingOutboundPayment :: Retryable { ref mut payment_params, .. } ) => {
780
- assert ! ( payment_params. is_some( ) ) ;
781
- let valid_params = payment_params. clone ( ) ;
782
- if let Payee :: Blinded { ref mut route_hints, .. } =
783
- & mut payment_params. as_mut ( ) . unwrap ( ) . payee
784
- {
785
- core:: mem:: swap ( route_hints, & mut invalid_blinded_payment_paths) ;
786
- } else {
787
- panic ! ( )
788
- }
789
- valid_params
790
- } ,
791
- _ => panic ! ( ) ,
792
- } ;
793
- * valid_payment_params. lock ( ) . unwrap ( ) = valid_params_from_outbounds;
773
+ sender. node . test_modify_pending_payment ( & payment_id, |pmt| {
774
+ match pmt {
775
+ PendingOutboundPayment :: Retryable { ref mut payment_params, .. } => {
776
+ assert ! ( payment_params. is_some( ) ) ;
777
+ let valid_params = payment_params. clone ( ) ;
778
+ if let Payee :: Blinded { ref mut route_hints, .. } =
779
+ & mut payment_params. as_mut ( ) . unwrap ( ) . payee
780
+ {
781
+ core:: mem:: swap ( route_hints, & mut invalid_blinded_payment_paths) ;
782
+ } else {
783
+ panic ! ( )
784
+ }
785
+ * valid_payment_params. lock ( ) . unwrap ( ) = valid_params;
786
+ } ,
787
+ _ => panic ! ( ) ,
788
+ }
789
+ } ) ;
794
790
} ,
795
791
|sender, payment_id| {
796
792
// Re-add the valid payment params so we use the right payment secret on the next retry.
797
- let mut outbounds =
798
- sender . node . pending_outbound_payments . pending_outbound_payments . lock ( ) . unwrap ( ) ;
799
- match outbounds . get_mut ( & payment_id ) {
800
- Some ( PendingOutboundPayment :: Retryable { payment_params, .. } ) => {
801
- * payment_params = valid_payment_params . lock ( ) . unwrap ( ) . take ( ) ;
802
- } ,
803
- _ => panic ! ( ) ,
804
- }
793
+ sender . node . test_modify_pending_payment ( & payment_id , |pmt| {
794
+ match pmt {
795
+ PendingOutboundPayment :: Retryable { payment_params , .. } => {
796
+ * payment_params = valid_payment_params . lock ( ) . unwrap ( ) . take ( ) ;
797
+ } ,
798
+ _ => panic ! ( ) ,
799
+ }
800
+ } ) ;
805
801
} ,
806
802
) ;
807
803
}
0 commit comments