Skip to content

Commit 3c02b42

Browse files
committed
add askrene-disable-channel
Add askrene-disable-channel RPC and refactor the what channels and nodes are excluded in the MCF solver (use a bitmap instead of gossmap_local_updatechan). Changelog-EXPERIMENTAL: askrene: add askrene-disable-channel RPC Signed-off-by: Lagrang3 <[email protected]>
1 parent 00e0b99 commit 3c02b42

File tree

11 files changed

+291
-32
lines changed

11 files changed

+291
-32
lines changed

contrib/msggen/msggen/schema.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,62 @@
361361
"Main web site: <https://github.com/ElementsProject/lightning>"
362362
]
363363
},
364+
"lightning-askrene-disable-channel.json": {
365+
"$schema": "../rpc-schema-draft.json",
366+
"type": "object",
367+
"additionalProperties": false,
368+
"rpc": "askrene-disable-channel",
369+
"title": "Command to disable a channel in a layer (EXPERIMENTAL)",
370+
"description": [
371+
"WARNING: experimental, so API may change.",
372+
"",
373+
"The **askrene-disable-channel** RPC command tells askrene to disable a channel whenever the given layer is used. This is mainly useful to force the use of alternate paths."
374+
],
375+
"request": {
376+
"required": [
377+
"layer",
378+
"short_channel_id"
379+
],
380+
"properties": {
381+
"layer": {
382+
"type": "string",
383+
"description": [
384+
"The name of the layer to apply this change to."
385+
]
386+
},
387+
"short_channel_id": {
388+
"type": "short_channel_id",
389+
"description": [
390+
"The channel to disable."
391+
]
392+
},
393+
"direction": {
394+
"type": "u32",
395+
"description": [
396+
"The direction of the channel. If the direction is not specified then both directions are disabled."
397+
]
398+
}
399+
}
400+
},
401+
"response": {
402+
"required": [],
403+
"properties": {}
404+
},
405+
"see_also": [
406+
"lightning-getroutes(7)",
407+
"lightning-askrene-create-channel(7)",
408+
"lightning-askrene-inform-channel(7)",
409+
"lightning-askrene-disable-node(7)",
410+
"lightning-askrene-listlayers(7)",
411+
"lightning-askrene-age(7)"
412+
],
413+
"author": [
414+
"Rusty Russell <<[email protected]>> is mainly responsible."
415+
],
416+
"resources": [
417+
"Main web site: <https://github.com/ElementsProject/lightning>"
418+
]
419+
},
364420
"lightning-askrene-disable-node.json": {
365421
"$schema": "../rpc-schema-draft.json",
366422
"type": "object",
@@ -556,6 +612,7 @@
556612
"required": [
557613
"layer",
558614
"disabled_nodes",
615+
"disabled_channels",
559616
"created_channels",
560617
"constraints"
561618
],
@@ -575,6 +632,15 @@
575632
]
576633
}
577634
},
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."
641+
]
642+
}
643+
},
578644
"created_channels": {
579645
"type": "array",
580646
"items": {

doc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ GENERATE_MARKDOWN := doc/lightning-addgossip.7 \
88
doc/lightning-addpsbtoutput.7 \
99
doc/lightning-askrene-create-channel.7 \
1010
doc/lightning-askrene-disable-node.7 \
11+
doc/lightning-askrene-disable-channel.7 \
1112
doc/lightning-askrene-inform-channel.7 \
1213
doc/lightning-askrene-listlayers.7 \
1314
doc/lightning-askrene-reserve.7 \

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Core Lightning Documentation
1515
lightning-addgossip <lightning-addgossip.7.md>
1616
lightning-addpsbtoutput <lightning-addpsbtoutput.7.md>
1717
lightning-askrene-create-channel <lightning-askrene-create-channel.7.md>
18+
lightning-askrene-disable-channel <lightning-askrene-disable-channel.7.md>
1819
lightning-askrene-disable-node <lightning-askrene-disable-node.7.md>
1920
lightning-askrene-inform-channel <lightning-askrene-inform-channel.7.md>
2021
lightning-askrene-listlayers <lightning-askrene-listlayers.7.md>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"$schema": "../rpc-schema-draft.json",
3+
"type": "object",
4+
"additionalProperties": false,
5+
"rpc": "askrene-disable-channel",
6+
"title": "Command to disable a channel in a layer (EXPERIMENTAL)",
7+
"description": [
8+
"WARNING: experimental, so API may change.",
9+
"",
10+
"The **askrene-disable-channel** RPC command tells askrene to disable a channel whenever the given layer is used. This is mainly useful to force the use of alternate paths."
11+
],
12+
"request": {
13+
"required": [
14+
"layer",
15+
"short_channel_id"
16+
],
17+
"properties": {
18+
"layer": {
19+
"type": "string",
20+
"description": [
21+
"The name of the layer to apply this change to."
22+
]
23+
},
24+
"short_channel_id": {
25+
"type": "short_channel_id",
26+
"description": [
27+
"The channel to disable."
28+
]
29+
},
30+
"direction": {
31+
"type": "u32",
32+
"description": [
33+
"The direction of the channel. If the direction is not specified then both directions are disabled."
34+
]
35+
}
36+
}
37+
},
38+
"response": {
39+
"required": [],
40+
"properties": {}
41+
},
42+
"see_also": [
43+
"lightning-getroutes(7)",
44+
"lightning-askrene-create-channel(7)",
45+
"lightning-askrene-inform-channel(7)",
46+
"lightning-askrene-disable-node(7)",
47+
"lightning-askrene-listlayers(7)",
48+
"lightning-askrene-age(7)"
49+
],
50+
"author": [
51+
"Rusty Russell <<[email protected]>> is mainly responsible."
52+
],
53+
"resources": [
54+
"Main web site: <https://github.com/ElementsProject/lightning>"
55+
]
56+
}

doc/schemas/lightning-askrene-listlayers.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"required": [
3434
"layer",
3535
"disabled_nodes",
36+
"disabled_channels",
3637
"created_channels",
3738
"constraints"
3839
],
@@ -52,6 +53,15 @@
5253
]
5354
}
5455
},
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."
62+
]
63+
}
64+
},
5565
"created_channels": {
5666
"type": "array",
5767
"items": {

plugins/askrene/askrene.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,12 @@ static const char *get_routes(const tal_t *ctx,
337337

338338
gossmap_apply_localmods(askrene->gossmap, localmods);
339339

340+
rq->disabled = tal_get_disabled_bitmap(rq, rq);
341+
if (!rq->disabled) {
342+
ret = tal_fmt(ctx, "Failed creation of disabled bitmap.");
343+
goto out;
344+
}
345+
340346
srcnode = gossmap_find_node(askrene->gossmap, source);
341347
if (!srcnode) {
342348
ret = tal_fmt(ctx, "Unknown source node %s", fmt_node_id(tmpctx, source));
@@ -881,6 +887,44 @@ static struct command_result *json_askrene_inform_channel(struct command *cmd,
881887
return command_finished(cmd, response);
882888
}
883889

890+
static struct command_result *json_askrene_disable_channel(struct command *cmd,
891+
const char *buffer,
892+
const jsmntok_t *params)
893+
{
894+
struct short_channel_id *scid;
895+
int *direction;
896+
const char *layername;
897+
struct layer *layer;
898+
struct json_stream *response;
899+
struct askrene *askrene = get_askrene(cmd->plugin);
900+
901+
if (!param(cmd, buffer, params,
902+
p_req("layer", param_layername, &layername),
903+
p_req("short_channel_id", param_short_channel_id, &scid),
904+
p_opt("direction", param_zero_or_one, &direction),
905+
NULL))
906+
return command_param_failed();
907+
908+
layer = find_layer(askrene, layername);
909+
if (!layer)
910+
layer = new_layer(askrene, layername);
911+
912+
struct short_channel_id_dir scidd = {.scid = *scid};
913+
if (direction) {
914+
scidd.dir = *direction;
915+
layer_add_disabled_channel(layer, &scidd);
916+
} else {
917+
/* If no direction is provided we disable both. */
918+
scidd.dir = 0;
919+
layer_add_disabled_channel(layer, &scidd);
920+
scidd.dir = 1;
921+
layer_add_disabled_channel(layer, &scidd);
922+
}
923+
924+
response = jsonrpc_stream_success(cmd);
925+
return command_finished(cmd, response);
926+
}
927+
884928
static struct command_result *json_askrene_disable_node(struct command *cmd,
885929
const char *buffer,
886930
const jsmntok_t *params)
@@ -983,6 +1027,10 @@ static const struct plugin_command commands[] = {
9831027
"askrene-age",
9841028
json_askrene_age,
9851029
},
1030+
{
1031+
"askrene-disable-channel",
1032+
json_askrene_disable_channel,
1033+
},
9861034
};
9871035

9881036
static void askrene_markmem(struct plugin *plugin, struct htable *memtable)

plugins/askrene/askrene.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define LIGHTNING_PLUGINS_ASKRENE_ASKRENE_H
33
#include "config.h"
44
#include <bitcoin/short_channel_id.h>
5+
#include <ccan/bitmap/bitmap.h>
56
#include <ccan/htable/htable_type.h>
67
#include <ccan/list/list.h>
78
#include <common/amount.h>
@@ -41,6 +42,10 @@ struct route_query {
4142
/* This is *not* updated during a query! Has all layers applied. */
4243
const struct gossmap *gossmap;
4344

45+
/* Bit is set for [idx*2+dir] if that channel is disabled or if it
46+
* belongs to a disabled node.. */
47+
bitmap *disabled;
48+
4449
/* We need to take in-flight payments into account */
4550
const struct reserve_htable *reserved;
4651

0 commit comments

Comments
 (0)