|
18 | 18 | #include <errno.h>
|
19 | 19 | #include <math.h>
|
20 | 20 | #include <plugins/askrene/askrene.h>
|
21 |
| -#include <plugins/askrene/explain_failure.h> |
22 | 21 | #include <plugins/askrene/flow.h>
|
23 | 22 | #include <plugins/askrene/layer.h>
|
24 | 23 | #include <plugins/askrene/mcf.h>
|
25 |
| -#include <plugins/askrene/refine.h> |
26 | 24 | #include <plugins/askrene/reserve.h>
|
27 | 25 |
|
28 | 26 | /* "spendable" for a channel assumes a single HTLC: for additional HTLCs,
|
@@ -332,22 +330,6 @@ const char *fmt_flow_full(const tal_t *ctx,
|
332 | 330 | return str;
|
333 | 331 | }
|
334 | 332 |
|
335 |
| -static struct amount_msat linear_flows_cost(struct flow **flows, |
336 |
| - struct amount_msat total_amount, |
337 |
| - double delay_feefactor) |
338 |
| -{ |
339 |
| - struct amount_msat total = AMOUNT_MSAT(0); |
340 |
| - |
341 |
| - for (size_t i = 0; i < tal_count(flows); i++) { |
342 |
| - if (!amount_msat_accumulate(&total, |
343 |
| - linear_flow_cost(flows[i], |
344 |
| - total_amount, |
345 |
| - delay_feefactor))) |
346 |
| - abort(); |
347 |
| - } |
348 |
| - return total; |
349 |
| -} |
350 |
| - |
351 | 333 | static u64 time_delta_ms(struct timerel t)
|
352 | 334 | {
|
353 | 335 | u64 msec = t.ts.tv_sec * 1000 + t.ts.tv_nsec / 1000000;
|
@@ -376,8 +358,6 @@ static const char *get_routes(const tal_t *ctx,
|
376 | 358 | struct route_query *rq = tal(ctx, struct route_query);
|
377 | 359 | struct flow **flows;
|
378 | 360 | const struct gossmap_node *srcnode, *dstnode;
|
379 |
| - double delay_feefactor; |
380 |
| - u32 mu; |
381 | 361 | const char *ret;
|
382 | 362 | struct timerel time_delta;
|
383 | 363 | struct timemono time_start = time_mono();
|
@@ -451,109 +431,15 @@ static const char *get_routes(const tal_t *ctx,
|
451 | 431 | goto fail;
|
452 | 432 | }
|
453 | 433 |
|
454 |
| - delay_feefactor = 1.0/1000000; |
455 |
| - |
456 |
| - /* First up, don't care about fees (well, just enough to tiebreak!) */ |
457 |
| - mu = 1; |
458 |
| - flows = minflow(rq, rq, srcnode, dstnode, amount, |
459 |
| - mu, delay_feefactor, single_path); |
460 |
| - if (!flows) { |
461 |
| - ret = explain_failure(ctx, rq, srcnode, dstnode, amount); |
462 |
| - goto fail; |
463 |
| - } |
464 |
| - |
465 |
| - /* Too much delay? */ |
466 |
| - while (finalcltv + flows_worst_delay(flows) > maxdelay) { |
467 |
| - delay_feefactor *= 2; |
468 |
| - rq_log(tmpctx, rq, LOG_UNUSUAL, |
469 |
| - "The worst flow delay is %"PRIu64" (> %i), retrying with delay_feefactor %f...", |
470 |
| - flows_worst_delay(flows), maxdelay - finalcltv, delay_feefactor); |
471 |
| - flows = minflow(rq, rq, srcnode, dstnode, amount, |
472 |
| - mu, delay_feefactor, single_path); |
473 |
| - if (!flows || delay_feefactor > 10) { |
474 |
| - ret = rq_log(ctx, rq, LOG_UNUSUAL, |
475 |
| - "Could not find route without excessive delays"); |
476 |
| - goto fail; |
477 |
| - } |
478 |
| - } |
479 |
| - |
480 |
| - /* Too expensive? */ |
481 |
| -too_expensive: |
482 |
| - while (amount_msat_greater(flowset_fee(rq->plugin, flows), maxfee)) { |
483 |
| - struct flow **new_flows; |
484 |
| - |
485 |
| - if (mu == 1) |
486 |
| - mu = 10; |
487 |
| - else |
488 |
| - mu += 10; |
489 |
| - rq_log(tmpctx, rq, LOG_UNUSUAL, |
490 |
| - "The flows had a fee of %s, greater than max of %s, retrying with mu of %u%%...", |
491 |
| - fmt_amount_msat(tmpctx, flowset_fee(rq->plugin, flows)), |
492 |
| - fmt_amount_msat(tmpctx, maxfee), |
493 |
| - mu); |
494 |
| - new_flows = minflow(rq, rq, srcnode, dstnode, amount, |
495 |
| - mu > 100 ? 100 : mu, delay_feefactor, single_path); |
496 |
| - if (!flows || mu >= 100) { |
497 |
| - ret = rq_log(ctx, rq, LOG_UNUSUAL, |
498 |
| - "Could not find route without excessive cost"); |
499 |
| - goto fail; |
500 |
| - } |
501 |
| - |
502 |
| - /* This is possible, because MCF's linear fees are not the same. */ |
503 |
| - if (amount_msat_greater(flowset_fee(rq->plugin, new_flows), |
504 |
| - flowset_fee(rq->plugin, flows))) { |
505 |
| - struct amount_msat old_cost = linear_flows_cost(flows, amount, delay_feefactor); |
506 |
| - struct amount_msat new_cost = linear_flows_cost(new_flows, amount, delay_feefactor); |
507 |
| - if (amount_msat_greater_eq(new_cost, old_cost)) { |
508 |
| - rq_log(tmpctx, rq, LOG_BROKEN, "Old flows cost %s:", |
509 |
| - fmt_amount_msat(tmpctx, old_cost)); |
510 |
| - for (size_t i = 0; i < tal_count(flows); i++) { |
511 |
| - rq_log(tmpctx, rq, LOG_BROKEN, |
512 |
| - "Flow %zu/%zu: %s (linear cost %s)", i, tal_count(flows), |
513 |
| - fmt_flow_full(tmpctx, rq, flows[i]), |
514 |
| - fmt_amount_msat(tmpctx, linear_flow_cost(flows[i], |
515 |
| - amount, |
516 |
| - delay_feefactor))); |
517 |
| - } |
518 |
| - rq_log(tmpctx, rq, LOG_BROKEN, "Old flows cost %s:", |
519 |
| - fmt_amount_msat(tmpctx, new_cost)); |
520 |
| - for (size_t i = 0; i < tal_count(new_flows); i++) { |
521 |
| - rq_log(tmpctx, rq, LOG_BROKEN, |
522 |
| - "Flow %zu/%zu: %s (linear cost %s)", i, tal_count(new_flows), |
523 |
| - fmt_flow_full(tmpctx, rq, new_flows[i]), |
524 |
| - fmt_amount_msat(tmpctx, linear_flow_cost(new_flows[i], |
525 |
| - amount, |
526 |
| - delay_feefactor))); |
527 |
| - } |
528 |
| - } |
529 |
| - } |
530 |
| - tal_free(flows); |
531 |
| - flows = new_flows; |
532 |
| - } |
533 |
| - |
534 |
| - if (finalcltv + flows_worst_delay(flows) > maxdelay) { |
535 |
| - ret = rq_log(ctx, rq, LOG_UNUSUAL, |
536 |
| - "Could not find route without excessive cost or delays"); |
537 |
| - goto fail; |
538 |
| - } |
539 |
| - |
540 |
| - /* The above did not take into account the extra funds to pay |
541 |
| - * fees, so we try to adjust now. We could re-run MCF if this |
542 |
| - * fails, but failure basically never happens where payment is |
543 |
| - * still possible */ |
544 |
| - ret = refine_with_fees_and_limits(ctx, rq, amount, &flows, probability); |
545 |
| - if (ret) |
| 434 | + /* FIXME: single_path should signal a change in algorithm. */ |
| 435 | + ret = default_routes(rq, rq, srcnode, dstnode, amount, single_path, |
| 436 | + maxfee, finalcltv, maxdelay, &flows, probability); |
| 437 | + if (ret) { |
546 | 438 | goto fail;
|
547 |
| - |
548 |
| - /* Again, a tiny corner case: refine step can make us exceed maxfee */ |
549 |
| - if (amount_msat_greater(flowset_fee(rq->plugin, flows), maxfee)) { |
550 |
| - rq_log(tmpctx, rq, LOG_UNUSUAL, |
551 |
| - "After final refinement, fee was excessive: retrying"); |
552 |
| - goto too_expensive; |
553 | 439 | }
|
554 |
| - |
555 |
| - rq_log(tmpctx, rq, LOG_DBG, "Final answer has %zu flows with mu=%u", |
556 |
| - tal_count(flows), mu); |
| 440 | + assert(tal_count(flows) > 0); |
| 441 | + rq_log(tmpctx, rq, LOG_DBG, "Final answer has %zu flows", |
| 442 | + tal_count(flows)); |
557 | 443 |
|
558 | 444 | /* Convert back into routes, with delay and other information fixed */
|
559 | 445 | *routes = tal_arr(ctx, struct route *, tal_count(flows));
|
|
0 commit comments