Skip to content

Commit e3dfc02

Browse files
committed
askrene: remove indexes from refine_flows except for increase_flows()
This removes the index array from code after increase_flows()m, so we use the flows array directly. The next step will be to make increase_flows() use the flows array, and remove the index array indirection entirely. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 565a92e commit e3dfc02

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

plugins/askrene/refine.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -508,33 +508,32 @@ const char *refine_flows(const tal_t *ctx, struct route_query *rq,
508508
/* increase flows if necessary to meet the target */
509509
increase_flows(rq, *flows, &flows_index, deliver, /* tolerance = */ 0.02);
510510

511+
/* finally write the remaining flows */
512+
write_selected_flows(working_ctx, flows_index, flows);
513+
511514
/* detect htlc_min violations */
512-
for (size_t i = 0; i < tal_count(flows_index);) {
513-
size_t k = flows_index[i];
514-
if (amount_msat_greater_eq((*flows)[k]->delivers,
515-
min_deliverable[k])) {
515+
for (size_t i = 0; i < tal_count(*flows);) {
516+
if (amount_msat_greater_eq((*flows)[i]->delivers,
517+
flow_min_deliverable(rq, (*flows)[i]))) {
516518
i++;
517519
continue;
518520
}
519-
/* htlc_min is not met for this flow */
520-
tal_arr_remove(&flows_index, i);
521521
error_message = remove_htlc_min_violations(
522-
ctx, rq, (*flows)[k]);
522+
ctx, rq, (*flows)[i]);
523523
if (error_message)
524524
goto fail;
525+
/* htlc_min is not met for this flow */
526+
tal_arr_remove(flows, i);
525527
}
526528

527529
/* remove 0 amount flows if any */
528-
asort(flows_index, tal_count(flows_index), revcmp_flows, *flows);
529-
for (int i = tal_count(flows_index) - 1; i >= 0; i--) {
530-
if (!amount_msat_is_zero((*flows)[flows_index[i]]->delivers))
530+
asort(*flows, tal_count(*flows), revcmp_flows_noidx, NULL);
531+
for (int i = tal_count(*flows) - 1; i >= 0; i--) {
532+
if (!amount_msat_is_zero((*flows)[i]->delivers))
531533
break;
532-
tal_arr_remove(&flows_index, i);
534+
tal_arr_remove(flows, i);
533535
}
534536

535-
/* finally write the remaining flows */
536-
write_selected_flows(working_ctx, flows_index, flows);
537-
538537
tal_free(working_ctx);
539538
return NULL;
540539

0 commit comments

Comments
 (0)