@@ -637,12 +637,10 @@ fn amount_doesnt_match_invreq() {
637637
638638 // Replace the invoice request contained within outbound_payments before sending so the invreq
639639 // 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 ( ) ;
640+ let mut valid_invreq = None ;
641+ nodes[ 0 ] . node . test_modify_pending_payment ( & payment_id, |pmt| {
642+ if let PendingOutboundPayment :: StaticInvoiceReceived { invoice_request, .. } = pmt {
643+ valid_invreq = Some ( invoice_request. clone ( ) ) ;
646644 * invoice_request = offer
647645 . request_invoice (
648646 & nodes[ 0 ] . keys_manager . get_inbound_payment_key ( ) ,
@@ -657,10 +655,10 @@ fn amount_doesnt_match_invreq() {
657655 . unwrap ( )
658656 . build_and_sign ( )
659657 . unwrap ( ) ;
660- } ,
661- _ => panic ! ( ) ,
662- }
663- core :: mem :: drop ( outbounds ) ;
658+ } else {
659+ panic ! ( )
660+ }
661+ } ) ;
664662
665663 nodes[ 0 ]
666664 . onion_messenger
@@ -683,15 +681,13 @@ fn amount_doesnt_match_invreq() {
683681
684682 // Modify the invoice request stored in our outbounds to be the correct one, to make sure the
685683 // 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) ;
684+ nodes[ 0 ] . node . test_modify_pending_payment ( & payment_id, |pmt| {
685+ if let PendingOutboundPayment :: Retryable { invoice_request, .. } = pmt {
686+ * invoice_request = valid_invreq. take ( ) ;
687+ } else {
688+ panic ! ( )
689+ }
690+ } ) ;
695691
696692 fail_blinded_htlc_backwards ( payment_hash, 1 , & [ & nodes[ 0 ] , & nodes[ 1 ] , & nodes[ 3 ] ] , true ) ;
697693
@@ -720,27 +716,24 @@ fn reject_missing_invreq() {
720716 |sender, _, payment_id| {
721717 // Remove the invoice request from our Retryable payment so we don't include it in the onion on
722718 // 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, .. } ) => {
719+ sender. node . test_modify_pending_payment ( & payment_id, |pmt| {
720+ if let PendingOutboundPayment :: Retryable { invoice_request, .. } = pmt {
727721 assert ! ( invoice_request. is_some( ) ) ;
728- invoice_request. take ( )
729- } ,
730- _ => panic ! ( ) ,
731- } ;
732- * valid_invreq . lock ( ) . unwrap ( ) = valid_invreq_from_outbounds ;
722+ * valid_invreq . lock ( ) . unwrap ( ) = invoice_request. take ( ) ;
723+ } else {
724+ panic ! ( )
725+ }
726+ } ) ;
733727 } ,
734728 |sender, payment_id| {
735729 // 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, .. } ) => {
730+ sender. node . test_modify_pending_payment ( & payment_id, |pmt| {
731+ if let PendingOutboundPayment :: Retryable { invoice_request, .. } = pmt {
740732 * invoice_request = valid_invreq. lock ( ) . unwrap ( ) . take ( ) ;
741- } ,
742- _ => panic ! ( ) ,
743- }
733+ } else {
734+ panic ! ( )
735+ }
736+ } ) ;
744737 } ,
745738 ) ;
746739}
@@ -773,10 +766,8 @@ fn reject_bad_payment_secret() {
773766 }
774767
775768 // 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, .. } ) => {
769+ sender. node . test_modify_pending_payment ( & payment_id, |pmt| {
770+ if let PendingOutboundPayment :: Retryable { ref mut payment_params, .. } = pmt {
780771 assert ! ( payment_params. is_some( ) ) ;
781772 let valid_params = payment_params. clone ( ) ;
782773 if let Payee :: Blinded { ref mut route_hints, .. } =
@@ -786,22 +777,21 @@ fn reject_bad_payment_secret() {
786777 } else {
787778 panic ! ( )
788779 }
789- valid_params
790- } ,
791- _ => panic ! ( ) ,
792- } ;
793- * valid_payment_params . lock ( ) . unwrap ( ) = valid_params_from_outbounds ;
780+ * valid_payment_params . lock ( ) . unwrap ( ) = valid_params;
781+ } else {
782+ panic ! ( )
783+ }
784+ } ) ;
794785 } ,
795786 |sender, payment_id| {
796787 // 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, .. } ) => {
788+ sender. node . test_modify_pending_payment ( & payment_id, |pmt| {
789+ if let PendingOutboundPayment :: Retryable { payment_params, .. } = pmt {
801790 * payment_params = valid_payment_params. lock ( ) . unwrap ( ) . take ( ) ;
802- } ,
803- _ => panic ! ( ) ,
804- }
791+ } else {
792+ panic ! ( )
793+ }
794+ } ) ;
805795 } ,
806796 ) ;
807797}
0 commit comments