Skip to content

Commit 2735673

Browse files
committed
askrene: make increase_flows() use the raw flows array.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent e3dfc02 commit 2735673

File tree

1 file changed

+5
-30
lines changed

1 file changed

+5
-30
lines changed

plugins/askrene/refine.c

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,6 @@ enum why_capped {
168168
};
169169

170170
/* Reverse order: bigger first */
171-
static int revcmp_flows(const size_t *a, const size_t *b, struct flow **flows)
172-
{
173-
if (amount_msat_eq(flows[*a]->delivers, flows[*b]->delivers))
174-
return 0;
175-
if (amount_msat_greater(flows[*a]->delivers, flows[*b]->delivers))
176-
return -1;
177-
return 1;
178-
}
179-
180171
static int revcmp_flows_noidx(struct flow *const *a, struct flow *const *b, void *unused)
181172
{
182173
if (amount_msat_eq((*a)->delivers, (*b)->delivers))
@@ -317,17 +308,6 @@ remove_htlc_min_violations(const tal_t *ctx, struct route_query *rq,
317308
return error_message;
318309
}
319310

320-
static struct amount_msat sum_all_deliver(struct flow **flows,
321-
size_t *flows_index)
322-
{
323-
struct amount_msat all_deliver = AMOUNT_MSAT(0);
324-
for (size_t i = 0; i < tal_count(flows_index); i++) {
325-
if (!amount_msat_accumulate(&all_deliver,
326-
flows[flows_index[i]]->delivers))
327-
abort();
328-
}
329-
return all_deliver;
330-
}
331311

332312
static struct amount_msat sum_all_deliver_noidx(struct flow **flows)
333313
{
@@ -409,28 +389,26 @@ static struct amount_msat remove_excess(struct flow ***flows,
409389
* Returns the total delivery amount. */
410390
static struct amount_msat increase_flows(const struct route_query *rq,
411391
struct flow **flows,
412-
size_t **flows_index,
413392
struct amount_msat deliver,
414393
double tolerance)
415394
{
416395
if (tal_count(flows) == 0)
417396
return AMOUNT_MSAT(0);
418397

419398
struct amount_msat all_deliver, defect;
420-
all_deliver = sum_all_deliver(flows, *flows_index);
399+
all_deliver = sum_all_deliver_noidx(flows);
421400

422401
/* early exit: target is already met */
423402
if (!amount_msat_sub(&defect, deliver, all_deliver) ||
424403
amount_msat_is_zero(defect))
425404
return all_deliver;
426405

427-
asort(*flows_index, tal_count(*flows_index), revcmp_flows, flows);
406+
asort(flows, tal_count(flows), revcmp_flows_noidx, NULL);
428407

429408
all_deliver = AMOUNT_MSAT(0);
430409
for (size_t i = 0;
431-
i < tal_count(*flows_index) && !amount_msat_is_zero(defect); i++) {
432-
const size_t index = (*flows_index)[i];
433-
struct flow *flow = flows[index];
410+
i < tal_count(flows) && !amount_msat_is_zero(defect); i++) {
411+
struct flow *flow = flows[i];
434412
struct amount_msat can_add = defect, amt;
435413

436414
/* no more than tolerance */
@@ -506,10 +484,7 @@ const char *refine_flows(const tal_t *ctx, struct route_query *rq,
506484
}
507485

508486
/* increase flows if necessary to meet the target */
509-
increase_flows(rq, *flows, &flows_index, deliver, /* tolerance = */ 0.02);
510-
511-
/* finally write the remaining flows */
512-
write_selected_flows(working_ctx, flows_index, flows);
487+
increase_flows(rq, *flows, deliver, /* tolerance = */ 0.02);
513488

514489
/* detect htlc_min violations */
515490
for (size_t i = 0; i < tal_count(*flows);) {

0 commit comments

Comments
 (0)