askrene: move routines only accessed by the child process into child/.

We want to make it clear when future generations edit the code, which
routines are called in the child (i.e. all the routing), and which in
the parent.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2026-02-16 17:29:33 +10:30
parent da2f77767c
commit 8775b62871
28 changed files with 74 additions and 82 deletions

View File

@@ -1,32 +1,22 @@
PLUGIN_ASKRENE_SRC := \
PLUGIN_ASKRENE_PARENT_SRC := \
plugins/askrene/askrene.c \
plugins/askrene/datastore_wire.c \
plugins/askrene/layer.c \
plugins/askrene/reserve.c \
plugins/askrene/mcf.c \
plugins/askrene/dijkstra.c \
plugins/askrene/flow.c \
plugins/askrene/refine.c \
plugins/askrene/explain_failure.c \
plugins/askrene/graph.c \
plugins/askrene/priorityqueue.c \
plugins/askrene/algorithm.c \
PLUGIN_ASKRENE_CHILD_SRC := \
plugins/askrene/child/mcf.c \
plugins/askrene/child/dijkstra.c \
plugins/askrene/child/flow.c \
plugins/askrene/child/refine.c \
plugins/askrene/child/explain_failure.c \
plugins/askrene/child/graph.c \
plugins/askrene/child/priorityqueue.c \
plugins/askrene/child/algorithm.c \
plugins/askrene/child/child_log.c \
PLUGIN_ASKRENE_HEADER := \
plugins/askrene/askrene.h \
plugins/askrene/datastore_wire.h \
plugins/askrene/layer.h \
plugins/askrene/reserve.h \
plugins/askrene/mcf.h \
plugins/askrene/dijkstra.h \
plugins/askrene/flow.h \
plugins/askrene/refine.h \
plugins/askrene/explain_failure.h \
plugins/askrene/graph.h \
plugins/askrene/priorityqueue.h \
plugins/askrene/algorithm.h \
plugins/askrene/child/child_log.h \
PLUGIN_ASKRENE_SRC := $(PLUGIN_ASKRENE_PARENT_SRC) $(PLUGIN_ASKRENE_CHILD_SRC)
PLUGIN_ASKRENE_HEADER := $(PLUGIN_ASKRENE_SRC:.c=.h)
PLUGIN_ASKRENE_OBJS := $(PLUGIN_ASKRENE_SRC:.c=.o)

View File

@@ -26,9 +26,9 @@
#include <math.h>
#include <plugins/askrene/askrene.h>
#include <plugins/askrene/child/child_log.h>
#include <plugins/askrene/flow.h>
#include <plugins/askrene/child/flow.h>
#include <plugins/askrene/child/mcf.h>
#include <plugins/askrene/layer.h>
#include <plugins/askrene/mcf.h>
#include <plugins/askrene/reserve.h>
#include <sys/wait.h>
#include <unistd.h>

View File

@@ -1,8 +1,8 @@
#include "config.h"
#include <ccan/bitmap/bitmap.h>
#include <ccan/tal/tal.h>
#include <plugins/askrene/algorithm.h>
#include <plugins/askrene/priorityqueue.h>
#include <plugins/askrene/child/algorithm.h>
#include <plugins/askrene/child/priorityqueue.h>
static const s64 INFINITE = INT64_MAX;

View File

@@ -1,11 +1,11 @@
#ifndef LIGHTNING_PLUGINS_ASKRENE_ALGORITHM_H
#define LIGHTNING_PLUGINS_ASKRENE_ALGORITHM_H
#ifndef LIGHTNING_PLUGINS_ASKRENE_CHILD_ALGORITHM_H
#define LIGHTNING_PLUGINS_ASKRENE_CHILD_ALGORITHM_H
/* Implementation of network algorithms: shortests path, minimum cost flow, etc.
*/
#include "config.h"
#include <plugins/askrene/graph.h>
#include <plugins/askrene/child/graph.h>
/* Search any path from source to destination using Breadth First Search.
*
@@ -176,4 +176,4 @@ bool mcf_refinement(const tal_t *ctx,
const s64 *cost,
s64 *potential);
#endif /* LIGHTNING_PLUGINS_ASKRENE_ALGORITHM_H */
#endif /* LIGHTNING_PLUGINS_ASKRENE_CHILD_ALGORITHM_H */

View File

@@ -1,6 +1,6 @@
#define NDEBUG 1
#include "config.h"
#include <plugins/askrene/dijkstra.h>
#include <plugins/askrene/child/dijkstra.h>
/* In the heap we keep node idx, but in this structure we keep the distance
* value associated to every node, and their position in the heap as a pointer

View File

@@ -1,5 +1,5 @@
#ifndef LIGHTNING_PLUGINS_ASKRENE_DIJKSTRA_H
#define LIGHTNING_PLUGINS_ASKRENE_DIJKSTRA_H
#ifndef LIGHTNING_PLUGINS_ASKRENE_CHILD_DIJKSTRA_H
#define LIGHTNING_PLUGINS_ASKRENE_CHILD_DIJKSTRA_H
#include "config.h"
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
@@ -27,4 +27,4 @@ size_t dijkstra_size(const struct dijkstra *dijkstra);
/* Maximum number of elements the heap can host */
size_t dijkstra_maxsize(const struct dijkstra *dijkstra);
#endif /* LIGHTNING_PLUGINS_ASKRENE_DIJKSTRA_H */
#endif /* LIGHTNING_PLUGINS_ASKRENE_CHILD_DIJKSTRA_H */

View File

@@ -4,7 +4,7 @@
#include <common/gossmap.h>
#include <common/route.h>
#include <plugins/askrene/askrene.h>
#include <plugins/askrene/explain_failure.h>
#include <plugins/askrene/child/explain_failure.h>
#include <plugins/askrene/layer.h>
#include <plugins/askrene/reserve.h>

View File

@@ -1,5 +1,5 @@
#ifndef LIGHTNING_PLUGINS_ASKRENE_EXPLAIN_FAILURE_H
#define LIGHTNING_PLUGINS_ASKRENE_EXPLAIN_FAILURE_H
#ifndef LIGHTNING_PLUGINS_ASKRENE_CHILD_EXPLAIN_FAILURE_H
#define LIGHTNING_PLUGINS_ASKRENE_CHILD_EXPLAIN_FAILURE_H
#include "config.h"
#include <common/amount.h>
@@ -13,4 +13,4 @@ const char *explain_failure(const tal_t *ctx,
const struct gossmap_node *dstnode,
struct amount_msat amount);
#endif /* LIGHTNING_PLUGINS_ASKRENE_EXPLAIN_FAILURE_H */
#endif /* LIGHTNING_PLUGINS_ASKRENE_CHILD_EXPLAIN_FAILURE_H */

View File

@@ -6,7 +6,7 @@
#include <common/overflows.h>
#include <math.h>
#include <plugins/askrene/askrene.h>
#include <plugins/askrene/flow.h>
#include <plugins/askrene/child/flow.h>
#include <plugins/libplugin.h>
#include <stdio.h>

View File

@@ -1,5 +1,5 @@
#ifndef LIGHTNING_PLUGINS_ASKRENE_FLOW_H
#define LIGHTNING_PLUGINS_ASKRENE_FLOW_H
#ifndef LIGHTNING_PLUGINS_ASKRENE_CHILD_FLOW_H
#define LIGHTNING_PLUGINS_ASKRENE_CHILD_FLOW_H
#include "config.h"
#include <bitcoin/short_channel_id.h>
#include <common/amount.h>
@@ -66,4 +66,4 @@ const char *fmt_flows_step_scid(const tal_t *ctx,
const char *fmt_flow_full(const tal_t *ctx,
const struct route_query *rq,
const struct flow *flow);
#endif /* LIGHTNING_PLUGINS_ASKRENE_FLOW_H */
#endif /* LIGHTNING_PLUGINS_ASKRENE_CHILD_FLOW_H */

View File

@@ -1,5 +1,5 @@
#include "config.h"
#include <plugins/askrene/graph.h>
#include <plugins/askrene/child/graph.h>
/* in the background add the actual arc or dual arc */
static void graph_push_outbound_arc(struct graph *graph, const struct arc arc,

View File

@@ -1,5 +1,5 @@
#ifndef LIGHTNING_PLUGINS_ASKRENE_GRAPH_H
#define LIGHTNING_PLUGINS_ASKRENE_GRAPH_H
#ifndef LIGHTNING_PLUGINS_ASKRENE_CHILD_GRAPH_H
#define LIGHTNING_PLUGINS_ASKRENE_CHILD_GRAPH_H
/* Defines a graph data structure. */
@@ -168,4 +168,4 @@ bool graph_add_arc(struct graph *graph, const struct arc arc,
struct graph *graph_new(const tal_t *ctx, const size_t max_num_nodes,
const size_t max_num_arcs, const size_t arc_dual_bit);
#endif /* LIGHTNING_PLUGINS_ASKRENE_GRAPH_H */
#endif /* LIGHTNING_PLUGINS_ASKRENE_CHILD_GRAPH_H */

View File

@@ -9,15 +9,14 @@
#include <float.h>
#include <inttypes.h>
#include <math.h>
#include <plugins/askrene/algorithm.h>
#include <plugins/askrene/askrene.h>
#include <plugins/askrene/dijkstra.h>
#include <plugins/askrene/explain_failure.h>
#include <plugins/askrene/flow.h>
#include <plugins/askrene/graph.h>
#include <plugins/askrene/mcf.h>
#include <plugins/askrene/refine.h>
#include <plugins/libplugin.h>
#include <plugins/askrene/child/algorithm.h>
#include <plugins/askrene/child/dijkstra.h>
#include <plugins/askrene/child/explain_failure.h>
#include <plugins/askrene/child/flow.h>
#include <plugins/askrene/child/graph.h>
#include <plugins/askrene/child/mcf.h>
#include <plugins/askrene/child/refine.h>
#include <stdint.h>
/* # Optimal payments

View File

@@ -1,8 +1,9 @@
#ifndef LIGHTNING_PLUGINS_ASKRENE_MCF_H
#define LIGHTNING_PLUGINS_ASKRENE_MCF_H
#ifndef LIGHTNING_PLUGINS_ASKRENE_CHILD_MCF_H
#define LIGHTNING_PLUGINS_ASKRENE_CHILD_MCF_H
/* Eduardo Quintela's (lagrang3@protonmail.com) Min Cost Flow implementation
* from renepay, as modified to fit askrene */
#include "config.h"
#include <ccan/time/time.h>
#include <common/amount.h>
#include <common/gossmap.h>
@@ -29,4 +30,4 @@ const char *single_path_routes(const tal_t *ctx, struct route_query *rq,
u32 maxdelay, struct flow ***flows,
double *probability);
#endif /* LIGHTNING_PLUGINS_ASKRENE_MCF_H */
#endif /* LIGHTNING_PLUGINS_ASKRENE_CHILD_MCF_H */

View File

@@ -1,6 +1,6 @@
#define NDEBUG 1
#include "config.h"
#include <plugins/askrene/priorityqueue.h>
#include <plugins/askrene/child/priorityqueue.h>
/* priorityqueue: a data structure for pairs (key, value) with
* 0<=key<max_num_elements, with easy access to elements by key and the pair

View File

@@ -1,5 +1,5 @@
#ifndef LIGHTNING_PLUGINS_ASKRENE_PRIORITYQUEUE_H
#define LIGHTNING_PLUGINS_ASKRENE_PRIORITYQUEUE_H
#ifndef LIGHTNING_PLUGINS_ASKRENE_CHILD_PRIORITYQUEUE_H
#define LIGHTNING_PLUGINS_ASKRENE_CHILD_PRIORITYQUEUE_H
/* Defines a priority queue using gheap. */
@@ -32,4 +32,4 @@ size_t priorityqueue_size(const struct priorityqueue *priorityqueue);
/* Maximum number of elements the heap can host */
size_t priorityqueue_maxsize(const struct priorityqueue *priorityqueue);
#endif /* LIGHTNING_PLUGINS_ASKRENE_PRIORITYQUEUE_H */
#endif /* LIGHTNING_PLUGINS_ASKRENE_CHILD_PRIORITYQUEUE_H */

View File

@@ -4,8 +4,8 @@
#include <ccan/tal/str/str.h>
#include <common/gossmap.h>
#include <plugins/askrene/askrene.h>
#include <plugins/askrene/flow.h>
#include <plugins/askrene/refine.h>
#include <plugins/askrene/child/flow.h>
#include <plugins/askrene/child/refine.h>
#include <plugins/askrene/reserve.h>
#include <string.h>

View File

@@ -1,5 +1,5 @@
#ifndef LIGHTNING_PLUGINS_ASKRENE_REFINE_H
#define LIGHTNING_PLUGINS_ASKRENE_REFINE_H
#ifndef LIGHTNING_PLUGINS_ASKRENE_CHILD_REFINE_H
#define LIGHTNING_PLUGINS_ASKRENE_CHILD_REFINE_H
#include "config.h"
#include <ccan/tal/tal.h>
@@ -41,4 +41,4 @@ const char *reduce_num_flows(const tal_t *ctx,
struct flow ***flows,
struct amount_msat deliver,
size_t num_parts);
#endif /* LIGHTNING_PLUGINS_ASKRENE_REFINE_H */
#endif /* LIGHTNING_PLUGINS_ASKRENE_CHILD_REFINE_H */

View File

@@ -14,6 +14,7 @@
#include <common/node_id.h>
struct askrene;
struct command;
struct layer;
struct json_stream;

View File

@@ -8,6 +8,8 @@
#include <common/amount.h>
#include <common/fp16.h>
struct json_stream;
/* Initialize hash table for reservations */
struct reserve_htable *new_reserve_htable(const tal_t *ctx);

View File

@@ -9,12 +9,11 @@ ALL_TEST_PROGRAMS += $(PLUGIN_ASKRENE_TEST_PROGRAMS)
$(PLUGIN_RENEPAY_TEST_OBJS): $(PLUGIN_ASKRENE_SRC) plugins/askrene/test/Makefile
plugins/askrene/test/run-bfs plugins/askrene/test/run-dijkstra plugins/askrene/test/run-flow plugins/askrene/test/run-mcf plugins/askrene/test/run-mcf-large: \
plugins/askrene/priorityqueue.o \
plugins/askrene/graph.o
plugins/askrene/child/priorityqueue.o \
plugins/askrene/child/graph.o
$(PLUGIN_ASKRENE_TEST_PROGRAMS): $(PLUGIN_LIB_OBJS) libcommon.a
check-askrene: $(PLUGIN_ASKRENE_TEST_PROGRAMS:%=unittest/%)
check-units: check-askrene

View File

@@ -3,11 +3,11 @@
#include <ccan/tal/tal.h>
#include <common/setup.h>
#include <inttypes.h>
#include <plugins/askrene/graph.h>
#include <plugins/askrene/child/graph.h>
#include <stdio.h>
#define ASKRENE_UNITTEST
#include "../algorithm.c"
#include "../child/algorithm.c"
#define MAX_NODES 256
#define MAX_ARCS 256

View File

@@ -3,11 +3,11 @@
#include <ccan/tal/tal.h>
#include <common/setup.h>
#include <inttypes.h>
#include <plugins/askrene/graph.h>
#include <plugins/askrene/child/graph.h>
#include <stdio.h>
#define ASKRENE_UNITTEST
#include "../algorithm.c"
#include "../child/algorithm.c"
// 1->2 7
// 1->3 9

View File

@@ -3,11 +3,11 @@
#include <ccan/tal/tal.h>
#include <common/setup.h>
#include <inttypes.h>
#include <plugins/askrene/graph.h>
#include <plugins/askrene/child/graph.h>
#include <stdio.h>
#define ASKRENE_UNITTEST
#include "../algorithm.c"
#include "../child/algorithm.c"
#define MAX_NODES 256
#define MAX_ARCS 256

View File

@@ -7,7 +7,7 @@
#include <stdio.h>
#define ASKRENE_UNITTEST
#include "../graph.c"
#include "../child/graph.c"
#define MAX_NODES 10
#define MAX_ARCS 256

View File

@@ -3,11 +3,11 @@
#include <ccan/tal/tal.h>
#include <common/setup.h>
#include <inttypes.h>
#include <plugins/askrene/graph.h>
#include <plugins/askrene/child/graph.h>
#include <stdio.h>
#define ASKRENE_UNITTEST
#include "../algorithm.c"
#include "../child/algorithm.c"
#ifdef HAVE_ZLIB
#include <zlib.h>

View File

@@ -3,11 +3,11 @@
#include <ccan/tal/tal.h>
#include <common/setup.h>
#include <inttypes.h>
#include <plugins/askrene/graph.h>
#include <plugins/askrene/child/graph.h>
#include <stdio.h>
#define ASKRENE_UNITTEST
#include "../algorithm.c"
#include "../child/algorithm.c"
#define CHECK(arg) if(!(arg)){fprintf(stderr, "failed CHECK at line %d: %s\n", __LINE__, #arg); abort();}

View File

@@ -6,7 +6,7 @@
#include <stdio.h>
#define ASKRENE_UNITTEST
#include "../priorityqueue.c"
#include "../child/priorityqueue.c"
#define CHECK(arg) if(!(arg)){fprintf(stderr, "failed CHECK at line %d: %s\n", __LINE__, #arg); abort();}