1919#include <errno.h>
2020#include <math.h>
2121#include <plugins/askrene/askrene.h>
22- #include <plugins/askrene/explain_failure.h>
2322#include <plugins/askrene/flow.h>
2423#include <plugins/askrene/layer.h>
2524#include <plugins/askrene/mcf.h>
26- #include <plugins/askrene/refine.h>
2725#include <plugins/askrene/reserve.h>
2826
2927/* "spendable" for a channel assumes a single HTLC: for additional HTLCs,
@@ -333,22 +331,6 @@ const char *fmt_flow_full(const tal_t *ctx,
333331 return str ;
334332}
335333
336- static struct amount_msat linear_flows_cost (struct flow * * flows ,
337- struct amount_msat total_amount ,
338- double delay_feefactor )
339- {
340- struct amount_msat total = AMOUNT_MSAT (0 );
341-
342- for (size_t i = 0 ; i < tal_count (flows ); i ++ ) {
343- if (!amount_msat_accumulate (& total ,
344- linear_flow_cost (flows [i ],
345- total_amount ,
346- delay_feefactor )))
347- abort ();
348- }
349- return total ;
350- }
351-
352334/* Returns an error message, or sets *routes */
353335static const char * get_routes (const tal_t * ctx ,
354336 struct command * cmd ,
@@ -371,8 +353,6 @@ static const char *get_routes(const tal_t *ctx,
371353 struct route_query * rq = tal (ctx , struct route_query );
372354 struct flow * * flows ;
373355 const struct gossmap_node * srcnode , * dstnode ;
374- double delay_feefactor ;
375- u32 mu ;
376356 const char * ret ;
377357 struct timerel time_delta ;
378358 struct timemono time_start = time_mono ();
@@ -446,109 +426,15 @@ static const char *get_routes(const tal_t *ctx,
446426 goto fail ;
447427 }
448428
449- delay_feefactor = 1.0 /1000000 ;
450-
451- /* First up, don't care about fees (well, just enough to tiebreak!) */
452- mu = 1 ;
453- flows = minflow (rq , rq , srcnode , dstnode , amount ,
454- mu , delay_feefactor , single_path );
455- if (!flows ) {
456- ret = explain_failure (ctx , rq , srcnode , dstnode , amount );
457- goto fail ;
458- }
459-
460- /* Too much delay? */
461- while (finalcltv + flows_worst_delay (flows ) > maxdelay ) {
462- delay_feefactor *= 2 ;
463- rq_log (tmpctx , rq , LOG_UNUSUAL ,
464- "The worst flow delay is %" PRIu64 " (> %i), retrying with delay_feefactor %f..." ,
465- flows_worst_delay (flows ), maxdelay - finalcltv , delay_feefactor );
466- flows = minflow (rq , rq , srcnode , dstnode , amount ,
467- mu , delay_feefactor , single_path );
468- if (!flows || delay_feefactor > 10 ) {
469- ret = rq_log (ctx , rq , LOG_UNUSUAL ,
470- "Could not find route without excessive delays" );
471- goto fail ;
472- }
473- }
474-
475- /* Too expensive? */
476- too_expensive :
477- while (amount_msat_greater (flowset_fee (rq -> plugin , flows ), maxfee )) {
478- struct flow * * new_flows ;
479-
480- if (mu == 1 )
481- mu = 10 ;
482- else
483- mu += 10 ;
484- rq_log (tmpctx , rq , LOG_UNUSUAL ,
485- "The flows had a fee of %s, greater than max of %s, retrying with mu of %u%%..." ,
486- fmt_amount_msat (tmpctx , flowset_fee (rq -> plugin , flows )),
487- fmt_amount_msat (tmpctx , maxfee ),
488- mu );
489- new_flows = minflow (rq , rq , srcnode , dstnode , amount ,
490- mu > 100 ? 100 : mu , delay_feefactor , single_path );
491- if (!flows || mu >= 100 ) {
492- ret = rq_log (ctx , rq , LOG_UNUSUAL ,
493- "Could not find route without excessive cost" );
494- goto fail ;
495- }
496-
497- /* This is possible, because MCF's linear fees are not the same. */
498- if (amount_msat_greater (flowset_fee (rq -> plugin , new_flows ),
499- flowset_fee (rq -> plugin , flows ))) {
500- struct amount_msat old_cost = linear_flows_cost (flows , amount , delay_feefactor );
501- struct amount_msat new_cost = linear_flows_cost (new_flows , amount , delay_feefactor );
502- if (amount_msat_greater_eq (new_cost , old_cost )) {
503- rq_log (tmpctx , rq , LOG_BROKEN , "Old flows cost %s:" ,
504- fmt_amount_msat (tmpctx , old_cost ));
505- for (size_t i = 0 ; i < tal_count (flows ); i ++ ) {
506- rq_log (tmpctx , rq , LOG_BROKEN ,
507- "Flow %zu/%zu: %s (linear cost %s)" , i , tal_count (flows ),
508- fmt_flow_full (tmpctx , rq , flows [i ]),
509- fmt_amount_msat (tmpctx , linear_flow_cost (flows [i ],
510- amount ,
511- delay_feefactor )));
512- }
513- rq_log (tmpctx , rq , LOG_BROKEN , "Old flows cost %s:" ,
514- fmt_amount_msat (tmpctx , new_cost ));
515- for (size_t i = 0 ; i < tal_count (new_flows ); i ++ ) {
516- rq_log (tmpctx , rq , LOG_BROKEN ,
517- "Flow %zu/%zu: %s (linear cost %s)" , i , tal_count (new_flows ),
518- fmt_flow_full (tmpctx , rq , new_flows [i ]),
519- fmt_amount_msat (tmpctx , linear_flow_cost (new_flows [i ],
520- amount ,
521- delay_feefactor )));
522- }
523- }
524- }
525- tal_free (flows );
526- flows = new_flows ;
527- }
528-
529- if (finalcltv + flows_worst_delay (flows ) > maxdelay ) {
530- ret = rq_log (ctx , rq , LOG_UNUSUAL ,
531- "Could not find route without excessive cost or delays" );
532- goto fail ;
533- }
534-
535- /* The above did not take into account the extra funds to pay
536- * fees, so we try to adjust now. We could re-run MCF if this
537- * fails, but failure basically never happens where payment is
538- * still possible */
539- ret = refine_with_fees_and_limits (ctx , rq , amount , & flows , probability );
540- if (ret )
429+ /* FIXME: single_path should signal a change in algorithm. */
430+ ret = default_routes (rq , rq , srcnode , dstnode , amount , single_path ,
431+ maxfee , finalcltv , maxdelay , & flows , probability );
432+ if (ret ) {
541433 goto fail ;
542-
543- /* Again, a tiny corner case: refine step can make us exceed maxfee */
544- if (amount_msat_greater (flowset_fee (rq -> plugin , flows ), maxfee )) {
545- rq_log (tmpctx , rq , LOG_UNUSUAL ,
546- "After final refinement, fee was excessive: retrying" );
547- goto too_expensive ;
548434 }
549-
550- rq_log (tmpctx , rq , LOG_DBG , "Final answer has %zu flows with mu=%u " ,
551- tal_count (flows ), mu );
435+ assert ( tal_count ( flows ) > 0 );
436+ rq_log (tmpctx , rq , LOG_DBG , "Final answer has %zu flows" ,
437+ tal_count (flows ));
552438
553439 /* Convert back into routes, with delay and other information fixed */
554440 * routes = tal_arr (ctx , struct route * , tal_count (flows ));
0 commit comments