From 9ce3f5dde4a3ee63e7f35c6bbd647daa87fbbce8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 10 May 2025 20:11:47 +0930 Subject: [PATCH] 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 556e38c8388ffd7cdf832e83d2a191796accd5cb ("askrene-bias-channel: bias call add up."). Also add tests, and a better Changelog line. Signed-off-by: Rusty Russell Changelog-Added: JSON-RPC: `askrene-bias-channel` now has a `relative` option to add, rather than replace, a channel bias. --- contrib/msggen/msggen/schema.json | 12 ++++++------ doc/schemas/askrene-bias-channel.json | 12 ++++++------ plugins/askrene/askrene.c | 2 +- tests/test_askrene.py | 17 +++++++++++++++++ 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/contrib/msggen/msggen/schema.json b/contrib/msggen/msggen/schema.json index 15babcb2f..18a81d7ba 100644 --- a/contrib/msggen/msggen/schema.json +++ b/contrib/msggen/msggen/schema.json @@ -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)" - ] } } }, diff --git a/doc/schemas/askrene-bias-channel.json b/doc/schemas/askrene-bias-channel.json index 1e3091336..73eddb5bf 100644 --- a/doc/schemas/askrene-bias-channel.json +++ b/doc/schemas/askrene-bias-channel.json @@ -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)" - ] } } }, diff --git a/plugins/askrene/askrene.c b/plugins/askrene/askrene.c index 0e2f2f3fc..14a6e8964 100644 --- a/plugins/askrene/askrene.c +++ b/plugins/askrene/askrene.c @@ -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__, diff --git a/tests/test_askrene.py b/tests/test_askrene.py index 7404d4664..1c3787c0d 100644 --- a/tests/test_askrene.py +++ b/tests/test_askrene.py @@ -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'] = []