Skip to content

Commit

Permalink
askrene-bias-channel: bias call add up.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Lagrang3 committed Feb 11, 2025
1 parent 3f2b490 commit 5129604
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
"title": "Command to apply a manual bias to a channel in a layer",
"added": "v24.11",
"description": [
"The **askrene-bias-channel** RPC command tells askrene to favor or disfavor a channel when considering it for routing."
"The **askrene-bias-channel** RPC command tells askrene to favor or disfavor a channel when considering it for routing. Repeated calls to askrene-bias-channel add up the biases up to +100 or down to -100."
],
"request": {
"required": [
Expand Down
2 changes: 1 addition & 1 deletion doc/schemas/lightning-askrene-bias-channel.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"title": "Command to apply a manual bias to a channel in a layer",
"added": "v24.11",
"description": [
"The **askrene-bias-channel** RPC command tells askrene to favor or disfavor a channel when considering it for routing."
"The **askrene-bias-channel** RPC command tells askrene to favor or disfavor a channel when considering it for routing. Repeated calls to askrene-bias-channel add up the biases up to +100 or down to -100."
],
"request": {
"required": [
Expand Down
12 changes: 9 additions & 3 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 @@ -294,15 +297,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_sum = bias->bias + bias_factor;
bias_sum = MIN(100, bias_sum);
bias_sum = MAX(-100, bias_sum);
bias->bias = bias_sum;
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
3 changes: 2 additions & 1 deletion tests/test_askrene.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,8 @@ def amount_through_chan(chan, routes):
total += p['amount_msat']
return total
amount_before = amount_through_chan(chan, route['routes'])

# remove any previous biases
l1.rpc.askrene_age('biases', int(time.time()) + 10)
l1.rpc.askrene_bias_channel('biases', chan, -bias)
route2 = l1.rpc.getroutes(source=l1.info['id'],
destination=nodeids[n],
Expand Down

0 comments on commit 5129604

Please sign in to comment.