@@ -12,8 +12,9 @@ use bitcoin::secp256k1::Secp256k1;
12
12
use lightning:: chain;
13
13
use lightning:: ln:: channelmanager:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
14
14
use lightning:: ln:: features:: InvoiceFeatures ;
15
- use lightning:: routing:: network_graph:: NetGraphMsgHandler ;
15
+ use lightning:: routing:: network_graph:: { NetGraphMsgHandler , RoutingFees } ;
16
16
use lightning:: routing:: router;
17
+ use lightning:: routing:: router:: RouteHint ;
17
18
use lightning:: util:: config:: UserConfig ;
18
19
use rand;
19
20
use rand:: Rng ;
@@ -200,6 +201,8 @@ pub(crate) async fn poll_for_user_input(
200
201
continue ;
201
202
}
202
203
let invoice = invoice_res. unwrap ( ) ;
204
+ let route_hints: Vec < lightning_invoice:: Route > =
205
+ invoice. routes ( ) . iter ( ) . map ( |& route| route. clone ( ) ) . collect ( ) ;
203
206
204
207
let amt_pico_btc = invoice. amount_pico_btc ( ) ;
205
208
if amt_pico_btc. is_none ( ) {
@@ -272,6 +275,7 @@ pub(crate) async fn poll_for_user_input(
272
275
payment_hash,
273
276
payment_secret,
274
277
invoice_features_opt,
278
+ route_hints,
275
279
router. clone ( ) ,
276
280
channel_manager. clone ( ) ,
277
281
payment_storage. clone ( ) ,
@@ -500,6 +504,7 @@ fn open_channel(
500
504
fn send_payment (
501
505
payee : PublicKey , amt_msat : u64 , final_cltv : u32 , payment_hash : PaymentHash ,
502
506
payment_secret : Option < PaymentSecret > , payee_features : Option < InvoiceFeatures > ,
507
+ mut route_hints : Vec < lightning_invoice:: Route > ,
503
508
router : Arc < NetGraphMsgHandler < Arc < dyn chain:: Access > , Arc < FilesystemLogger > > > ,
504
509
channel_manager : Arc < ChannelManager > , payment_storage : PaymentInfoStorage ,
505
510
logger : Arc < FilesystemLogger > ,
@@ -508,13 +513,29 @@ fn send_payment(
508
513
let first_hops = channel_manager. list_usable_channels ( ) ;
509
514
let payer_pubkey = channel_manager. get_our_node_id ( ) ;
510
515
516
+ let mut hints: Vec < RouteHint > = Vec :: new ( ) ;
517
+ for route in route_hints. drain ( ..) {
518
+ let route_hops = route. into_inner ( ) ;
519
+ let last_hop = & route_hops[ route_hops. len ( ) - 1 ] ;
520
+ hints. push ( RouteHint {
521
+ src_node_id : last_hop. pubkey ,
522
+ short_channel_id : u64:: from_be_bytes ( last_hop. short_channel_id ) ,
523
+ fees : RoutingFees {
524
+ base_msat : last_hop. fee_base_msat ,
525
+ proportional_millionths : last_hop. fee_proportional_millionths ,
526
+ } ,
527
+ cltv_expiry_delta : last_hop. cltv_expiry_delta ,
528
+ htlc_minimum_msat : None ,
529
+ htlc_maximum_msat : None ,
530
+ } )
531
+ }
511
532
let route = router:: get_route (
512
533
& payer_pubkey,
513
534
& network_graph,
514
535
& payee,
515
536
payee_features,
516
537
Some ( & first_hops. iter ( ) . collect :: < Vec < _ > > ( ) ) ,
517
- & vec ! [ ] ,
538
+ & hints . iter ( ) . collect :: < Vec < _ > > ( ) ,
518
539
amt_msat,
519
540
final_cltv,
520
541
logger,
@@ -567,6 +588,7 @@ fn get_invoice(
567
588
568
589
// Add route hints to the invoice.
569
590
let our_channels = channel_manager. list_usable_channels ( ) ;
591
+ let mut min_final_cltv_expiry = 9 ;
570
592
for channel in our_channels {
571
593
let short_channel_id = match channel. short_channel_id {
572
594
Some ( id) => id. to_be_bytes ( ) ,
@@ -576,6 +598,9 @@ fn get_invoice(
576
598
Some ( info) => info,
577
599
None => continue ,
578
600
} ;
601
+ if forwarding_info. cltv_expiry_delta > min_final_cltv_expiry {
602
+ min_final_cltv_expiry = forwarding_info. cltv_expiry_delta ;
603
+ }
579
604
invoice = invoice. route ( vec ! [ lightning_invoice:: RouteHop {
580
605
pubkey: channel. remote_network_id,
581
606
short_channel_id,
@@ -584,6 +609,7 @@ fn get_invoice(
584
609
cltv_expiry_delta: forwarding_info. cltv_expiry_delta,
585
610
} ] ) ;
586
611
}
612
+ invoice = invoice. min_final_cltv_expiry ( min_final_cltv_expiry. into ( ) ) ;
587
613
588
614
// Sign the invoice.
589
615
let invoice =
0 commit comments