1313#include <plugins/renepay/routebuilder.h>
1414#include <plugins/renepay/routetracker.h>
1515#include <unistd.h>
16+ #include <wire/bolt12_wiregen.h>
1617
1718#define INVALID_ID UINT32_MAX
1819
@@ -515,7 +516,9 @@ REGISTER_PAYMENT_MODIFIER(refreshgossmap, refreshgossmap_cb);
515516static void add_hintchan (struct payment * payment , const struct node_id * src ,
516517 const struct node_id * dst , u16 cltv_expiry_delta ,
517518 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 )
519522{
520523 assert (payment );
521524 assert (payment -> local_gossmods );
@@ -528,6 +531,12 @@ static void add_hintchan(struct payment *payment, const struct node_id *src,
528531 struct short_channel_id_dir scidd ;
529532 /* We assume any HTLC is allowed */
530533 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+
531540 struct amount_msat fee_base = amount_msat (fee_base_msat );
532541 bool enabled = true;
533542 scidd .scid = scid ;
@@ -604,7 +613,8 @@ static struct command_result *routehints_done(struct command *cmd UNUSED,
604613 add_hintchan (payment , & r [j ].pubkey , end ,
605614 r [j ].cltv_expiry_delta ,
606615 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 );
608618 end = & r [j ].pubkey ;
609619 }
610620 }
@@ -625,6 +635,8 @@ static struct command_result *routehints_done(struct command *cmd UNUSED,
625635
626636static struct command_result * routehints_cb (struct payment * payment )
627637{
638+ if (payment -> payment_info .routehints == NULL )
639+ return payment_continue (payment );
628640 struct command * cmd = payment_command (payment );
629641 assert (cmd );
630642 struct out_req * req = jsonrpc_request_start (
@@ -636,6 +648,44 @@ static struct command_result *routehints_cb(struct payment *payment)
636648
637649REGISTER_PAYMENT_MODIFIER (routehints , routehints_cb );
638650
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+
639689/*****************************************************************************
640690 * compute_routes
641691 *
@@ -694,23 +744,30 @@ static struct command_result *compute_routes_cb(struct payment *payment)
694744 * better to pass computed_routes as a reference? */
695745 routetracker -> computed_routes = tal_free (routetracker -> computed_routes );
696746
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+
697752 // TODO: add an algorithm selector here
698753 /* We let this return an unlikely path, as it's better to try once than
699754 * simply refuse. Plus, models are not truth! */
700755 routetracker -> computed_routes = get_routes (
701756 routetracker ,
702757 & payment -> payment_info ,
703758 & pay_plugin -> my_id ,
704- & payment -> payment_info . destination ,
759+ payment -> routing_destination ,
705760 pay_plugin -> gossmap ,
706761 pay_plugin -> uncertainty ,
707762 payment -> disabledmap ,
708763 remaining ,
709764 feebudget ,
710765 & payment -> next_partid ,
711766 payment -> groupid ,
767+ blinded_destination ,
712768 & errcode ,
713769 & err_msg );
770+
714771 /* Otherwise the error message remains a child of the routetracker. */
715772 err_msg = tal_steal (tmpctx , err_msg );
716773
@@ -1230,20 +1287,21 @@ void *payment_virtual_program[] = {
12301287 /*6*/ OP_CALL , & getmychannels_pay_mod ,
12311288 /*8*/ OP_CALL , & refreshgossmap_pay_mod ,
12321289 /*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 ,
12341292 // TODO shadow_additions
12351293 /* 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 ,
12411299 /*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 ,
12441302 /*while*/
1245- /*28 */ OP_IF , & nothaveresults_pay_cond , (void * )24 ,
1303+ /*30 */ OP_IF , & nothaveresults_pay_cond , (void * )26 ,
12461304 /* 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