@@ -741,6 +741,78 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
741
741
expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
742
742
}
743
743
744
+ /// Verifies that the invoice request message can be retried if it fails to reach the
745
+ /// payee on the first attempt.
746
+ #[ test]
747
+ fn creates_and_pays_for_offer_with_retry ( ) {
748
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
749
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
750
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
751
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
752
+
753
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 10_000_000 , 1_000_000_000 ) ;
754
+
755
+ let alice = & nodes[ 0 ] ;
756
+ let alice_id = alice. node . get_our_node_id ( ) ;
757
+ let bob = & nodes[ 1 ] ;
758
+ let bob_id = bob. node . get_our_node_id ( ) ;
759
+
760
+ let offer = alice. node
761
+ . create_offer_builder ( None ) . unwrap ( )
762
+ . amount_msats ( 10_000_000 )
763
+ . build ( ) . unwrap ( ) ;
764
+ assert_ne ! ( offer. signing_pubkey( ) , Some ( alice_id) ) ;
765
+ assert ! ( !offer. paths( ) . is_empty( ) ) ;
766
+ for path in offer. paths ( ) {
767
+ assert_eq ! ( path. introduction_node( ) , & IntroductionNode :: NodeId ( alice_id) ) ;
768
+ }
769
+ let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
770
+ bob. node . pay_for_offer ( & offer, None , None , None , payment_id, Retry :: Attempts ( 0 ) , None ) . unwrap ( ) ;
771
+ expect_recent_payment ! ( bob, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
772
+
773
+ let _lost_onion_message = bob. onion_messenger . next_onion_message_for_peer ( alice_id) . unwrap ( ) ;
774
+
775
+ // Simulate a scenario where the original onion_message is lost before reaching Alice.
776
+ // Use handle_message_received to regenerate the message.
777
+ bob. node . message_received ( ) ;
778
+ let onion_message = bob. onion_messenger . next_onion_message_for_peer ( alice_id) . unwrap ( ) ;
779
+
780
+ alice. onion_messenger . handle_onion_message ( & bob_id, & onion_message) ;
781
+
782
+ let ( invoice_request, reply_path) = extract_invoice_request ( alice, & onion_message) ;
783
+ let payment_context = PaymentContext :: Bolt12Offer ( Bolt12OfferContext {
784
+ offer_id : offer. id ( ) ,
785
+ invoice_request : InvoiceRequestFields {
786
+ payer_id : invoice_request. payer_id ( ) ,
787
+ quantity : None ,
788
+ payer_note_truncated : None ,
789
+ } ,
790
+ } ) ;
791
+ assert_eq ! ( invoice_request. amount_msats( ) , None ) ;
792
+ assert_ne ! ( invoice_request. payer_id( ) , bob_id) ;
793
+ assert_eq ! ( reply_path. introduction_node( ) , & IntroductionNode :: NodeId ( bob_id) ) ;
794
+ let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
795
+ bob. onion_messenger . handle_onion_message ( & alice_id, & onion_message) ;
796
+
797
+ // Expect no more OffersMessage to be enqueued by this point, even after calling
798
+ // handle_message_received.
799
+ bob. node . message_received ( ) ;
800
+
801
+ assert ! ( bob. onion_messenger. next_onion_message_for_peer( alice_id) . is_none( ) ) ;
802
+
803
+ let ( invoice, _) = extract_invoice ( bob, & onion_message) ;
804
+ assert_eq ! ( invoice. amount_msats( ) , 10_000_000 ) ;
805
+ assert_ne ! ( invoice. signing_pubkey( ) , alice_id) ;
806
+ assert ! ( !invoice. payment_paths( ) . is_empty( ) ) ;
807
+ for path in invoice. payment_paths ( ) {
808
+ assert_eq ! ( path. introduction_node( ) , & IntroductionNode :: NodeId ( alice_id) ) ;
809
+ }
810
+ route_bolt12_payment ( bob, & [ alice] , & invoice) ;
811
+ expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
812
+ claim_bolt12_payment ( bob, & [ alice] , payment_context) ;
813
+ expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
814
+ }
815
+
744
816
/// Checks that a refund can be paid through a one-hop blinded path and that ephemeral pubkeys are
745
817
/// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
746
818
/// introduction node of the blinded path.
0 commit comments