From 0c7e1f0b5d8bf2e6c135e293af66bdd6e3b2e987 Mon Sep 17 00:00:00 2001 From: Lagrang3 Date: Mon, 10 Feb 2025 13:38:56 +0100 Subject: [PATCH] askrene-bias-channel: bias call add up. The channel bias feature is not being used yet by any plugin, so this hopefully doesn't break any working code. When askrene-bias-channel is called the bias quantity is added on top of any previous biased already present on that channel instead of overwriting it. Changelog-Changed: askrene-bias-channel: bias call add up. Signed-off-by: Lagrang3 --- contrib/msggen/msggen/schema.json | 18 ++++++++++++++++++ doc/schemas/askrene-bias-channel.json | 8 ++++++++ doc/schemas/plugin.json | 10 ++++++++++ plugins/askrene/askrene.c | 4 +++- plugins/askrene/layer.c | 22 +++++++++++++++------- plugins/askrene/layer.h | 3 ++- 6 files changed, 56 insertions(+), 9 deletions(-) diff --git a/contrib/msggen/msggen/schema.json b/contrib/msggen/msggen/schema.json index bfda44000dfc..15babcb2fbd0 100644 --- a/contrib/msggen/msggen/schema.json +++ b/contrib/msggen/msggen/schema.json @@ -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": [ @@ -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, @@ -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, diff --git a/doc/schemas/askrene-bias-channel.json b/doc/schemas/askrene-bias-channel.json index 2389d026c0da..1e3091336145 100644 --- a/doc/schemas/askrene-bias-channel.json +++ b/doc/schemas/askrene-bias-channel.json @@ -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": [ diff --git a/doc/schemas/plugin.json b/doc/schemas/plugin.json index f9db5792c683..8e636eaaba03 100644 --- a/doc/schemas/plugin.json +++ b/doc/schemas/plugin.json @@ -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, @@ -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, diff --git a/plugins/askrene/askrene.c b/plugins/askrene/askrene.c index d1bc89b8e30c..0e2f2f3fcdbe 100644 --- a/plugins/askrene/askrene.c +++ b/plugins/askrene/askrene.c @@ -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) diff --git a/plugins/askrene/layer.c b/plugins/askrene/layer.c index 6237f605d26d..281e32a03c7b 100644 --- a/plugins/askrene/layer.c +++ b/plugins/askrene/layer.c @@ -10,6 +10,9 @@ #include #include +#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 */ @@ -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; @@ -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); } @@ -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) @@ -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; } diff --git a/plugins/askrene/layer.h b/plugins/askrene/layer.h index 9c5083ab9f26..e9b06fd5a4e6 100644 --- a/plugins/askrene/layer.h +++ b/plugins/askrene/layer.h @@ -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,