@@ -301,11 +301,12 @@ struct amount_msat get_additional_per_htlc_cost(const struct route_query *rq,
301301 return AMOUNT_MSAT (0 );
302302}
303303
304- const char * rq_log (const tal_t * ctx ,
305- const struct route_query * rq ,
306- enum log_level level ,
307- const char * fmt ,
308- ...)
304+ PRINTF_FMT (4 , 5 )
305+ static const char * cmd_log (const tal_t * ctx ,
306+ struct command * cmd ,
307+ enum log_level level ,
308+ const char * fmt ,
309+ ...)
309310{
310311 va_list args ;
311312 const char * msg ;
@@ -314,14 +315,14 @@ const char *rq_log(const tal_t *ctx,
314315 msg = tal_vfmt (ctx , fmt , args );
315316 va_end (args );
316317
317- plugin_notify_message (rq -> cmd , level , "%s" , msg );
318+ plugin_notify_message (cmd , level , "%s" , msg );
318319
319320 /* Notifications already get logged at debug. Otherwise reduce
320321 * severity. */
321322 if (level != LOG_DBG )
322- plugin_log (rq -> plugin ,
323+ plugin_log (cmd -> plugin ,
323324 level == LOG_BROKEN ? level : level - 1 ,
324- "%s: %s" , rq -> cmd -> id , msg );
325+ "%s: %s" , cmd -> id , msg );
325326 return msg ;
326327}
327328
@@ -363,7 +364,9 @@ struct getroutes_info {
363364 u32 maxparts ;
364365};
365366
366- static void apply_layers (struct askrene * askrene , struct route_query * rq ,
367+ static void apply_layers (struct askrene * askrene ,
368+ struct command * cmd ,
369+ struct route_query * rq ,
367370 const struct node_id * source ,
368371 struct amount_msat amount ,
369372 struct gossmap_localmods * localmods ,
@@ -375,14 +378,17 @@ static void apply_layers(struct askrene *askrene, struct route_query *rq,
375378 const struct layer * l = find_layer (askrene , layers [i ]);
376379 if (!l ) {
377380 if (streq (layers [i ], "auto.localchans" )) {
378- plugin_log (rq -> plugin , LOG_DBG , "Adding auto.localchans" );
381+ cmd_log (tmpctx , cmd , LOG_DBG ,
382+ "Adding auto.localchans" );
379383 l = local_layer ;
380384 } else if (streq (layers [i ], "auto.no_mpp_support" )) {
381- plugin_log (rq -> plugin , LOG_DBG , "Adding auto.no_mpp_support, sorry" );
385+ cmd_log (tmpctx , cmd , LOG_DBG ,
386+ "Adding auto.no_mpp_support, sorry" );
382387 l = remove_small_channel_layer (layers , askrene , amount , localmods );
383388 } else {
384389 assert (streq (layers [i ], "auto.sourcefree" ));
385- plugin_log (rq -> plugin , LOG_DBG , "Adding auto.sourcefree" );
390+ cmd_log (tmpctx , cmd , LOG_DBG ,
391+ "Adding auto.sourcefree" );
386392 l = source_free_layer (layers , askrene , source , localmods );
387393 }
388394 }
@@ -433,15 +439,16 @@ void get_constraints(const struct route_query *rq,
433439 reserve_sub (rq -> reserved , & scidd , rq -> layers , max );
434440}
435441
436- static void process_child_logs (struct route_query * rq , int log_fd )
442+ static void process_child_logs (struct command * cmd ,
443+ int log_fd )
437444{
438445 u8 * msg ;
439446 while ((msg = wire_sync_read (tmpctx , log_fd )) != NULL ) {
440447 enum log_level level ;
441448 char * entry ;
442449 struct node_id * peer ;
443450 if (fromwire_status_log (tmpctx , msg , & level , & peer , & entry ))
444- rq_log (tmpctx , rq , level , "%s" , entry );
451+ cmd_log (tmpctx , cmd , level , "%s" , entry );
445452 }
446453}
447454
@@ -454,6 +461,7 @@ static struct command_result *do_getroutes(struct command *cmd,
454461 const char * err , * json ;
455462 struct timemono time_start , deadline ;
456463 int child_fd , log_fd , child_pid , child_status ;
464+ s8 * biases ;
457465
458466 /* update the gossmap */
459467 if (gossmap_refresh (askrene -> gossmap )) {
@@ -464,18 +472,16 @@ static struct command_result *do_getroutes(struct command *cmd,
464472 }
465473
466474 /* build this request structure */
467- rq -> cmd = cmd ;
468- rq -> plugin = cmd -> plugin ;
475+ rq -> cmd_id = cmd -> id ;
469476 rq -> gossmap = askrene -> gossmap ;
470477 rq -> reserved = askrene -> reserved ;
471478 rq -> layers = tal_arr (rq , const struct layer * , 0 );
472479 rq -> capacities = tal_dup_talarr (rq , fp16_t , askrene -> capacities );
473480 /* FIXME: we still need to do something useful with these */
474481 rq -> additional_costs = info -> additional_costs ;
475- rq -> maxparts = info -> maxparts ;
476482
477483 /* apply selected layers to the localmods */
478- apply_layers (askrene , rq , & info -> source , info -> amount , localmods ,
484+ apply_layers (askrene , cmd , rq , & info -> source , info -> amount , localmods ,
479485 info -> layers , info -> local_layer );
480486
481487 /* Clear scids with reservations, too, so we don't have to look up
@@ -495,18 +501,19 @@ static struct command_result *do_getroutes(struct command *cmd,
495501
496502 /* localmods can add channels, so we need to allocate biases array
497503 * *afterwards* */
498- rq -> biases =
504+ rq -> biases = biases =
499505 tal_arrz (rq , s8 , gossmap_max_chan_idx (askrene -> gossmap ) * 2 );
500506
501507 /* Note any channel biases */
502508 for (size_t i = 0 ; i < tal_count (rq -> layers ); i ++ )
503- layer_apply_biases (rq -> layers [i ], askrene -> gossmap , rq -> biases );
509+ layer_apply_biases (rq -> layers [i ], askrene -> gossmap , biases );
504510
505511 /* checkout the source */
506512 const struct gossmap_node * srcnode =
507513 gossmap_find_node (askrene -> gossmap , & info -> source );
508514 if (!srcnode ) {
509- err = rq_log (tmpctx , rq , LOG_INFORM , "Unknown source node %s" ,
515+ err = cmd_log (tmpctx , cmd , LOG_INFORM ,
516+ "Unknown source node %s" ,
510517 fmt_node_id (tmpctx , & info -> source ));
511518 goto fail ;
512519 }
@@ -515,7 +522,7 @@ static struct command_result *do_getroutes(struct command *cmd,
515522 const struct gossmap_node * dstnode =
516523 gossmap_find_node (askrene -> gossmap , & info -> dest );
517524 if (!dstnode ) {
518- err = rq_log (tmpctx , rq , LOG_INFORM ,
525+ err = cmd_log (tmpctx , cmd , LOG_INFORM ,
519526 "Unknown destination node %s" ,
520527 fmt_node_id (tmpctx , & info -> dest ));
521528 goto fail ;
@@ -525,14 +532,14 @@ static struct command_result *do_getroutes(struct command *cmd,
525532 if (have_layer (info -> layers , "auto.no_mpp_support" ) &&
526533 info -> dev_algo != ALGO_SINGLE_PATH ) {
527534 info -> dev_algo = ALGO_SINGLE_PATH ;
528- rq_log (tmpctx , rq , LOG_DBG ,
535+ cmd_log (tmpctx , cmd , LOG_DBG ,
529536 "Layer no_mpp_support is active we switch to a "
530537 "single path algorithm." );
531538 }
532- if (rq -> maxparts == 1 &&
539+ if (info -> maxparts == 1 &&
533540 info -> dev_algo != ALGO_SINGLE_PATH ) {
534541 info -> dev_algo = ALGO_SINGLE_PATH ;
535- rq_log (tmpctx , rq , LOG_DBG ,
542+ cmd_log (tmpctx , cmd , LOG_DBG ,
536543 "maxparts == 1: switching to a single path algorithm." );
537544 }
538545
@@ -542,14 +549,14 @@ static struct command_result *do_getroutes(struct command *cmd,
542549 child_fd = fork_router_child (rq , info -> dev_algo == ALGO_SINGLE_PATH ,
543550 deadline , srcnode , dstnode , info -> amount ,
544551 info -> maxfee , info -> finalcltv , info -> maxdelay ,
545- cmd -> id , cmd -> filter , & log_fd , & child_pid );
552+ info -> maxparts , cmd -> id , cmd -> filter , & log_fd , & child_pid );
546553 if (child_fd == -1 ) {
547554 err = tal_fmt (tmpctx , "failed to fork: %s" , strerror (errno ));
548555 goto fail_broken ;
549556 }
550557
551558 /* FIXME: Go async! */
552- process_child_logs (rq , log_fd );
559+ process_child_logs (cmd , log_fd );
553560 close (log_fd );
554561 json = grab_fd_str (cmd , child_fd );
555562 close (child_fd );
@@ -558,9 +565,9 @@ static struct command_result *do_getroutes(struct command *cmd,
558565 struct timerel time_delta = timemono_between (time_mono (), time_start );
559566
560567 /* log the time of computation */
561- rq_log (tmpctx , rq , LOG_DBG , "get_routes %s %" PRIu64 " ms" ,
562- WEXITSTATUS (child_status ) != 0 ? "failed after" : "completed in" ,
563- time_to_msec (time_delta ));
568+ cmd_log (tmpctx , cmd , LOG_DBG , "get_routes %s %" PRIu64 " ms" ,
569+ WEXITSTATUS (child_status ) != 0 ? "failed after" : "completed in" ,
570+ time_to_msec (time_delta ));
564571
565572 if (WIFSIGNALED (child_status )) {
566573 err = tal_fmt (tmpctx , "child died with signal %u" ,
0 commit comments