Skip to content

Commit 556e38c

Browse files
Lagrang3rustyrussell
authored andcommitted
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 <lagrang3@protonmail.com>
1 parent c81ec4f commit 556e38c

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

contrib/msggen/msggen/schema.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@
309309
"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."
310310
]
311311
},
312+
"relative": {
313+
"type": "boolean",
314+
"added": "v25.05",
315+
"default": false,
316+
"description": [
317+
"The bias will be added to the previous value."
318+
]
319+
},
312320
"description": {
313321
"type": "string",
314322
"description": [
@@ -29248,6 +29256,11 @@
2924829256
"active": true,
2924929257
"dynamic": false
2925029258
},
29259+
{
29260+
"name": "/root/lightning/plugins/cln-lsps-client",
29261+
"active": true,
29262+
"dynamic": false
29263+
},
2925129264
{
2925229265
"name": "/root/lightning/plugins/bookkeeper",
2925329266
"active": true,
@@ -29381,6 +29394,11 @@
2938129394
"active": true,
2938229395
"dynamic": false
2938329396
},
29397+
{
29398+
"name": "/root/lightning/plugins/cln-lsps-client",
29399+
"active": true,
29400+
"dynamic": false
29401+
},
2938429402
{
2938529403
"name": "/root/lightning/plugins/bookkeeper",
2938629404
"active": true,

doc/schemas/askrene-bias-channel.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
"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."
3434
]
3535
},
36+
"relative": {
37+
"type": "boolean",
38+
"added": "v25.05",
39+
"default": false,
40+
"description": [
41+
"The bias will be added to the previous value."
42+
]
43+
},
3644
"description": {
3745
"type": "string",
3846
"description": [

doc/schemas/plugin.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@
297297
"active": true,
298298
"dynamic": false
299299
},
300+
{
301+
"name": "/root/lightning/plugins/cln-lsps-client",
302+
"active": true,
303+
"dynamic": false
304+
},
300305
{
301306
"name": "/root/lightning/plugins/bookkeeper",
302307
"active": true,
@@ -430,6 +435,11 @@
430435
"active": true,
431436
"dynamic": false
432437
},
438+
{
439+
"name": "/root/lightning/plugins/cln-lsps-client",
440+
"active": true,
441+
"dynamic": false
442+
},
433443
{
434444
"name": "/root/lightning/plugins/bookkeeper",
435445
"active": true,

plugins/askrene/askrene.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,18 +1098,20 @@ static struct command_result *json_askrene_bias_channel(struct command *cmd,
10981098
const char *description;
10991099
s8 *bias;
11001100
const struct bias *b;
1101+
bool *relative;
11011102

11021103
if (!param(cmd, buffer, params,
11031104
p_req("layer", param_known_layer, &layer),
11041105
p_req("short_channel_id_dir", param_short_channel_id_dir, &scidd),
11051106
p_req("bias", param_s8_hundred, &bias),
1107+
p_opt_def("relative", param_bool, &relative, false),
11061108
p_opt("description", param_string, &description),
11071109
NULL))
11081110
return command_param_failed();
11091111
plugin_log(cmd->plugin, LOG_TRACE, "%s called: %.*s", __func__,
11101112
json_tok_full_len(params), json_tok_full(buffer, params));
11111113

1112-
b = layer_set_bias(layer, scidd, description, *bias);
1114+
b = layer_set_bias(layer, scidd, description, *bias, *relative);
11131115
response = jsonrpc_stream_success(cmd);
11141116
json_array_start(response, "biases");
11151117
if (b)

plugins/askrene/layer.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include <plugins/askrene/layer.h>
1111
#include <wire/wire.h>
1212

13+
#define MIN(a, b) ((a) < (b) ? (a) : (b))
14+
#define MAX(a, b) ((a) > (b) ? (a) : (b))
15+
1316
/* Different elements in the datastore */
1417
enum dstore_layer_type {
1518
/* 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,
285288
static const struct bias *set_bias(struct layer *layer,
286289
const struct short_channel_id_dir *scidd,
287290
const char *description TAKES,
288-
s8 bias_factor)
291+
s8 bias_factor,
292+
bool relative)
289293
{
290294
struct bias *bias;
291295

@@ -294,15 +298,18 @@ static const struct bias *set_bias(struct layer *layer,
294298
bias = tal(layer, struct bias);
295299
bias->scidd = *scidd;
296300
bias_hash_add(layer->biases, bias);
301+
bias->bias = 0;
297302
} else {
298303
tal_free(bias->description);
299304
}
300-
301-
bias->bias = bias_factor;
305+
int bias_new = relative ? bias->bias + bias_factor : bias_factor;
306+
bias_new = MIN(100, bias_new);
307+
bias_new = MAX(-100, bias_new);
308+
bias->bias = bias_new;
302309
bias->description = tal_strdup_or_null(bias, description);
303310

304311
/* Don't bother keeping around zero biases */
305-
if (bias_factor == 0) {
312+
if (bias->bias == 0) {
306313
bias_hash_del(layer->biases, bias);
307314
bias = tal_free(bias);
308315
}
@@ -588,7 +595,7 @@ static void load_channel_bias(struct plugin *plugin,
588595
description = fromwire_wirestring(tmpctx, cursor, len);
589596

590597
if (*cursor)
591-
set_bias(layer, &scidd, take(description), bias_factor);
598+
set_bias(layer, &scidd, take(description), bias_factor, false);
592599
}
593600

594601
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,
818825
const struct bias *layer_set_bias(struct layer *layer,
819826
const struct short_channel_id_dir *scidd,
820827
const char *description TAKES,
821-
s8 bias_factor)
828+
s8 bias_factor,
829+
bool relative)
822830
{
823831
const struct bias *bias;
824832

825-
bias = set_bias(layer, scidd, description, bias_factor);
833+
bias = set_bias(layer, scidd, description, bias_factor, relative);
826834
save_channel_bias(layer, bias);
827835
return bias;
828836
}

plugins/askrene/layer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ void layer_add_local_channel(struct layer *layer,
5959
const struct bias *layer_set_bias(struct layer *layer,
6060
const struct short_channel_id_dir *scidd,
6161
const char *description TAKES,
62-
s8 bias_factor);
62+
s8 bias_factor,
63+
bool relative);
6364

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

0 commit comments

Comments
 (0)