@@ -17,6 +17,7 @@ use crate::events::{
17
17
use crate :: ln:: blinded_payment_tests:: { fail_blinded_htlc_backwards, get_blinded_route_parameters} ;
18
18
use crate :: ln:: channelmanager:: { PaymentId , RecipientOnionFields } ;
19
19
use crate :: ln:: functional_test_utils:: * ;
20
+ use crate :: ln:: inbound_payment;
20
21
use crate :: ln:: msgs;
21
22
use crate :: ln:: msgs:: {
22
23
BaseMessageHandler , ChannelMessageHandler , MessageSendEvent , OnionMessageHandler ,
@@ -36,8 +37,11 @@ use crate::offers::flow::{
36
37
} ;
37
38
use crate :: offers:: invoice_request:: InvoiceRequest ;
38
39
use crate :: offers:: nonce:: Nonce ;
39
- use crate :: offers:: offer:: Offer ;
40
- use crate :: offers:: static_invoice:: StaticInvoice ;
40
+ use crate :: offers:: offer:: { Amount , Offer } ;
41
+ use crate :: offers:: static_invoice:: {
42
+ StaticInvoice , StaticInvoiceBuilder ,
43
+ DEFAULT_RELATIVE_EXPIRY as STATIC_INVOICE_DEFAULT_RELATIVE_EXPIRY ,
44
+ } ;
41
45
use crate :: onion_message:: async_payments:: { AsyncPaymentsMessage , AsyncPaymentsMessageHandler } ;
42
46
use crate :: onion_message:: messenger:: {
43
47
Destination , MessageRouter , MessageSendInstructions , PeeledOnion ,
@@ -240,10 +244,50 @@ fn pass_async_payments_oms(
240
244
( held_htlc_available_om_1_2, release_held_htlc)
241
245
}
242
246
247
+ fn create_static_invoice_builder < ' a > (
248
+ recipient : & Node , offer : & ' a Offer , offer_nonce : Nonce , relative_expiry : Option < Duration > ,
249
+ ) -> StaticInvoiceBuilder < ' a > {
250
+ let entropy = recipient. keys_manager ;
251
+ let amount_msat = offer. amount ( ) . and_then ( |amount| match amount {
252
+ Amount :: Bitcoin { amount_msats } => Some ( amount_msats) ,
253
+ Amount :: Currency { .. } => None ,
254
+ } ) ;
255
+
256
+ let relative_expiry = relative_expiry. unwrap_or ( STATIC_INVOICE_DEFAULT_RELATIVE_EXPIRY ) ;
257
+ let relative_expiry_secs: u32 = relative_expiry. as_secs ( ) . try_into ( ) . unwrap_or ( u32:: MAX ) ;
258
+
259
+ let created_at = recipient. node . duration_since_epoch ( ) ;
260
+ let payment_secret = inbound_payment:: create_for_spontaneous_payment (
261
+ & recipient. keys_manager . get_inbound_payment_key ( ) ,
262
+ amount_msat,
263
+ relative_expiry_secs,
264
+ created_at. as_secs ( ) ,
265
+ None ,
266
+ )
267
+ . unwrap ( ) ;
268
+
269
+ recipient
270
+ . node
271
+ . flow
272
+ . create_static_invoice_builder (
273
+ & recipient. router ,
274
+ entropy,
275
+ offer,
276
+ offer_nonce,
277
+ payment_secret,
278
+ relative_expiry_secs,
279
+ recipient. node . list_usable_channels ( ) ,
280
+ recipient. node . test_get_peers_for_blinded_path ( ) ,
281
+ )
282
+ . unwrap ( )
283
+ }
284
+
243
285
fn create_static_invoice < T : secp256k1:: Signing + secp256k1:: Verification > (
244
286
always_online_counterparty : & Node , recipient : & Node , relative_expiry : Option < Duration > ,
245
287
secp_ctx : & Secp256k1 < T > ,
246
288
) -> ( Offer , StaticInvoice ) {
289
+ let entropy_source = recipient. keys_manager ;
290
+
247
291
let blinded_paths_to_always_online_node = always_online_counterparty
248
292
. message_router
249
293
. create_blinded_paths (
@@ -256,15 +300,14 @@ fn create_static_invoice<T: secp256k1::Signing + secp256k1::Verification>(
256
300
. unwrap ( ) ;
257
301
let ( offer_builder, offer_nonce) = recipient
258
302
. node
259
- . create_async_receive_offer_builder ( blinded_paths_to_always_online_node)
303
+ . flow
304
+ . create_async_receive_offer_builder ( entropy_source, blinded_paths_to_always_online_node)
260
305
. unwrap ( ) ;
261
306
let offer = offer_builder. build ( ) . unwrap ( ) ;
262
- let static_invoice = recipient
263
- . node
264
- . create_static_invoice_builder ( & offer, offer_nonce, relative_expiry)
265
- . unwrap ( )
266
- . build_and_sign ( & secp_ctx)
267
- . unwrap ( ) ;
307
+ let static_invoice =
308
+ create_static_invoice_builder ( recipient, & offer, offer_nonce, relative_expiry)
309
+ . build_and_sign ( & secp_ctx)
310
+ . unwrap ( ) ;
268
311
( offer, static_invoice)
269
312
}
270
313
@@ -377,6 +420,7 @@ fn static_invoice_unknown_required_features() {
377
420
let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
378
421
let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
379
422
let nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
423
+ let entropy_source = nodes[ 2 ] . keys_manager ;
380
424
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
381
425
create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
382
426
@@ -393,16 +437,15 @@ fn static_invoice_unknown_required_features() {
393
437
. unwrap ( ) ;
394
438
let ( offer_builder, nonce) = nodes[ 2 ]
395
439
. node
396
- . create_async_receive_offer_builder ( blinded_paths_to_always_online_node)
440
+ . flow
441
+ . create_async_receive_offer_builder ( entropy_source, blinded_paths_to_always_online_node)
397
442
. unwrap ( ) ;
398
443
let offer = offer_builder. build ( ) . unwrap ( ) ;
399
- let static_invoice_unknown_req_features = nodes[ 2 ]
400
- . node
401
- . create_static_invoice_builder ( & offer, nonce, None )
402
- . unwrap ( )
403
- . features_unchecked ( Bolt12InvoiceFeatures :: unknown ( ) )
404
- . build_and_sign ( & secp_ctx)
405
- . unwrap ( ) ;
444
+ let static_invoice_unknown_req_features =
445
+ create_static_invoice_builder ( & nodes[ 2 ] , & offer, nonce, None )
446
+ . features_unchecked ( Bolt12InvoiceFeatures :: unknown ( ) )
447
+ . build_and_sign ( & secp_ctx)
448
+ . unwrap ( ) ;
406
449
407
450
// Initiate payment to the offer corresponding to the manually-constructed invoice that has
408
451
// unknown required features.
@@ -1073,6 +1116,7 @@ fn invalid_async_receive_with_retry<F1, F2>(
1073
1116
create_node_chanmgrs ( 3 , & node_cfgs, & [ None , Some ( allow_priv_chan_fwds_cfg) , None ] ) ;
1074
1117
1075
1118
let nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
1119
+ let entropy_source = nodes[ 2 ] . keys_manager ;
1076
1120
create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
1077
1121
create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
1078
1122
@@ -1102,7 +1146,8 @@ fn invalid_async_receive_with_retry<F1, F2>(
1102
1146
. unwrap ( ) ;
1103
1147
let ( offer_builder, offer_nonce) = nodes[ 2 ]
1104
1148
. node
1105
- . create_async_receive_offer_builder ( blinded_paths_to_always_online_node)
1149
+ . flow
1150
+ . create_async_receive_offer_builder ( entropy_source, blinded_paths_to_always_online_node)
1106
1151
. unwrap ( ) ;
1107
1152
let offer = offer_builder. build ( ) . unwrap ( ) ;
1108
1153
let amt_msat = 5000 ;
@@ -1112,12 +1157,10 @@ fn invalid_async_receive_with_retry<F1, F2>(
1112
1157
// use the same nodes to avoid complicating the test with a bunch of extra nodes.
1113
1158
let mut static_invoice_paths = Vec :: new ( ) ;
1114
1159
for _ in 0 ..3 {
1115
- let static_inv_for_path = nodes[ 2 ]
1116
- . node
1117
- . create_static_invoice_builder ( & offer, offer_nonce, None )
1118
- . unwrap ( )
1119
- . build_and_sign ( & secp_ctx)
1120
- . unwrap ( ) ;
1160
+ let static_inv_for_path =
1161
+ create_static_invoice_builder ( & nodes[ 2 ] , & offer, offer_nonce, None )
1162
+ . build_and_sign ( & secp_ctx)
1163
+ . unwrap ( ) ;
1121
1164
static_invoice_paths. push ( static_inv_for_path. payment_paths ( ) [ 0 ] . clone ( ) ) ;
1122
1165
}
1123
1166
nodes[ 2 ] . router . expect_blinded_payment_paths ( static_invoice_paths) ;
0 commit comments