Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,62 @@
"Main web site: <https://github.com/ElementsProject/lightning>"
]
},
"lightning-askrene-disable-channel.json": {
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"rpc": "askrene-disable-channel",
"title": "Command to disable a channel in a layer (EXPERIMENTAL)",
"description": [
"WARNING: experimental, so API may change.",
"",
"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."
],
"request": {
"required": [
"layer",
"short_channel_id"
],
"properties": {
"layer": {
"type": "string",
"description": [
"The name of the layer to apply this change to."
]
},
"short_channel_id": {
"type": "short_channel_id",
"description": [
"The channel to disable."
]
},
"direction": {
"type": "u32",
"description": [
"The direction of the channel. If the direction is not specified then both directions are disabled."
]
}
}
},
"response": {
"required": [],
"properties": {}
},
"see_also": [
"lightning-getroutes(7)",
"lightning-askrene-create-channel(7)",
"lightning-askrene-inform-channel(7)",
"lightning-askrene-disable-node(7)",
"lightning-askrene-listlayers(7)",
"lightning-askrene-age(7)"
],
"author": [
"Rusty Russell <<[email protected]>> is mainly responsible."
],
"resources": [
"Main web site: <https://github.com/ElementsProject/lightning>"
]
},
"lightning-askrene-disable-node.json": {
"$schema": "../rpc-schema-draft.json",
"type": "object",
Expand Down Expand Up @@ -556,6 +612,7 @@
"required": [
"layer",
"disabled_nodes",
"disabled_channels",
"created_channels",
"constraints"
],
Expand All @@ -575,6 +632,15 @@
]
}
},
"disabled_channels": {
"type": "array",
"items": {
"type": "short_channel_id_dir",
"description": [
"The short channel id of the disabled channel."
]
}
},
"created_channels": {
"type": "array",
"items": {
Expand Down
1 change: 1 addition & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ GENERATE_MARKDOWN := doc/lightning-addgossip.7 \
doc/lightning-addpsbtoutput.7 \
doc/lightning-askrene-create-channel.7 \
doc/lightning-askrene-disable-node.7 \
doc/lightning-askrene-disable-channel.7 \
doc/lightning-askrene-inform-channel.7 \
doc/lightning-askrene-listlayers.7 \
doc/lightning-askrene-reserve.7 \
Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Core Lightning Documentation
lightning-addgossip <lightning-addgossip.7.md>
lightning-addpsbtoutput <lightning-addpsbtoutput.7.md>
lightning-askrene-create-channel <lightning-askrene-create-channel.7.md>
lightning-askrene-disable-channel <lightning-askrene-disable-channel.7.md>
lightning-askrene-disable-node <lightning-askrene-disable-node.7.md>
lightning-askrene-inform-channel <lightning-askrene-inform-channel.7.md>
lightning-askrene-listlayers <lightning-askrene-listlayers.7.md>
Expand Down
56 changes: 56 additions & 0 deletions doc/schemas/lightning-askrene-disable-channel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"$schema": "../rpc-schema-draft.json",
"type": "object",
"additionalProperties": false,
"rpc": "askrene-disable-channel",
"title": "Command to disable a channel in a layer (EXPERIMENTAL)",
"description": [
"WARNING: experimental, so API may change.",
"",
"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."
],
"request": {
"required": [
"layer",
"short_channel_id"
],
"properties": {
"layer": {
"type": "string",
"description": [
"The name of the layer to apply this change to."
]
},
"short_channel_id": {
"type": "short_channel_id",
"description": [
"The channel to disable."
]
},
"direction": {
"type": "u32",
"description": [
"The direction of the channel. If the direction is not specified then both directions are disabled."
]
}
}
},
"response": {
"required": [],
"properties": {}
},
"see_also": [
"lightning-getroutes(7)",
"lightning-askrene-create-channel(7)",
"lightning-askrene-inform-channel(7)",
"lightning-askrene-disable-node(7)",
"lightning-askrene-listlayers(7)",
"lightning-askrene-age(7)"
],
"author": [
"Rusty Russell <<[email protected]>> is mainly responsible."
],
"resources": [
"Main web site: <https://github.com/ElementsProject/lightning>"
]
}
10 changes: 10 additions & 0 deletions doc/schemas/lightning-askrene-listlayers.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"required": [
"layer",
"disabled_nodes",
"disabled_channels",
"created_channels",
"constraints"
],
Expand All @@ -52,6 +53,15 @@
]
}
},
"disabled_channels": {
"type": "array",
"items": {
"type": "short_channel_id_dir",
"description": [
"The short channel id of the disabled channel."
]
}
},
"created_channels": {
"type": "array",
"items": {
Expand Down
48 changes: 48 additions & 0 deletions plugins/askrene/askrene.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ static const char *get_routes(const tal_t *ctx,

gossmap_apply_localmods(askrene->gossmap, localmods);

rq->disabled = tal_get_disabled_bitmap(rq, rq);
if (!rq->disabled) {
ret = tal_fmt(ctx, "Failed creation of disabled bitmap.");
goto out;
}

srcnode = gossmap_find_node(askrene->gossmap, source);
if (!srcnode) {
ret = tal_fmt(ctx, "Unknown source node %s", fmt_node_id(tmpctx, source));
Expand Down Expand Up @@ -881,6 +887,44 @@ static struct command_result *json_askrene_inform_channel(struct command *cmd,
return command_finished(cmd, response);
}

static struct command_result *json_askrene_disable_channel(struct command *cmd,
const char *buffer,
const jsmntok_t *params)
{
struct short_channel_id *scid;
int *direction;
const char *layername;
struct layer *layer;
struct json_stream *response;
struct askrene *askrene = get_askrene(cmd->plugin);

if (!param(cmd, buffer, params,
p_req("layer", param_layername, &layername),
p_req("short_channel_id", param_short_channel_id, &scid),
p_opt("direction", param_zero_or_one, &direction),
NULL))
return command_param_failed();

layer = find_layer(askrene, layername);
if (!layer)
layer = new_layer(askrene, layername);

struct short_channel_id_dir scidd = {.scid = *scid};
if (direction) {
scidd.dir = *direction;
layer_add_disabled_channel(layer, &scidd);
} else {
/* If no direction is provided we disable both. */
scidd.dir = 0;
layer_add_disabled_channel(layer, &scidd);
scidd.dir = 1;
layer_add_disabled_channel(layer, &scidd);
}

response = jsonrpc_stream_success(cmd);
return command_finished(cmd, response);
}

static struct command_result *json_askrene_disable_node(struct command *cmd,
const char *buffer,
const jsmntok_t *params)
Expand Down Expand Up @@ -983,6 +1027,10 @@ static const struct plugin_command commands[] = {
"askrene-age",
json_askrene_age,
},
{
"askrene-disable-channel",
json_askrene_disable_channel,
},
};

static void askrene_markmem(struct plugin *plugin, struct htable *memtable)
Expand Down
5 changes: 5 additions & 0 deletions plugins/askrene/askrene.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define LIGHTNING_PLUGINS_ASKRENE_ASKRENE_H
#include "config.h"
#include <bitcoin/short_channel_id.h>
#include <ccan/bitmap/bitmap.h>
#include <ccan/htable/htable_type.h>
#include <ccan/list/list.h>
#include <common/amount.h>
Expand Down Expand Up @@ -41,6 +42,10 @@ struct route_query {
/* This is *not* updated during a query! Has all layers applied. */
const struct gossmap *gossmap;

/* Bit is set for [idx*2+dir] if that channel is disabled or if it
* belongs to a disabled node.. */
bitmap *disabled;

/* We need to take in-flight payments into account */
const struct reserve_htable *reserved;

Expand Down
Loading
Loading