askrene: fix API breakage, add tests.

We cannot add new parameters in the middle, since we accept parameters by JSON
array as well as by dicts.  In fact, this broke tests, but due to unrelated
breakage in the GitHub "Automerge" functionality, it got applied as
556e38c838 ("askrene-bias-channel: bias call add
up.").

Also add tests, and a better Changelog line.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `askrene-bias-channel` now has a `relative` option to add, rather than replace, a channel bias.
This commit is contained in:
Rusty Russell
2025-05-10 20:11:47 +09:30
parent 628d002c59
commit 9ce3f5dde4
4 changed files with 30 additions and 13 deletions

View File

@@ -309,6 +309,12 @@
"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."
]
},
"description": {
"type": "string",
"description": [
"Description/annotation to display in askrene-listlayers(7)"
]
},
"relative": {
"type": "boolean",
"added": "v25.05",
@@ -316,12 +322,6 @@
"description": [
"The bias will be added to the previous value."
]
},
"description": {
"type": "string",
"description": [
"Description/annotation to display in askrene-listlayers(7)"
]
}
}
},

View File

@@ -33,6 +33,12 @@
"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."
]
},
"description": {
"type": "string",
"description": [
"Description/annotation to display in askrene-listlayers(7)"
]
},
"relative": {
"type": "boolean",
"added": "v25.05",
@@ -40,12 +46,6 @@
"description": [
"The bias will be added to the previous value."
]
},
"description": {
"type": "string",
"description": [
"Description/annotation to display in askrene-listlayers(7)"
]
}
}
},

View File

@@ -1104,8 +1104,8 @@ static struct command_result *json_askrene_bias_channel(struct command *cmd,
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),
p_opt_def("relative", param_bool, &relative, false),
NULL))
return command_param_failed();
plugin_log(cmd->plugin, LOG_TRACE, "%s called: %.*s", __func__,

View File

@@ -277,6 +277,23 @@ def test_layers(node_factory):
with pytest.raises(RpcError, match="bias: should be a number between -100 and 100"):
l2.rpc.askrene_bias_channel('test_layers', '1x1x1/1', 101, "bigger bias")
# We can make them relative.
l2.rpc.askrene_bias_channel('test_layers', '1x1x1/1', 1, 'adding bias', True)
expect['biases'] = [{'short_channel_id_dir': '1x1x1/1', 'bias': -4, 'description': "adding bias"}]
listlayers = l2.rpc.askrene_listlayers('test_layers')
assert listlayers == {'layers': [expect]}
l2.rpc.askrene_bias_channel(layer='test_layers', short_channel_id_dir='1x1x1/1', bias=-1, relative=True)
expect['biases'] = [{'short_channel_id_dir': '1x1x1/1', 'bias': -5}]
listlayers = l2.rpc.askrene_listlayers('test_layers')
assert listlayers == {'layers': [expect]}
# They truncate on +/- 100 though:
l2.rpc.askrene_bias_channel('test_layers', '1x1x1/1', -99, None, True)
expect['biases'] = [{'short_channel_id_dir': '1x1x1/1', 'bias': -100}]
listlayers = l2.rpc.askrene_listlayers('test_layers')
assert listlayers == {'layers': [expect]}
# We can remove them.
l2.rpc.askrene_bias_channel('test_layers', '1x1x1/1', 0)
expect['biases'] = []