MCPcopy Create free account
hub / github.com/ElementsProject/lightning / refine_flows

Function refine_flows

plugins/askrene/child/refine.c:535–631  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

533}
534
535const char *refine_flows(const tal_t *ctx, struct route_query *rq,
536 struct amount_msat deliver, struct flow ***flows)
537{
538 const tal_t *working_ctx = tal(ctx, tal_t);
539 const char *error_message = NULL;
540 struct amount_msat *min_deliverable;
541 size_t *flows_index;
542
543 /* do not deliver more than HTLC_MAX allow us */
544 for (size_t i = 0; i < tal_count(*flows);) {
545 struct amount_msat try_deliver = (*flows)[i]->delivers;
546 struct amount_msat deliverable =
547 flow_max_deliverable(rq, (*flows)[i]);
548
549 /* We don't expect to have a zero flow amount here. Just report
550 * it. */
551 if (amount_msat_is_zero(try_deliver)) {
552 child_log(tmpctx, LOG_UNUSUAL,
553 "Tried to refine a flow with zero amount: %s",
554 fmt_flow_full(tmpctx, rq, (*flows)[i]));
555 del_flow_from_arr(flows, i);
556 continue;
557 }
558
559 /* A path with a very small deliverable amount is not worth the
560 * effort, and we don't want either a path that for fees and
561 * HTLC max constraints removes too much from the actual
562 * delivery amount. In theory the MCF already has partitioned
563 * the payment in different paths. The refinement step is not
564 * expected to change the flow by much. */
565 if (amount_msat_less(deliverable, AMOUNT_MSAT(1000)) ||
566 amount_msat_ratio(deliverable, try_deliver) < 0.2) {
567 error_message = remove_bottleneck(ctx, rq, (*flows)[i]);
568 if (error_message)
569 goto fail;
570 del_flow_from_arr(flows, i);
571 continue;
572 }
573
574 (*flows)[i]->delivers =
575 amount_msat_min(try_deliver, deliverable);
576 i++;
577 }
578 if (tal_count(*flows) == 0) {
579 /* No flows left to complete the next steps, early exit. */
580 goto fail;
581 }
582
583 /* remove excess from MCF granularity if any */
584 remove_excess(flows, deliver);
585
586 min_deliverable = tal_arrz(working_ctx, struct amount_msat,
587 tal_count(*flows));
588 flows_index = tal_arrz(working_ctx, size_t, tal_count(*flows));
589 for (size_t i = 0; i < tal_count(*flows); i++) {
590 // FIXME: does flow_max_deliverable work for a single
591 // channel with 0 fees?
592 min_deliverable[i] = flow_min_deliverable(rq, (*flows)[i]);

Callers 1

linear_routesFunction · 0.85

Calls 15

flow_max_deliverableFunction · 0.85
amount_msat_is_zeroFunction · 0.85
child_logFunction · 0.85
fmt_flow_fullFunction · 0.85
del_flow_from_arrFunction · 0.85
amount_msat_ratioFunction · 0.85
remove_bottleneckFunction · 0.85
amount_msat_minFunction · 0.85
remove_excessFunction · 0.85
flow_min_deliverableFunction · 0.85
increase_flowsFunction · 0.85
amount_msat_greater_eqFunction · 0.85

Tested by

no test coverage detected