Skip to content

Commit da572d0

Browse files
committed
askrene: disabled nodes and channels types
Use different types for disabled nodes and channels. Signed-off-by: Lagrang3 <[email protected]>
1 parent 02005e7 commit da572d0

File tree

3 files changed

+49
-52
lines changed

3 files changed

+49
-52
lines changed

contrib/msggen/msggen/schema.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@
611611
"additionalProperties": false,
612612
"required": [
613613
"layer",
614-
"disabled",
614+
"disabled_nodes",
615+
"disabled_channels",
615616
"created_channels",
616617
"constraints"
617618
],
@@ -622,22 +623,21 @@
622623
"The name of the layer."
623624
]
624625
},
625-
"disabled": {
626+
"disabled_nodes": {
626627
"type": "array",
627628
"items": {
628-
"oneOf": [
629-
{
630-
"type": "pubkey",
631-
"description": [
632-
"The id of the disabled node."
633-
]
634-
},
635-
{
636-
"type": "short_channel_id_dir",
637-
"description": [
638-
"The short channel id of the disabled channel."
639-
]
640-
}
629+
"type": "pubkey",
630+
"description": [
631+
"The id of the disabled node."
632+
]
633+
}
634+
},
635+
"disabled_channels": {
636+
"type": "array",
637+
"items": {
638+
"type": "short_channel_id_dir",
639+
"description": [
640+
"The short channel id of the disabled channel."
641641
]
642642
}
643643
},

doc/schemas/lightning-askrene-listlayers.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"additionalProperties": false,
3333
"required": [
3434
"layer",
35-
"disabled",
35+
"disabled_nodes",
36+
"disabled_channels",
3637
"created_channels",
3738
"constraints"
3839
],
@@ -43,22 +44,21 @@
4344
"The name of the layer."
4445
]
4546
},
46-
"disabled": {
47+
"disabled_nodes": {
4748
"type": "array",
4849
"items": {
49-
"oneOf": [
50-
{
51-
"type": "pubkey",
52-
"description": [
53-
"The id of the disabled node."
54-
]
55-
},
56-
{
57-
"type": "short_channel_id_dir",
58-
"description": [
59-
"The short channel id of the disabled channel."
60-
]
61-
}
50+
"type": "pubkey",
51+
"description": [
52+
"The id of the disabled node."
53+
]
54+
}
55+
},
56+
"disabled_channels": {
57+
"type": "array",
58+
"items": {
59+
"type": "short_channel_id_dir",
60+
"description": [
61+
"The short channel id of the disabled channel."
6262
]
6363
}
6464
},

plugins/askrene/layer.c

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ struct layer {
8383
struct constraint_hash *constraints;
8484

8585
/* Channels and nodes to disable (tal_arr). */
86-
struct route_exclusion *disabled;
86+
struct node_id *disabled_nodes;
87+
struct short_channel_id_dir *disabled_chans;
8788
};
8889

8990
struct layer *new_temp_layer(const tal_t *ctx, const char *name)
@@ -95,7 +96,8 @@ struct layer *new_temp_layer(const tal_t *ctx, const char *name)
9596
local_channel_hash_init(l->local_channels);
9697
l->constraints = tal(l, struct constraint_hash);
9798
constraint_hash_init(l->constraints);
98-
l->disabled = tal_arr(l, struct route_exclusion, 0);
99+
l->disabled_chans = tal_arr(l, struct short_channel_id_dir, 0);
100+
l->disabled_nodes = tal_arr(l, struct node_id, 0);
99101

100102
return l;
101103
}
@@ -300,19 +302,13 @@ size_t layer_trim_constraints(struct layer *layer, u64 cutoff)
300302

301303
void layer_add_disabled_node(struct layer *layer, const struct node_id *node)
302304
{
303-
struct route_exclusion ex;
304-
ex.type = EXCLUDE_NODE;
305-
ex.u.node_id = *node;
306-
tal_arr_expand(&layer->disabled, ex);
305+
tal_arr_expand(&layer->disabled_nodes, *node);
307306
}
308307

309308
void layer_add_disabled_channel(struct layer *layer,
310309
const struct short_channel_id_dir *scidd)
311310
{
312-
struct route_exclusion ex;
313-
ex.type = EXCLUDE_CHANNEL;
314-
ex.u.chan_id = *scidd;
315-
tal_arr_expand(&layer->disabled, ex);
311+
tal_arr_expand(&layer->disabled_chans, *scidd);
316312
}
317313

318314
void layer_add_localmods(const struct layer *layer,
@@ -407,9 +403,13 @@ static void json_add_layer(struct json_stream *js,
407403

408404
json_object_start(js, fieldname);
409405
json_add_string(js, "layer", layer->name);
410-
json_array_start(js, "disabled");
411-
for (size_t i = 0; i < tal_count(layer->disabled); i++)
412-
json_add_route_exclusion(js, NULL, &layer->disabled[i]);
406+
json_array_start(js, "disabled_nodes");
407+
for (size_t i = 0; i < tal_count(layer->disabled_nodes); i++)
408+
json_add_node_id(js, NULL, &layer->disabled_nodes[i]);
409+
json_array_end(js);
410+
json_array_start(js, "disabled_channels");
411+
for (size_t i = 0; i < tal_count(layer->disabled_chans); i++)
412+
json_add_short_channel_id_dir(js, NULL, layer->disabled_chans[i]);
413413
json_array_end(js);
414414
json_array_start(js, "created_channels");
415415
for (lc = local_channel_hash_first(layer->local_channels, &lcit);
@@ -498,16 +498,13 @@ bitmap *tal_get_disabled_bitmap(const tal_t *ctx, struct route_query *rq)
498498
for (size_t i = 0; i < tal_count(rq->layers); i++) {
499499
const struct layer *l = rq->layers[i];
500500

501-
for (size_t j = 0; j < tal_count(l->disabled); j++) {
502-
const struct route_exclusion *ex = &l->disabled[j];
501+
for (size_t j = 0; j < tal_count(l->disabled_chans); j++)
502+
set_channel_bit(disabled, rq->gossmap,
503+
&l->disabled_chans[j]);
503504

504-
if (ex->type == EXCLUDE_CHANNEL)
505-
set_channel_bit(disabled, rq->gossmap,
506-
&ex->u.chan_id);
507-
else
508-
set_node_channels_bit(disabled, rq->gossmap,
509-
&ex->u.node_id);
510-
}
505+
for (size_t j = 0; j < tal_count(l->disabled_nodes); j++)
506+
set_node_channels_bit(disabled, rq->gossmap,
507+
&l->disabled_nodes[j]);
511508
}
512509
return disabled;
513510
}

0 commit comments

Comments
 (0)