Skip to content

Commit 6112c99

Browse files
committed
add askrene-disable-channel
Changelog-EXPERIMENTAL: askrene: add askrene-disable-channel RPC Signed-off-by: Lagrang3 <[email protected]>
1 parent 6f087dd commit 6112c99

File tree

7 files changed

+131
-8
lines changed

7 files changed

+131
-8
lines changed

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 \
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
}
57+

doc/schemas/lightning-askrene-listlayers.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"additionalProperties": false,
3333
"required": [
3434
"layer",
35-
"disabled_nodes",
35+
"disabled",
3636
"created_channels",
3737
"constraints"
3838
],
@@ -43,13 +43,23 @@
4343
"The name of the layer."
4444
]
4545
},
46-
"disabled_nodes": {
46+
"disabled": {
4747
"type": "array",
4848
"items": {
49-
"type": "pubkey",
50-
"description": [
51-
"The id of the disabled node."
52-
]
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+
}
62+
]
5363
}
5464
},
5565
"created_channels": {

plugins/askrene/askrene.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,44 @@ static struct command_result *json_askrene_inform_channel(struct command *cmd,
881881
return command_finished(cmd, response);
882882
}
883883

884+
static struct command_result *json_askrene_disable_channel(struct command *cmd,
885+
const char *buffer,
886+
const jsmntok_t *params)
887+
{
888+
struct short_channel_id *scid;
889+
int *direction;
890+
const char *layername;
891+
struct layer *layer;
892+
struct json_stream *response;
893+
struct askrene *askrene = get_askrene(cmd->plugin);
894+
895+
if (!param(cmd, buffer, params,
896+
p_req("layer", param_layername, &layername),
897+
p_req("short_channel_id", param_short_channel_id, &scid),
898+
p_opt("direction", param_zero_or_one, &direction),
899+
NULL))
900+
return command_param_failed();
901+
902+
layer = find_layer(askrene, layername);
903+
if (!layer)
904+
layer = new_layer(askrene, layername);
905+
906+
struct short_channel_id_dir scidd = {.scid = *scid};
907+
if (direction) {
908+
scidd.dir = *direction;
909+
layer_add_disabled_channel(layer, &scidd);
910+
} else {
911+
/* If no direction is provided we disable both. */
912+
scidd.dir = 0;
913+
layer_add_disabled_channel(layer, &scidd);
914+
scidd.dir = 1;
915+
layer_add_disabled_channel(layer, &scidd);
916+
}
917+
918+
response = jsonrpc_stream_success(cmd);
919+
return command_finished(cmd, response);
920+
}
921+
884922
static struct command_result *json_askrene_disable_node(struct command *cmd,
885923
const char *buffer,
886924
const jsmntok_t *params)
@@ -983,6 +1021,10 @@ static const struct plugin_command commands[] = {
9831021
"askrene-age",
9841022
json_askrene_age,
9851023
},
1024+
{
1025+
"askrene-disable-channel",
1026+
json_askrene_disable_channel,
1027+
},
9861028
};
9871029

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

plugins/askrene/layer.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,15 @@ void layer_add_disabled_node(struct layer *layer, const struct node_id *node)
306306
tal_arr_expand(&layer->disabled, ex);
307307
}
308308

309+
void layer_add_disabled_channel(struct layer *layer,
310+
const struct short_channel_id_dir *scidd)
311+
{
312+
struct route_exclusion ex;
313+
ex.type = EXCLUDE_CHANNEL;
314+
ex.u.chan_id = *scidd;
315+
tal_arr_expand(&layer->disabled, ex);
316+
}
317+
309318
void layer_add_localmods(const struct layer *layer,
310319
const struct gossmap *gossmap,
311320
bool zero_cost,

plugins/askrene/layer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ size_t layer_trim_constraints(struct layer *layer, u64 cutoff);
102102
/* Add a disabled node to a layer. */
103103
void layer_add_disabled_node(struct layer *layer, const struct node_id *node);
104104

105+
/* Add a disabled channel to a layer. */
106+
void layer_add_disabled_channel(struct layer *layer,
107+
const struct short_channel_id_dir *scidd);
108+
105109
/* Print out a json object per layer, or all if layer is NULL */
106110
void json_add_layers(struct json_stream *js,
107111
struct askrene *askrene,

tests/test_askrene.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ def test_layers(node_factory):
1616
assert l2.rpc.askrene_listlayers('test_layers') == {'layers': []}
1717

1818
expect = {'layer': 'test_layers',
19-
'disabled_nodes': [],
19+
'disabled': [],
2020
'created_channels': [],
2121
'constraints': []}
2222
l2.rpc.askrene_disable_node('test_layers', l1.info['id'])
23-
expect['disabled_nodes'].append(l1.info['id'])
23+
expect['disabled'].append(l1.info['id'])
2424
assert l2.rpc.askrene_listlayers('test_layers') == {'layers': [expect]}
2525
assert l2.rpc.askrene_listlayers() == {'layers': [expect]}
2626
assert l2.rpc.askrene_listlayers('test_layers2') == {'layers': []}

0 commit comments

Comments
 (0)