askrene: remove indexes from refine_flows except for increase_flows()
What changed, and why it matters
This is a small internal code cleanup in the askrene routing plugin. It removes an unnecessary intermediate index array in the flow-refinement logic, making the code operate directly on the flows array. There is no indication this fixes a security bug or changes externally observable behavior.
No security action required. Treat as normal code-maintenance review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors refine_flows() in plugins/askrene/refine.c. Previously, after increase_flows(), the code kept a flows_index array and iterated over it to check htlc_min violations and remove zero-amount flows, then called write_selected_flows() to copy selected entries back to flows. The patch moves write_selected_flows() earlier (right after increase_flows()), then iterates directly over flows for the remaining cleanup steps, removing entries from *flows itself. This is a structural simplification and appears functionally equivalent, with no security-relevant change evident from the diff.
Changed components
plugins/askrene/refine.cInspect captured patch +13 / −14
diff --git a/plugins/askrene/refine.c b/plugins/askrene/refine.c
index efe9c744..0072f366 100644
--- a/plugins/askrene/refine.c
+++ b/plugins/askrene/refine.c
@@ -508,33 +508,32 @@ const char *refine_flows(const tal_t *ctx, struct route_query *rq,
/* increase flows if necessary to meet the target */
increase_flows(rq, *flows, &flows_index, deliver, /* tolerance = */ 0.02);
+ /* finally write the remaining flows */
+ write_selected_flows(working_ctx, flows_index, flows);
+
/* detect htlc_min violations */
- for (size_t i = 0; i < tal_count(flows_index);) {
- size_t k = flows_index[i];
- if (amount_msat_greater_eq((*flows)[k]->delivers,
- min_deliverable[k])) {
+ for (size_t i = 0; i < tal_count(*flows);) {
+ if (amount_msat_greater_eq((*flows)[i]->delivers,
+ flow_min_deliverable(rq, (*flows)[i]))) {
i++;
continue;
}
- /* htlc_min is not met for this flow */
- tal_arr_remove(&flows_index, i);
error_message = remove_htlc_min_violations(
- ctx, rq, (*flows)[k]);
+ ctx, rq, (*flows)[i]);
if (error_message)
goto fail;
+ /* htlc_min is not met for this flow */
+ tal_arr_remove(flows, i);
}
/* remove 0 amount flows if any */
- asort(flows_index, tal_count(flows_index), revcmp_flows, *flows);
- for (int i = tal_count(flows_index) - 1; i >= 0; i--) {
- if (!amount_msat_is_zero((*flows)[flows_index[i]]->delivers))
+ asort(*flows, tal_count(*flows), revcmp_flows_noidx, NULL);
+ for (int i = tal_count(*flows) - 1; i >= 0; i--) {
+ if (!amount_msat_is_zero((*flows)[i]->delivers))
break;
- tal_arr_remove(&flows_index, i);
+ tal_arr_remove(flows, i);
}
- /* finally write the remaining flows */
- write_selected_flows(working_ctx, flows_index, flows);
-
tal_free(working_ctx);
return NULL;
Why this scored 11/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.