@@ -27,7 +27,7 @@ use crate::ln::outbound_payment::{
27
27
PendingOutboundPayment , Retry , TEST_ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY ,
28
28
} ;
29
29
use crate :: offers:: async_receive_offer_cache:: {
30
- TEST_MAX_CACHED_OFFERS_TARGET , TEST_MAX_UPDATE_ATTEMPTS ,
30
+ TEST_INVOICE_REFRESH_THRESHOLD , TEST_MAX_CACHED_OFFERS_TARGET , TEST_MAX_UPDATE_ATTEMPTS ,
31
31
TEST_MIN_OFFER_PATHS_RELATIVE_EXPIRY_SECS , TEST_OFFER_REFRESH_THRESHOLD ,
32
32
} ;
33
33
use crate :: offers:: flow:: {
@@ -1680,11 +1680,53 @@ fn offer_cache_round_trip_ser() {
1680
1680
assert_eq ! ( cached_offers_pre_ser, cached_offers_post_ser) ;
1681
1681
}
1682
1682
1683
+ #[ test]
1684
+ fn refresh_static_invoices_for_pending_offers ( ) {
1685
+ // Check that an invoice for an offer that is pending persistence with the server will be updated
1686
+ // every timer tick.
1687
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1688
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1689
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None , None ] ) ;
1690
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1691
+ create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
1692
+ let server = & nodes[ 0 ] ;
1693
+ let recipient = & nodes[ 1 ] ;
1694
+
1695
+ let recipient_id = vec ! [ 42 ; 32 ] ;
1696
+ let inv_server_paths =
1697
+ server. node . blinded_paths_for_async_recipient ( recipient_id. clone ( ) , None ) . unwrap ( ) ;
1698
+ recipient. node . set_paths_to_static_invoice_server ( inv_server_paths) . unwrap ( ) ;
1699
+ expect_offer_paths_requests ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] ) ;
1700
+
1701
+ // Set up the recipient to have one offer pending with the static invoice server.
1702
+ invoice_flow_up_to_send_serve_static_invoice ( server, recipient) ;
1703
+
1704
+ // Every timer tick, we'll send a fresh invoice to the server.
1705
+ for _ in 0 ..10 {
1706
+ recipient. node . timer_tick_occurred ( ) ;
1707
+ let pending_oms = recipient. onion_messenger . release_pending_msgs ( ) ;
1708
+ pending_oms
1709
+ . get ( & server. node . get_our_node_id ( ) )
1710
+ . unwrap ( )
1711
+ . into_iter ( )
1712
+ . find ( |msg| match server. onion_messenger . peel_onion_message ( & msg) . unwrap ( ) {
1713
+ PeeledOnion :: AsyncPayments ( AsyncPaymentsMessage :: ServeStaticInvoice ( _) , _, _) => {
1714
+ true
1715
+ } ,
1716
+ PeeledOnion :: AsyncPayments ( AsyncPaymentsMessage :: OfferPathsRequest ( _) , _, _) => {
1717
+ false
1718
+ } ,
1719
+ _ => panic ! ( "Unexpected message" ) ,
1720
+ } )
1721
+ . unwrap ( ) ;
1722
+ }
1723
+ }
1724
+
1683
1725
#[ cfg_attr( feature = "std" , ignore) ]
1684
1726
#[ test]
1685
- fn refresh_static_invoices ( ) {
1686
- // Check that an invoice for a particular offer stored with the server will be updated once per
1687
- // timer tick .
1727
+ fn refresh_static_invoices_for_used_offers ( ) {
1728
+ // Check that an invoice for a used offer stored with the server will be updated every
1729
+ // INVOICE_REFRESH_THRESHOLD .
1688
1730
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
1689
1731
let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
1690
1732
@@ -1709,19 +1751,20 @@ fn refresh_static_invoices() {
1709
1751
// Set up the recipient to have one offer and an invoice with the static invoice server.
1710
1752
let flow_res = pass_static_invoice_server_messages ( server, recipient, recipient_id. clone ( ) ) ;
1711
1753
let original_invoice = flow_res. invoice ;
1712
- // Mark the offer as used so we'll update the invoice on timer tick .
1754
+ // Mark the offer as used so we'll update the invoice after INVOICE_REFRESH_THRESHOLD .
1713
1755
let _offer = recipient. node . get_async_receive_offer ( ) . unwrap ( ) ;
1714
1756
1715
1757
// Force the server and recipient to send OMs directly to each other for testing simplicity.
1716
1758
server. message_router . peers_override . lock ( ) . unwrap ( ) . push ( recipient. node . get_our_node_id ( ) ) ;
1717
1759
recipient. message_router . peers_override . lock ( ) . unwrap ( ) . push ( server. node . get_our_node_id ( ) ) ;
1718
1760
1719
- assert ! ( recipient
1720
- . onion_messenger
1721
- . next_onion_message_for_peer ( server . node. get_our_node_id ( ) )
1722
- . is_none ( ) ) ;
1761
+ // Prior to INVOICE_REFRESH_THRESHOLD, we won't refresh the invoice.
1762
+ advance_time_by ( TEST_INVOICE_REFRESH_THRESHOLD , recipient ) ;
1763
+ recipient . node . timer_tick_occurred ( ) ;
1764
+ expect_offer_paths_requests ( & nodes [ 2 ] , & [ & nodes [ 0 ] , & nodes [ 1 ] ] ) ;
1723
1765
1724
- // Check that we'll refresh the invoice on the next timer tick.
1766
+ // After INVOICE_REFRESH_THRESHOLD, we will refresh the invoice.
1767
+ advance_time_by ( Duration :: from_secs ( 1 ) , recipient) ;
1725
1768
recipient. node . timer_tick_occurred ( ) ;
1726
1769
let pending_oms = recipient. onion_messenger . release_pending_msgs ( ) ;
1727
1770
let serve_static_invoice_om = pending_oms
0 commit comments