askrene: make minflow() static, and remove unused linear_flow_cost.
What changed, and why it matters
This is a routine code cleanup in Core Lightning's routing plugin. It makes two internal functions private (static) and removes one unused helper function. There is no security-relevant change: no bug is fixed, no behavior is altered, and no externally reachable interface is changed.
No action required. Treat as normal maintenance/refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit converts minflow() and single_path_flow() from external-linkage to static (file-local) in plugins/askrene/mcf.c, removes their declarations from plugins/askrene/mcf.h, deletes the unused linear_flow_cost() function, and moves the single_path_flow() doc comment from the header into the .c file. This is a pure refactoring/cleanup with no functional or security impact.
Changed components
plugins/askrene/mcf.cplugins/askrene/mcf.hInspect captured patch +28 / −86
diff --git a/plugins/askrene/mcf.c b/plugins/askrene/mcf.c
index 82418f79..c3bf28fc 100644
--- a/plugins/askrene/mcf.c
+++ b/plugins/askrene/mcf.c
@@ -528,26 +528,6 @@ static double base_fee_penalty_estimate(struct amount_msat amount)
return amount_msat_ratio(AMOUNT_MSAT(10000000), amount);
}
-struct amount_msat linear_flow_cost(const struct flow *flow,
- struct amount_msat total_amount,
- double delay_feefactor)
-{
- struct amount_msat msat_cost;
- s64 cost_ppm = 0;
- double base_fee_penalty = base_fee_penalty_estimate(total_amount);
-
- for (size_t i = 0; i < tal_count(flow->path); i++) {
- const struct half_chan *h = &flow->path[i]->half[flow->dirs[i]];
-
- cost_ppm +=
- linear_fee_cost(h->base_fee, h->proportional_fee, h->delay,
- base_fee_penalty, delay_feefactor);
- }
- if (!amount_msat_fee(&msat_cost, flow->delivers, 0, cost_ppm))
- abort();
- return msat_cost;
-}
-
static void init_linear_network(const tal_t *ctx,
const struct pay_parameters *params,
struct graph **graph, double **arc_prob_cost,
@@ -965,13 +945,13 @@ get_flow_singlepath(const tal_t *ctx, const struct pay_parameters *params,
* Check that local channels have fee costs = 0 and bounds with certainty (min=max). */
// TODO(eduardo): we should LOG_DBG the process of finding the MCF while
// adjusting the frugality factor.
-struct flow **minflow(const tal_t *ctx,
- const struct route_query *rq,
- const struct gossmap_node *source,
- const struct gossmap_node *target,
- struct amount_msat amount,
- u32 mu,
- double delay_feefactor)
+static struct flow **minflow(const tal_t *ctx,
+ const struct route_query *rq,
+ const struct gossmap_node *source,
+ const struct gossmap_node *target,
+ struct amount_msat amount,
+ u32 mu,
+ double delay_feefactor)
{
struct flow **flow_paths;
/* We allocate everything off this, and free it at the end,
@@ -1164,12 +1144,27 @@ static void init_linear_network_single_path(
}
}
-/* Similar to minflow but computes routes that have a single path. */
-struct flow **single_path_flow(const tal_t *ctx, const struct route_query *rq,
- const struct gossmap_node *source,
- const struct gossmap_node *target,
- struct amount_msat amount, u32 mu,
- double delay_feefactor)
+/**
+ * API for min cost single path.
+ * @ctx: context to allocate returned flows from
+ * @rq: the route_query we're processing (for logging)
+ * @source: the source to start from
+ * @target: the target to pay
+ * @amount: the amount we want to reach @target
+ * @mu: 0 = corresponds to only probabilities, 100 corresponds to only fee.
+ * @delay_feefactor: convert 1 block delay into msat.
+ *
+ * @delay_feefactor converts 1 block delay into msat, as if it were an additional
+ * fee. So if a CLTV delay on a node is 5 blocks, that's treated as if it
+ * were a fee of 5 * @delay_feefactor.
+ *
+ * Returns an array with one flow which deliver amount to target, or NULL.
+ */
+static struct flow **single_path_flow(const tal_t *ctx, const struct route_query *rq,
+ const struct gossmap_node *source,
+ const struct gossmap_node *target,
+ struct amount_msat amount, u32 mu,
+ double delay_feefactor)
{
struct flow **flow_paths;
/* We allocate everything off this, and free it at the end,
diff --git a/plugins/askrene/mcf.h b/plugins/askrene/mcf.h
index 7d601590..4fce70a5 100644
--- a/plugins/askrene/mcf.h
+++ b/plugins/askrene/mcf.h
@@ -8,59 +8,6 @@
struct route_query;
-/**
- * optimal_payment_flow - API for min cost flow function(s).
- * @ctx: context to allocate returned flows from
- * @rq: the route_query we're processing (for logging)
- * @source: the source to start from
- * @target: the target to pay
- * @amount: the amount we want to reach @target
- * @mu: 0 = corresponds to only probabilities, 100 corresponds to only fee.
- * @delay_feefactor: convert 1 block delay into msat.
- * @single_part: don't do MCF at all, just create a single flow.
- *
- * @delay_feefactor converts 1 block delay into msat, as if it were an additional
- * fee. So if a CLTV delay on a node is 5 blocks, that's treated as if it
- * were a fee of 5 * @delay_feefactor.
- *
- * Return a series of subflows which deliver amount to target, or NULL.
- */
-struct flow **minflow(const tal_t *ctx,
- const struct route_query *rq,
- const struct gossmap_node *source,
- const struct gossmap_node *target,
- struct amount_msat amount,
- u32 mu,
- double delay_feefactor);
-
-/**
- * API for min cost single path.
- * @ctx: context to allocate returned flows from
- * @rq: the route_query we're processing (for logging)
- * @source: the source to start from
- * @target: the target to pay
- * @amount: the amount we want to reach @target
- * @mu: 0 = corresponds to only probabilities, 100 corresponds to only fee.
- * @delay_feefactor: convert 1 block delay into msat.
- *
- * @delay_feefactor converts 1 block delay into msat, as if it were an additional
- * fee. So if a CLTV delay on a node is 5 blocks, that's treated as if it
- * were a fee of 5 * @delay_feefactor.
- *
- * Returns an array with one flow which deliver amount to target, or NULL.
- */
-struct flow **single_path_flow(const tal_t *ctx, const struct route_query *rq,
- const struct gossmap_node *source,
- const struct gossmap_node *target,
- struct amount_msat amount, u32 mu,
- double delay_feefactor);
-
-/* To sanity check: this is the approximation mcf uses for the cost
- * of each channel. */
-struct amount_msat linear_flow_cost(const struct flow *flow,
- struct amount_msat total_amount,
- double delay_feefactor);
-
/* A wrapper to the min. cost flow solver that actually takes into consideration
* the extra msats per channel needed to pay for fees. */
const char *default_routes(const tal_t *ctx, struct route_query *rq,
Why this scored 15/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.