Skip to content

Commit 9ce3f5d

Browse files
committed
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 556e38c ("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.
1 parent 628d002 commit 9ce3f5d

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

contrib/msggen/msggen/schema.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,19 +309,19 @@
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+
"description": {
313+
"type": "string",
314+
"description": [
315+
"Description/annotation to display in askrene-listlayers(7)"
316+
]
317+
},
312318
"relative": {
313319
"type": "boolean",
314320
"added": "v25.05",
315321
"default": false,
316322
"description": [
317323
"The bias will be added to the previous value."
318324
]
319-
},
320-
"description": {
321-
"type": "string",
322-
"description": [
323-
"Description/annotation to display in askrene-listlayers(7)"
324-
]
325325
}
326326
}
327327
},

doc/schemas/askrene-bias-channel.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@
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+
"description": {
37+
"type": "string",
38+
"description": [
39+
"Description/annotation to display in askrene-listlayers(7)"
40+
]
41+
},
3642
"relative": {
3743
"type": "boolean",
3844
"added": "v25.05",
3945
"default": false,
4046
"description": [
4147
"The bias will be added to the previous value."
4248
]
43-
},
44-
"description": {
45-
"type": "string",
46-
"description": [
47-
"Description/annotation to display in askrene-listlayers(7)"
48-
]
4949
}
5050
}
5151
},

plugins/askrene/askrene.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,8 +1104,8 @@ static struct command_result *json_askrene_bias_channel(struct command *cmd,
11041104
p_req("layer", param_known_layer, &layer),
11051105
p_req("short_channel_id_dir", param_short_channel_id_dir, &scidd),
11061106
p_req("bias", param_s8_hundred, &bias),
1107-
p_opt_def("relative", param_bool, &relative, false),
11081107
p_opt("description", param_string, &description),
1108+
p_opt_def("relative", param_bool, &relative, false),
11091109
NULL))
11101110
return command_param_failed();
11111111
plugin_log(cmd->plugin, LOG_TRACE, "%s called: %.*s", __func__,

tests/test_askrene.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,23 @@ def test_layers(node_factory):
277277
with pytest.raises(RpcError, match="bias: should be a number between -100 and 100"):
278278
l2.rpc.askrene_bias_channel('test_layers', '1x1x1/1', 101, "bigger bias")
279279

280+
# We can make them relative.
281+
l2.rpc.askrene_bias_channel('test_layers', '1x1x1/1', 1, 'adding bias', True)
282+
expect['biases'] = [{'short_channel_id_dir': '1x1x1/1', 'bias': -4, 'description': "adding bias"}]
283+
listlayers = l2.rpc.askrene_listlayers('test_layers')
284+
assert listlayers == {'layers': [expect]}
285+
286+
l2.rpc.askrene_bias_channel(layer='test_layers', short_channel_id_dir='1x1x1/1', bias=-1, relative=True)
287+
expect['biases'] = [{'short_channel_id_dir': '1x1x1/1', 'bias': -5}]
288+
listlayers = l2.rpc.askrene_listlayers('test_layers')
289+
assert listlayers == {'layers': [expect]}
290+
291+
# They truncate on +/- 100 though:
292+
l2.rpc.askrene_bias_channel('test_layers', '1x1x1/1', -99, None, True)
293+
expect['biases'] = [{'short_channel_id_dir': '1x1x1/1', 'bias': -100}]
294+
listlayers = l2.rpc.askrene_listlayers('test_layers')
295+
assert listlayers == {'layers': [expect]}
296+
280297
# We can remove them.
281298
l2.rpc.askrene_bias_channel('test_layers', '1x1x1/1', 0)
282299
expect['biases'] = []

0 commit comments

Comments
 (0)