Skip to content
Merged
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
18 changes: 18 additions & 0 deletions contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@
"The bias, positive being good and negative being bad (0 being no bias). Useful values are +/-1 through +/-10, though -100 through +100 are possible values."
]
},
"relative": {
"type": "boolean",
"added": "v25.05",
"default": false,
"description": [
"The bias will be added to the previous value."
]
},
"description": {
"type": "string",
"description": [
Expand Down Expand Up @@ -29248,6 +29256,11 @@
"active": true,
"dynamic": false
},
{
"name": "/root/lightning/plugins/cln-lsps-client",
"active": true,
"dynamic": false
},
{
"name": "/root/lightning/plugins/bookkeeper",
"active": true,
Expand Down Expand Up @@ -29381,6 +29394,11 @@
"active": true,
"dynamic": false
},
{
"name": "/root/lightning/plugins/cln-lsps-client",
"active": true,
"dynamic": false
},
{
"name": "/root/lightning/plugins/bookkeeper",
"active": true,
Expand Down
8 changes: 8 additions & 0 deletions doc/schemas/askrene-bias-channel.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
"The bias, positive being good and negative being bad (0 being no bias). Useful values are +/-1 through +/-10, though -100 through +100 are possible values."
]
},
"relative": {
"type": "boolean",
"added": "v25.05",
"default": false,
"description": [
"The bias will be added to the previous value."
]
},
"description": {
"type": "string",
"description": [
Expand Down
10 changes: 10 additions & 0 deletions doc/schemas/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@
"active": true,
"dynamic": false
},
{
"name": "/root/lightning/plugins/cln-lsps-client",
"active": true,
"dynamic": false
},
{
"name": "/root/lightning/plugins/bookkeeper",
"active": true,
Expand Down Expand Up @@ -430,6 +435,11 @@
"active": true,
"dynamic": false
},
{
"name": "/root/lightning/plugins/cln-lsps-client",
"active": true,
"dynamic": false
},
{
"name": "/root/lightning/plugins/bookkeeper",
"active": true,
Expand Down
4 changes: 3 additions & 1 deletion plugins/askrene/askrene.c
Original file line number Diff line number Diff line change
Expand Up @@ -1098,18 +1098,20 @@ static struct command_result *json_askrene_bias_channel(struct command *cmd,
const char *description;
s8 *bias;
const struct bias *b;
bool *relative;

if (!param(cmd, buffer, params,
p_req("layer", param_known_layer, &layer),
p_req("short_channel_id_dir", param_short_channel_id_dir, &scidd),
p_req("bias", param_s8_hundred, &bias),
p_opt_def("relative", param_bool, &relative, false),
p_opt("description", param_string, &description),
NULL))
return command_param_failed();
plugin_log(cmd->plugin, LOG_TRACE, "%s called: %.*s", __func__,
json_tok_full_len(params), json_tok_full(buffer, params));

b = layer_set_bias(layer, scidd, description, *bias);
b = layer_set_bias(layer, scidd, description, *bias, *relative);
response = jsonrpc_stream_success(cmd);
json_array_start(response, "biases");
if (b)
Expand Down
22 changes: 15 additions & 7 deletions plugins/askrene/layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <plugins/askrene/layer.h>
#include <wire/wire.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))

/* Different elements in the datastore */
enum dstore_layer_type {
/* We don't use type 0, which fromwire_u16 returns on trunction */
Expand Down Expand Up @@ -285,7 +288,8 @@ static const struct constraint *add_constraint(struct layer *layer,
static const struct bias *set_bias(struct layer *layer,
const struct short_channel_id_dir *scidd,
const char *description TAKES,
s8 bias_factor)
s8 bias_factor,
bool relative)
{
struct bias *bias;

Expand All @@ -294,15 +298,18 @@ static const struct bias *set_bias(struct layer *layer,
bias = tal(layer, struct bias);
bias->scidd = *scidd;
bias_hash_add(layer->biases, bias);
bias->bias = 0;
} else {
tal_free(bias->description);
}

bias->bias = bias_factor;
int bias_new = relative ? bias->bias + bias_factor : bias_factor;
bias_new = MIN(100, bias_new);
bias_new = MAX(-100, bias_new);
bias->bias = bias_new;
bias->description = tal_strdup_or_null(bias, description);

/* Don't bother keeping around zero biases */
if (bias_factor == 0) {
if (bias->bias == 0) {
bias_hash_del(layer->biases, bias);
bias = tal_free(bias);
}
Expand Down Expand Up @@ -588,7 +595,7 @@ static void load_channel_bias(struct plugin *plugin,
description = fromwire_wirestring(tmpctx, cursor, len);

if (*cursor)
set_bias(layer, &scidd, take(description), bias_factor);
set_bias(layer, &scidd, take(description), bias_factor, false);
}

static void towire_save_disabled_node(u8 **data, const struct node_id *node)
Expand Down Expand Up @@ -818,11 +825,12 @@ void layer_add_update_channel(struct layer *layer,
const struct bias *layer_set_bias(struct layer *layer,
const struct short_channel_id_dir *scidd,
const char *description TAKES,
s8 bias_factor)
s8 bias_factor,
bool relative)
{
const struct bias *bias;

bias = set_bias(layer, scidd, description, bias_factor);
bias = set_bias(layer, scidd, description, bias_factor, relative);
save_channel_bias(layer, bias);
return bias;
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/askrene/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void layer_add_local_channel(struct layer *layer,
const struct bias *layer_set_bias(struct layer *layer,
const struct short_channel_id_dir *scidd,
const char *description TAKES,
s8 bias_factor);
s8 bias_factor,
bool relative);

/* Update details on a channel (could be in this layer, or another) */
void layer_add_update_channel(struct layer *layer,
Expand Down
Loading