@@ -330,6 +330,38 @@ fn extract_payment_preimage(event: &Event) -> PaymentPreimage {
330330 }
331331}
332332
333+ fn expect_offer_paths_requests ( recipient : & Node , next_hop_nodes : & [ & Node ] ) {
334+ // We want to check that the async recipient has enqueued at least one `OfferPathsRequest` and no
335+ // other message types. Check this by iterating through all their outbound onion messages, peeling
336+ // multiple times if the messages are forwarded through other nodes.
337+ let per_msg_recipient_msgs = recipient. onion_messenger . release_pending_msgs ( ) ;
338+ let mut pk_to_msg = Vec :: new ( ) ;
339+ for ( pk, msgs) in per_msg_recipient_msgs {
340+ for msg in msgs {
341+ pk_to_msg. push ( ( pk, msg) ) ;
342+ }
343+ }
344+ let mut num_offer_paths_reqs: u8 = 0 ;
345+ while let Some ( ( pk, msg) ) = pk_to_msg. pop ( ) {
346+ let node = next_hop_nodes. iter ( ) . find ( |node| node. node . get_our_node_id ( ) == pk) . unwrap ( ) ;
347+ let peeled_msg = node. onion_messenger . peel_onion_message ( & msg) . unwrap ( ) ;
348+ match peeled_msg {
349+ PeeledOnion :: AsyncPayments ( AsyncPaymentsMessage :: OfferPathsRequest ( _) , _, _) => {
350+ num_offer_paths_reqs += 1 ;
351+ } ,
352+ PeeledOnion :: Forward ( next_hop, msg) => {
353+ let next_pk = match next_hop {
354+ crate :: blinded_path:: message:: NextMessageHop :: NodeId ( pk) => pk,
355+ _ => panic ! ( ) ,
356+ } ;
357+ pk_to_msg. push ( ( next_pk, msg) ) ;
358+ } ,
359+ _ => panic ! ( "Unexpected message" ) ,
360+ }
361+ }
362+ assert ! ( num_offer_paths_reqs > 0 ) ;
363+ }
364+
333365fn advance_time_by ( duration : Duration , node : & Node ) {
334366 let target_time = ( node. node . duration_since_epoch ( ) + duration) . as_secs ( ) as u32 ;
335367 let block = create_dummy_block ( node. best_block_hash ( ) , target_time, Vec :: new ( ) ) ;
@@ -512,6 +544,7 @@ fn ignore_unexpected_static_invoice() {
512544 let inv_server_paths =
513545 nodes[ 1 ] . node . blinded_paths_for_async_recipient ( recipient_id. clone ( ) , None ) . unwrap ( ) ;
514546 nodes[ 2 ] . node . set_paths_to_static_invoice_server ( inv_server_paths) . unwrap ( ) ;
547+ expect_offer_paths_requests ( & nodes[ 2 ] , & [ & nodes[ 0 ] , & nodes[ 1 ] ] ) ;
515548
516549 // Initiate payment to the sender's intended offer.
517550 let valid_static_invoice =
@@ -609,6 +642,7 @@ fn async_receive_flow_success() {
609642 let inv_server_paths =
610643 nodes[ 1 ] . node . blinded_paths_for_async_recipient ( recipient_id. clone ( ) , None ) . unwrap ( ) ;
611644 nodes[ 2 ] . node . set_paths_to_static_invoice_server ( inv_server_paths) . unwrap ( ) ;
645+ expect_offer_paths_requests ( & nodes[ 2 ] , & [ & nodes[ 0 ] , & nodes[ 1 ] ] ) ;
612646
613647 let invoice_flow_res =
614648 pass_static_invoice_server_messages ( & nodes[ 1 ] , & nodes[ 2 ] , recipient_id. clone ( ) ) ;
@@ -671,6 +705,7 @@ fn expired_static_invoice_fail() {
671705 let inv_server_paths =
672706 nodes[ 1 ] . node . blinded_paths_for_async_recipient ( recipient_id. clone ( ) , None ) . unwrap ( ) ;
673707 nodes[ 2 ] . node . set_paths_to_static_invoice_server ( inv_server_paths) . unwrap ( ) ;
708+ expect_offer_paths_requests ( & nodes[ 2 ] , & [ & nodes[ 0 ] , & nodes[ 1 ] ] ) ;
674709
675710 let static_invoice =
676711 pass_static_invoice_server_messages ( & nodes[ 1 ] , & nodes[ 2 ] , recipient_id. clone ( ) ) . invoice ;
@@ -746,6 +781,7 @@ fn timeout_unreleased_payment() {
746781 let inv_server_paths =
747782 server. node . blinded_paths_for_async_recipient ( recipient_id. clone ( ) , None ) . unwrap ( ) ;
748783 recipient. node . set_paths_to_static_invoice_server ( inv_server_paths) . unwrap ( ) ;
784+ expect_offer_paths_requests ( & nodes[ 2 ] , & [ & nodes[ 0 ] , & nodes[ 1 ] ] ) ;
749785
750786 let static_invoice =
751787 pass_static_invoice_server_messages ( server, recipient, recipient_id. clone ( ) ) . invoice ;
@@ -831,6 +867,7 @@ fn async_receive_mpp() {
831867 let inv_server_paths =
832868 nodes[ 1 ] . node . blinded_paths_for_async_recipient ( recipient_id. clone ( ) , None ) . unwrap ( ) ;
833869 nodes[ 3 ] . node . set_paths_to_static_invoice_server ( inv_server_paths) . unwrap ( ) ;
870+ expect_offer_paths_requests ( & nodes[ 3 ] , & [ & nodes[ 0 ] , & nodes[ 1 ] , & nodes[ 2 ] ] ) ;
834871
835872 let static_invoice =
836873 pass_static_invoice_server_messages ( & nodes[ 1 ] , & nodes[ 3 ] , recipient_id. clone ( ) ) . invoice ;
@@ -924,6 +961,7 @@ fn amount_doesnt_match_invreq() {
924961 let inv_server_paths =
925962 nodes[ 1 ] . node . blinded_paths_for_async_recipient ( recipient_id. clone ( ) , None ) . unwrap ( ) ;
926963 nodes[ 3 ] . node . set_paths_to_static_invoice_server ( inv_server_paths) . unwrap ( ) ;
964+ expect_offer_paths_requests ( & nodes[ 3 ] , & [ & nodes[ 0 ] , & nodes[ 1 ] , & nodes[ 2 ] ] ) ;
927965
928966 let static_invoice =
929967 pass_static_invoice_server_messages ( & nodes[ 1 ] , & nodes[ 3 ] , recipient_id. clone ( ) ) . invoice ;
@@ -1124,6 +1162,7 @@ fn invalid_async_receive_with_retry<F1, F2>(
11241162 let inv_server_paths =
11251163 nodes[ 1 ] . node . blinded_paths_for_async_recipient ( recipient_id. clone ( ) , None ) . unwrap ( ) ;
11261164 nodes[ 2 ] . node . set_paths_to_static_invoice_server ( inv_server_paths) . unwrap ( ) ;
1165+ expect_offer_paths_requests ( & nodes[ 2 ] , & [ & nodes[ 0 ] , & nodes[ 1 ] ] ) ;
11271166
11281167 // Set the random bytes so we can predict the offer nonce.
11291168 let hardcoded_random_bytes = [ 42 ; 32 ] ;
@@ -1251,6 +1290,7 @@ fn expired_static_invoice_message_path() {
12511290 let inv_server_paths =
12521291 nodes[ 1 ] . node . blinded_paths_for_async_recipient ( recipient_id. clone ( ) , None ) . unwrap ( ) ;
12531292 nodes[ 2 ] . node . set_paths_to_static_invoice_server ( inv_server_paths) . unwrap ( ) ;
1293+ expect_offer_paths_requests ( & nodes[ 2 ] , & [ & nodes[ 0 ] , & nodes[ 1 ] ] ) ;
12541294
12551295 let static_invoice =
12561296 pass_static_invoice_server_messages ( & nodes[ 1 ] , & nodes[ 2 ] , recipient_id. clone ( ) ) . invoice ;
@@ -1315,6 +1355,7 @@ fn expired_static_invoice_payment_path() {
13151355 let inv_server_paths =
13161356 nodes[ 1 ] . node . blinded_paths_for_async_recipient ( recipient_id. clone ( ) , None ) . unwrap ( ) ;
13171357 nodes[ 2 ] . node . set_paths_to_static_invoice_server ( inv_server_paths) . unwrap ( ) ;
1358+ expect_offer_paths_requests ( & nodes[ 2 ] , & [ & nodes[ 0 ] , & nodes[ 1 ] ] ) ;
13181359
13191360 // Make sure all nodes are at the same block height in preparation for CLTV timeout things.
13201361 let node_max_height =
@@ -1576,10 +1617,12 @@ fn limit_offer_paths_requests() {
15761617 let inv_server_paths =
15771618 server. node . blinded_paths_for_async_recipient ( recipient_id, None ) . unwrap ( ) ;
15781619 recipient. node . set_paths_to_static_invoice_server ( inv_server_paths) . unwrap ( ) ;
1620+ expect_offer_paths_requests ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] ) ;
15791621
15801622 // Up to TEST_MAX_UPDATE_ATTEMPTS offer_paths_requests are allowed to be sent out before the async
15811623 // recipient should give up.
1582- for _ in 0 ..TEST_MAX_UPDATE_ATTEMPTS {
1624+ // Subtract 1 because we sent the first request when invoice server paths were set above.
1625+ for _ in 0 ..TEST_MAX_UPDATE_ATTEMPTS - 1 {
15831626 recipient. node . test_check_refresh_async_receive_offers ( ) ;
15841627 let offer_paths_req = recipient
15851628 . onion_messenger
@@ -1744,6 +1787,7 @@ fn refresh_static_invoices() {
17441787 let inv_server_paths =
17451788 server. node . blinded_paths_for_async_recipient ( recipient_id. clone ( ) , None ) . unwrap ( ) ;
17461789 recipient. node . set_paths_to_static_invoice_server ( inv_server_paths) . unwrap ( ) ;
1790+ expect_offer_paths_requests ( & nodes[ 2 ] , & [ & nodes[ 0 ] , & nodes[ 1 ] ] ) ;
17471791
17481792 // Set up the recipient to have one offer and an invoice with the static invoice server.
17491793 let flow_res = pass_static_invoice_server_messages ( server, recipient, recipient_id. clone ( ) ) ;
@@ -2136,6 +2180,7 @@ fn invoice_server_is_not_channel_peer() {
21362180 let inv_server_paths =
21372181 invoice_server. node . blinded_paths_for_async_recipient ( recipient_id. clone ( ) , None ) . unwrap ( ) ;
21382182 recipient. node . set_paths_to_static_invoice_server ( inv_server_paths) . unwrap ( ) ;
2183+ expect_offer_paths_requests ( & nodes[ 2 ] , & [ & nodes[ 0 ] , & nodes[ 1 ] , & nodes[ 3 ] ] ) ;
21392184 let invoice =
21402185 pass_static_invoice_server_messages ( invoice_server, recipient, recipient_id. clone ( ) )
21412186 . invoice ;
0 commit comments