@@ -20,6 +20,8 @@ use crate::ln::offers_tests;
20
20
use crate :: ln:: onion_utils:: INVALID_ONION_BLINDING ;
21
21
use crate :: ln:: outbound_payment:: Retry ;
22
22
use crate :: offers:: nonce:: Nonce ;
23
+ use crate :: offers:: offer:: Offer ;
24
+ use crate :: offers:: static_invoice:: StaticInvoice ;
23
25
use crate :: onion_message:: async_payments:: {
24
26
AsyncPaymentsMessage , AsyncPaymentsMessageHandler , ReleaseHeldHtlc ,
25
27
} ;
@@ -32,11 +34,39 @@ use crate::sign::NodeSigner;
32
34
use crate :: types:: features:: Bolt12InvoiceFeatures ;
33
35
use crate :: types:: payment:: { PaymentPreimage , PaymentSecret } ;
34
36
use crate :: util:: config:: UserConfig ;
37
+ use bitcoin:: secp256k1;
35
38
use bitcoin:: secp256k1:: Secp256k1 ;
36
39
37
40
use core:: convert:: Infallible ;
38
41
use core:: time:: Duration ;
39
42
43
+ fn create_static_invoice < T : secp256k1:: Signing + secp256k1:: Verification > (
44
+ always_online_counterparty : & Node , recipient : & Node , relative_expiry : Option < Duration > ,
45
+ secp_ctx : & Secp256k1 < T > ,
46
+ ) -> ( Offer , StaticInvoice ) {
47
+ let blinded_paths_to_always_online_node = always_online_counterparty
48
+ . message_router
49
+ . create_blinded_paths (
50
+ always_online_counterparty. node . get_our_node_id ( ) ,
51
+ MessageContext :: Offers ( OffersContext :: InvoiceRequest { nonce : Nonce ( [ 42 ; 16 ] ) } ) ,
52
+ Vec :: new ( ) ,
53
+ & secp_ctx,
54
+ )
55
+ . unwrap ( ) ;
56
+ let ( offer_builder, offer_nonce) = recipient
57
+ . node
58
+ . create_async_receive_offer_builder ( blinded_paths_to_always_online_node)
59
+ . unwrap ( ) ;
60
+ let offer = offer_builder. build ( ) . unwrap ( ) ;
61
+ let static_invoice = recipient
62
+ . node
63
+ . create_static_invoice_builder ( & offer, offer_nonce, relative_expiry)
64
+ . unwrap ( )
65
+ . build_and_sign ( & secp_ctx)
66
+ . unwrap ( ) ;
67
+ ( offer, static_invoice)
68
+ }
69
+
40
70
#[ test]
41
71
fn blinded_keysend ( ) {
42
72
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
@@ -362,20 +392,8 @@ fn ignore_unexpected_static_invoice() {
362
392
create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
363
393
364
394
// Initiate payment to the sender's intended offer.
365
- let blinded_paths_to_always_online_node = nodes[ 1 ]
366
- . message_router
367
- . create_blinded_paths (
368
- nodes[ 1 ] . node . get_our_node_id ( ) ,
369
- MessageContext :: Offers ( OffersContext :: InvoiceRequest { nonce : Nonce ( [ 42 ; 16 ] ) } ) ,
370
- Vec :: new ( ) ,
371
- & secp_ctx,
372
- )
373
- . unwrap ( ) ;
374
- let ( offer_builder, offer_nonce) = nodes[ 2 ]
375
- . node
376
- . create_async_receive_offer_builder ( blinded_paths_to_always_online_node. clone ( ) )
377
- . unwrap ( ) ;
378
- let offer = offer_builder. build ( ) . unwrap ( ) ;
395
+ let ( offer, valid_static_invoice) =
396
+ create_static_invoice ( & nodes[ 1 ] , & nodes[ 2 ] , None , & secp_ctx) ;
379
397
let amt_msat = 5000 ;
380
398
let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
381
399
nodes[ 0 ]
@@ -393,20 +411,7 @@ fn ignore_unexpected_static_invoice() {
393
411
394
412
// Create a static invoice to be sent over the reply path containing the original payment_id, but
395
413
// the static invoice corresponds to a different offer than was originally paid.
396
- let unexpected_static_invoice = {
397
- let ( offer_builder, nonce) = nodes[ 2 ]
398
- . node
399
- . create_async_receive_offer_builder ( blinded_paths_to_always_online_node)
400
- . unwrap ( ) ;
401
- let sender_unintended_offer = offer_builder. build ( ) . unwrap ( ) ;
402
-
403
- nodes[ 2 ]
404
- . node
405
- . create_static_invoice_builder ( & sender_unintended_offer, nonce, None )
406
- . unwrap ( )
407
- . build_and_sign ( & secp_ctx)
408
- . unwrap ( )
409
- } ;
414
+ let unexpected_static_invoice = create_static_invoice ( & nodes[ 1 ] , & nodes[ 2 ] , None , & secp_ctx) . 1 ;
410
415
411
416
// Check that we'll ignore the unexpected static invoice.
412
417
nodes[ 1 ]
@@ -433,13 +438,6 @@ fn ignore_unexpected_static_invoice() {
433
438
434
439
// A valid static invoice corresponding to the correct offer will succeed and cause us to send a
435
440
// held_htlc_available onion message.
436
- let valid_static_invoice = nodes[ 2 ]
437
- . node
438
- . create_static_invoice_builder ( & offer, offer_nonce, None )
439
- . unwrap ( )
440
- . build_and_sign ( & secp_ctx)
441
- . unwrap ( ) ;
442
-
443
441
nodes[ 1 ]
444
442
. onion_messenger
445
443
. send_onion_message (
@@ -499,32 +497,14 @@ fn pays_static_invoice() {
499
497
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
500
498
create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
501
499
502
- let blinded_paths_to_always_online_node = nodes[ 1 ]
503
- . message_router
504
- . create_blinded_paths (
505
- nodes[ 1 ] . node . get_our_node_id ( ) ,
506
- MessageContext :: Offers ( OffersContext :: InvoiceRequest { nonce : Nonce ( [ 42 ; 16 ] ) } ) ,
507
- Vec :: new ( ) ,
508
- & secp_ctx,
509
- )
510
- . unwrap ( ) ;
511
- let ( offer_builder, offer_nonce) = nodes[ 2 ]
512
- . node
513
- . create_async_receive_offer_builder ( blinded_paths_to_always_online_node)
514
- . unwrap ( ) ;
515
- let offer = offer_builder. build ( ) . unwrap ( ) ;
516
- let amt_msat = 5000 ;
517
- let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
518
500
let relative_expiry = Duration :: from_secs ( 1000 ) ;
519
- let static_invoice = nodes[ 2 ]
520
- . node
521
- . create_static_invoice_builder ( & offer, offer_nonce, Some ( relative_expiry) )
522
- . unwrap ( )
523
- . build_and_sign ( & secp_ctx)
524
- . unwrap ( ) ;
501
+ let ( offer, static_invoice) =
502
+ create_static_invoice ( & nodes[ 1 ] , & nodes[ 2 ] , Some ( relative_expiry) , & secp_ctx) ;
525
503
assert ! ( static_invoice. invoice_features( ) . supports_basic_mpp( ) ) ;
526
504
assert_eq ! ( static_invoice. relative_expiry( ) , relative_expiry) ;
527
505
506
+ let amt_msat = 5000 ;
507
+ let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
528
508
nodes[ 0 ]
529
509
. node
530
510
. pay_for_offer ( & offer, None , Some ( amt_msat) , None , payment_id, Retry :: Attempts ( 0 ) , None )
0 commit comments