13
13
#include <plugins/renepay/routebuilder.h>
14
14
#include <plugins/renepay/routetracker.h>
15
15
#include <unistd.h>
16
+ #include <wire/bolt12_wiregen.h>
16
17
17
18
#define INVALID_ID UINT32_MAX
18
19
@@ -515,7 +516,9 @@ REGISTER_PAYMENT_MODIFIER(refreshgossmap, refreshgossmap_cb);
515
516
static void add_hintchan (struct payment * payment , const struct node_id * src ,
516
517
const struct node_id * dst , u16 cltv_expiry_delta ,
517
518
const struct short_channel_id scid , u32 fee_base_msat ,
518
- u32 fee_proportional_millionths )
519
+ u32 fee_proportional_millionths ,
520
+ const struct amount_msat * chan_htlc_min ,
521
+ const struct amount_msat * chan_htlc_max )
519
522
{
520
523
assert (payment );
521
524
assert (payment -> local_gossmods );
@@ -528,6 +531,12 @@ static void add_hintchan(struct payment *payment, const struct node_id *src,
528
531
struct short_channel_id_dir scidd ;
529
532
/* We assume any HTLC is allowed */
530
533
struct amount_msat htlc_min = AMOUNT_MSAT (0 ), htlc_max = MAX_CAPACITY ;
534
+
535
+ if (chan_htlc_min )
536
+ htlc_min = * chan_htlc_min ;
537
+ if (chan_htlc_max )
538
+ htlc_max = * chan_htlc_max ;
539
+
531
540
struct amount_msat fee_base = amount_msat (fee_base_msat );
532
541
bool enabled = true;
533
542
scidd .scid = scid ;
@@ -604,7 +613,8 @@ static struct command_result *routehints_done(struct command *cmd UNUSED,
604
613
add_hintchan (payment , & r [j ].pubkey , end ,
605
614
r [j ].cltv_expiry_delta ,
606
615
r [j ].short_channel_id , r [j ].fee_base_msat ,
607
- r [j ].fee_proportional_millionths );
616
+ r [j ].fee_proportional_millionths ,
617
+ NULL , NULL );
608
618
end = & r [j ].pubkey ;
609
619
}
610
620
}
@@ -625,6 +635,8 @@ static struct command_result *routehints_done(struct command *cmd UNUSED,
625
635
626
636
static struct command_result * routehints_cb (struct payment * payment )
627
637
{
638
+ if (payment -> payment_info .routehints == NULL )
639
+ return payment_continue (payment );
628
640
struct command * cmd = payment_command (payment );
629
641
assert (cmd );
630
642
struct out_req * req = jsonrpc_request_start (
@@ -636,6 +648,44 @@ static struct command_result *routehints_cb(struct payment *payment)
636
648
637
649
REGISTER_PAYMENT_MODIFIER (routehints , routehints_cb );
638
650
651
+
652
+ /*****************************************************************************
653
+ * blindedhints
654
+ *
655
+ * Similar to routehints but for bolt12 invoices: create fake channel that
656
+ * connect the blinded path entry point to the destination node.
657
+ */
658
+
659
+ static struct command_result * blindedhints_cb (struct payment * payment )
660
+ {
661
+ if (payment -> payment_info .blinded_paths == NULL )
662
+ return payment_continue (payment );
663
+
664
+ struct payment_info * pinfo = & payment -> payment_info ;
665
+ struct short_channel_id scid ;
666
+ struct node_id src ;
667
+
668
+ for (size_t i = 0 ; i < tal_count (pinfo -> blinded_paths ); i ++ ) {
669
+ const struct blinded_payinfo * payinfo =
670
+ pinfo -> blinded_payinfos [i ];
671
+ const struct blinded_path * path = pinfo -> blinded_paths [i ];
672
+
673
+ scid .u64 = i ; // a fake scid
674
+ node_id_from_pubkey (& src , & path -> first_node_id .pubkey );
675
+
676
+ add_hintchan (payment , & src , payment -> routing_destination ,
677
+ payinfo -> cltv_expiry_delta , scid ,
678
+ payinfo -> fee_base_msat ,
679
+ payinfo -> fee_proportional_millionths ,
680
+ & payinfo -> htlc_minimum_msat ,
681
+ & payinfo -> htlc_maximum_msat );
682
+ }
683
+ return payment_continue (payment );
684
+ }
685
+
686
+ REGISTER_PAYMENT_MODIFIER (blindedhints , blindedhints_cb );
687
+
688
+
639
689
/*****************************************************************************
640
690
* compute_routes
641
691
*
@@ -694,23 +744,30 @@ static struct command_result *compute_routes_cb(struct payment *payment)
694
744
* better to pass computed_routes as a reference? */
695
745
routetracker -> computed_routes = tal_free (routetracker -> computed_routes );
696
746
747
+ /* Send get_routes a note that it should discard the last hop because we
748
+ * are actually solving a multiple destinations problem. */
749
+ bool blinded_destination =
750
+ payment -> payment_info .blinded_paths != NULL ;
751
+
697
752
// TODO: add an algorithm selector here
698
753
/* We let this return an unlikely path, as it's better to try once than
699
754
* simply refuse. Plus, models are not truth! */
700
755
routetracker -> computed_routes = get_routes (
701
756
routetracker ,
702
757
& payment -> payment_info ,
703
758
& pay_plugin -> my_id ,
704
- & payment -> payment_info . destination ,
759
+ payment -> routing_destination ,
705
760
pay_plugin -> gossmap ,
706
761
pay_plugin -> uncertainty ,
707
762
payment -> disabledmap ,
708
763
remaining ,
709
764
feebudget ,
710
765
& payment -> next_partid ,
711
766
payment -> groupid ,
767
+ blinded_destination ,
712
768
& errcode ,
713
769
& err_msg );
770
+
714
771
/* Otherwise the error message remains a child of the routetracker. */
715
772
err_msg = tal_steal (tmpctx , err_msg );
716
773
@@ -1230,20 +1287,21 @@ void *payment_virtual_program[] = {
1230
1287
/*6*/ OP_CALL , & getmychannels_pay_mod ,
1231
1288
/*8*/ OP_CALL , & refreshgossmap_pay_mod ,
1232
1289
/*10*/ OP_CALL , & routehints_pay_mod ,
1233
- /*12*/ OP_CALL , & channelfilter_pay_mod ,
1290
+ /*12*/ OP_CALL , & blindedhints_pay_mod ,
1291
+ /*14*/ OP_CALL , & channelfilter_pay_mod ,
1234
1292
// TODO shadow_additions
1235
1293
/* do */
1236
- /*14 */ OP_CALL , & pendingsendpays_pay_mod ,
1237
- /*16 */ OP_CALL , & checktimeout_pay_mod ,
1238
- /*18 */ OP_CALL , & refreshgossmap_pay_mod ,
1239
- /*20 */ OP_CALL , & compute_routes_pay_mod ,
1240
- /*22 */ OP_CALL , & send_routes_pay_mod ,
1294
+ /*16 */ OP_CALL , & pendingsendpays_pay_mod ,
1295
+ /*18 */ OP_CALL , & checktimeout_pay_mod ,
1296
+ /*20 */ OP_CALL , & refreshgossmap_pay_mod ,
1297
+ /*22 */ OP_CALL , & compute_routes_pay_mod ,
1298
+ /*24 */ OP_CALL , & send_routes_pay_mod ,
1241
1299
/*do*/
1242
- /*24 */ OP_CALL , & sleep_pay_mod ,
1243
- /*26 */ OP_CALL , & collect_results_pay_mod ,
1300
+ /*26 */ OP_CALL , & sleep_pay_mod ,
1301
+ /*28 */ OP_CALL , & collect_results_pay_mod ,
1244
1302
/*while*/
1245
- /*28 */ OP_IF , & nothaveresults_pay_cond , (void * )24 ,
1303
+ /*30 */ OP_IF , & nothaveresults_pay_cond , (void * )26 ,
1246
1304
/* while */
1247
- /*31 */ OP_IF , & retry_pay_cond , (void * )14 ,
1248
- /*34 */ OP_CALL , & end_pay_mod , /* safety net, default failure if reached */
1249
- /*36 */ NULL };
1305
+ /*33 */ OP_IF , & retry_pay_cond , (void * )16 ,
1306
+ /*36 */ OP_CALL , & end_pay_mod , /* safety net, default failure if reached */
1307
+ /*38 */ NULL };
0 commit comments