Skip to content

Commit 31d28ba

Browse files
committed
askrene: remove max_deliverable cache from increase_flows.
Make it calculate on demand. This will be useful when we call it from elsewhere. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent e120202 commit 31d28ba

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

plugins/askrene/refine.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,11 @@ static struct amount_msat remove_excess(struct flow **flows,
389389
* flow beyond the tolerance fraction. It doesn't increase any flow above its
390390
* max_deliverable value.
391391
* Returns the total delivery amount. */
392-
static struct amount_msat increase_flows(struct flow **flows,
392+
static struct amount_msat increase_flows(const struct route_query *rq,
393+
struct flow **flows,
393394
size_t **flows_index,
394395
struct amount_msat deliver,
395-
double tolerance,
396-
struct amount_msat *max_deliverable)
396+
double tolerance)
397397
{
398398
if (tal_count(flows) == 0)
399399
return AMOUNT_MSAT(0);
@@ -422,7 +422,7 @@ static struct amount_msat increase_flows(struct flow **flows,
422422
can_add = amount_msat_min(can_add, amt);
423423

424424
/* no more than max_deliverable */
425-
if (!amount_msat_sub(&amt, max_deliverable[index],
425+
if (!amount_msat_sub(&amt, flow_max_deliverable(rq, flow, NULL),
426426
flow->delivers))
427427
continue;
428428
else
@@ -461,19 +461,15 @@ const char *refine_flows(const tal_t *ctx, struct route_query *rq,
461461
{
462462
const tal_t *working_ctx = tal(ctx, tal_t);
463463
const char *error_message = NULL;
464-
struct amount_msat *max_deliverable;
465464
struct amount_msat *min_deliverable;
466465
size_t *flows_index;
467466

468-
max_deliverable = tal_arrz(working_ctx, struct amount_msat,
469-
tal_count(*flows));
470467
min_deliverable = tal_arrz(working_ctx, struct amount_msat,
471468
tal_count(*flows));
472469
flows_index = tal_arrz(working_ctx, size_t, tal_count(*flows));
473470
for (size_t i = 0; i < tal_count(*flows); i++) {
474471
// FIXME: does flow_max_deliverable work for a single
475472
// channel with 0 fees?
476-
max_deliverable[i] = flow_max_deliverable(rq, (*flows)[i], bottleneck_idx);
477473
min_deliverable[i] = flow_min_deliverable(rq, (*flows)[i]);
478474
/* We use an array of indexes to keep track of the order
479475
* of the flows. Likewise flows can be removed by simply
@@ -485,15 +481,14 @@ const char *refine_flows(const tal_t *ctx, struct route_query *rq,
485481
for (size_t i = 0; i < tal_count(flows_index); i++) {
486482
(*flows)[flows_index[i]]->delivers =
487483
amount_msat_min((*flows)[flows_index[i]]->delivers,
488-
max_deliverable[flows_index[i]]);
484+
flow_max_deliverable(rq, (*flows)[flows_index[i]], bottleneck_idx));
489485
}
490486

491487
/* remove excess from MCF granularity if any */
492488
remove_excess(*flows, &flows_index, deliver);
493489

494490
/* increase flows if necessary to meet the target */
495-
increase_flows(*flows, &flows_index, deliver, /* tolerance = */ 0.02,
496-
max_deliverable);
491+
increase_flows(rq, *flows, &flows_index, deliver, /* tolerance = */ 0.02);
497492

498493
/* detect htlc_min violations */
499494
for (size_t i = 0; i < tal_count(flows_index);) {

0 commit comments

Comments
 (0)