Skip to content

Commit 6f087dd

Browse files
committed
askrene: add route_exclution array
Disabled nodes and channels are now saved into a tal_arr of type strut route_exclution. Signed-off-by: Lagrang3 <[email protected]>
1 parent e78c102 commit 6f087dd

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

plugins/askrene/layer.c

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <common/gossmap.h>
66
#include <common/json_stream.h>
77
#include <common/memleak.h>
8+
#include <common/route.h>
89
#include <plugins/askrene/askrene.h>
910
#include <plugins/askrene/layer.h>
1011

@@ -81,8 +82,8 @@ struct layer {
8182
/* Additional info, indexed by scid+dir */
8283
struct constraint_hash *constraints;
8384

84-
/* Nodes to completely disable (tal_arr) */
85-
struct node_id *disabled_nodes;
85+
/* Channels and nodes to disable (tal_arr). */
86+
struct route_exclusion *disabled;
8687
};
8788

8889
struct layer *new_temp_layer(const tal_t *ctx, const char *name)
@@ -94,7 +95,7 @@ struct layer *new_temp_layer(const tal_t *ctx, const char *name)
9495
local_channel_hash_init(l->local_channels);
9596
l->constraints = tal(l, struct constraint_hash);
9697
constraint_hash_init(l->constraints);
97-
l->disabled_nodes = tal_arr(l, struct node_id, 0);
98+
l->disabled = tal_arr(l, struct route_exclusion, 0);
9899

99100
return l;
100101
}
@@ -299,7 +300,10 @@ size_t layer_trim_constraints(struct layer *layer, u64 cutoff)
299300

300301
void layer_add_disabled_node(struct layer *layer, const struct node_id *node)
301302
{
302-
tal_arr_expand(&layer->disabled_nodes, *node);
303+
struct route_exclusion ex;
304+
ex.type = EXCLUDE_NODE;
305+
ex.u.node_id = *node;
306+
tal_arr_expand(&layer->disabled, ex);
303307
}
304308

305309
void layer_add_localmods(const struct layer *layer,
@@ -312,29 +316,32 @@ void layer_add_localmods(const struct layer *layer,
312316

313317
/* First, disable all channels into blocked nodes (local updates
314318
* can add new ones)! */
315-
for (size_t i = 0; i < tal_count(layer->disabled_nodes); i++) {
316-
const struct gossmap_node *node;
319+
for (size_t i = 0; i < tal_count(layer->disabled); i++) {
320+
struct route_exclusion ex = layer->disabled[i];
317321

318-
node = gossmap_find_node(gossmap, &layer->disabled_nodes[i]);
319-
if (!node)
320-
continue;
321-
for (size_t n = 0; n < node->num_chans; n++) {
322-
struct short_channel_id scid;
323-
struct gossmap_chan *c;
324-
int dir;
325-
c = gossmap_nth_chan(gossmap, node, n, &dir);
326-
scid = gossmap_chan_scid(gossmap, c);
327-
328-
/* Disabled zero-capacity on incoming */
329-
gossmap_local_updatechan(localmods,
330-
scid,
331-
AMOUNT_MSAT(0),
332-
AMOUNT_MSAT(0),
333-
0,
334-
0,
335-
0,
336-
false,
337-
!dir);
322+
/* Disable all channels of excluded nodes. */
323+
if (ex.type == EXCLUDE_NODE) {
324+
const struct gossmap_node *node;
325+
326+
node = gossmap_find_node(gossmap, &ex.u.node_id);
327+
if (!node)
328+
continue;
329+
for (size_t n = 0; n < node->num_chans; n++) {
330+
struct short_channel_id scid;
331+
struct gossmap_chan *c;
332+
int dir;
333+
c = gossmap_nth_chan(gossmap, node, n, &dir);
334+
scid = gossmap_chan_scid(gossmap, c);
335+
336+
/* Disabled zero-capacity on incoming */
337+
gossmap_local_updatechan(
338+
localmods, scid, AMOUNT_MSAT(0),
339+
AMOUNT_MSAT(0), 0, 0, 0, false, !dir);
340+
}
341+
} else {
342+
gossmap_local_updatechan(
343+
localmods, ex.u.chan_id.scid, AMOUNT_MSAT(0),
344+
AMOUNT_MSAT(0), 0, 0, 0, false, ex.u.chan_id.dir);
338345
}
339346
}
340347

@@ -422,9 +429,9 @@ static void json_add_layer(struct json_stream *js,
422429

423430
json_object_start(js, fieldname);
424431
json_add_string(js, "layer", layer->name);
425-
json_array_start(js, "disabled_nodes");
426-
for (size_t i = 0; i < tal_count(layer->disabled_nodes); i++)
427-
json_add_node_id(js, NULL, &layer->disabled_nodes[i]);
432+
json_array_start(js, "disabled");
433+
for (size_t i = 0; i < tal_count(layer->disabled); i++)
434+
json_add_route_exclusion(js, NULL, &layer->disabled[i]);
428435
json_array_end(js);
429436
json_array_start(js, "created_channels");
430437
for (lc = local_channel_hash_first(layer->local_channels, &lcit);

0 commit comments

Comments
 (0)