Skip to content

Commit b871ea0

Browse files
committed
askrene: don't crash if asked to route 0 msat.
But don't allow it either. ``` Jan 19 13:18:52 boltz lightningd[2259911]: cln-askrene: plugins/askrene/algorithm.c:274: simple_feasibleflow: Assertion `amount > 0' failed. Jan 19 13:18:52 boltz lightningd[2259911]: cln-askrene: FATAL SIGNAL 6 (version v24.11.1-1-ge9dbdeb) Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e212b407 send_backtrace Jan 19 13:18:52 boltz lightningd[2259911]: common/daemon.c:33 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e212b49e crashdump Jan 19 13:18:52 boltz lightningd[2259911]: common/daemon.c:75 Jan 19 13:18:52 boltz lightningd[2259911]: 0x7f964ba9251f ??? Jan 19 13:18:52 boltz lightningd[2259911]: ???:0 Jan 19 13:18:52 boltz lightningd[2259911]: 0x7f964bae69fc ??? Jan 19 13:18:52 boltz lightningd[2259911]: ???:0 Jan 19 13:18:52 boltz lightningd[2259911]: 0x7f964ba92475 ??? Jan 19 13:18:52 boltz lightningd[2259911]: ???:0 Jan 19 13:18:52 boltz lightningd[2259911]: 0x7f964ba787f2 ??? Jan 19 13:18:52 boltz lightningd[2259911]: ???:0 Jan 19 13:18:52 boltz lightningd[2259911]: 0x7f964ba7871a ??? Jan 19 13:18:52 boltz lightningd[2259911]: ???:0 Jan 19 13:18:52 boltz lightningd[2259911]: 0x7f964ba89e95 ??? Jan 19 13:18:52 boltz lightningd[2259911]: ???:0 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e211695e simple_feasibleflow Jan 19 13:18:52 boltz lightningd[2259911]: plugins/askrene/algorithm.c:274 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e2111495 minflow Jan 19 13:18:52 boltz lightningd[2259911]: plugins/askrene/mcf.c:1014 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e210bc74 get_routes Jan 19 13:18:52 boltz lightningd[2259911]: plugins/askrene/askrene.c:414 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e210c610 do_getroutes Jan 19 13:18:52 boltz lightningd[2259911]: plugins/askrene/askrene.c:615 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e210cad8 listpeerchannels_done Jan 19 13:18:52 boltz lightningd[2259911]: plugins/askrene/askrene.c:741 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e211b35a handle_rpc_reply Jan 19 13:18:52 boltz lightningd[2259911]: plugins/libplugin.c:1084 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e211b54c rpc_read_response_one Jan 19 13:18:52 boltz lightningd[2259911]: plugins/libplugin.c:1388 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e211b5fd rpc_conn_read_response Jan 19 13:18:52 boltz lightningd[2259911]: plugins/libplugin.c:1412 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e214fe8f next_plan Jan 19 13:18:52 boltz lightningd[2259911]: ccan/ccan/io/io.c:60 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e215036e do_plan Jan 19 13:18:52 boltz lightningd[2259911]: ccan/ccan/io/io.c:422 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e215042b io_ready Jan 19 13:18:52 boltz lightningd[2259911]: ccan/ccan/io/io.c:439 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e2151e2e io_loop Jan 19 13:18:52 boltz lightningd[2259911]: ccan/ccan/io/poll.c:455 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e211cc29 plugin_main Jan 19 13:18:52 boltz lightningd[2259911]: plugins/libplugin.c:2488 Jan 19 13:18:52 boltz lightningd[2259911]: 0x5576e210cb38 main Jan 19 13:18:52 boltz lightningd[2259911]: plugins/askrene/askrene.c:1262 Jan 19 13:18:52 boltz lightningd[2259911]: 0x7f964ba79d8f ??? ``` Signed-off-by: Rusty Russell <[email protected]> Changelog-Fixed: JSON-RPC: `getroutes` will refuse, not crash, if asked to find a route fr 0msat.
1 parent 54ee08b commit b871ea0

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

plugins/askrene/askrene.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -755,18 +755,26 @@ static struct command_result *json_getroutes(struct command *cmd,
755755
const u32 maxdelay_allowed = 2016;
756756
struct getroutes_info *info = tal(cmd, struct getroutes_info);
757757

758-
if (!param(cmd, buffer, params,
759-
p_req("source", param_node_id, &info->source),
760-
p_req("destination", param_node_id, &info->dest),
761-
p_req("amount_msat", param_msat, &info->amount),
762-
p_req("layers", param_layer_names, &info->layers),
763-
p_req("maxfee_msat", param_msat, &info->maxfee),
764-
p_req("final_cltv", param_u32, &info->finalcltv),
765-
p_opt_def("maxdelay", param_u32, &info->maxdelay,
766-
maxdelay_allowed),
767-
NULL))
758+
if (!param_check(cmd, buffer, params,
759+
p_req("source", param_node_id, &info->source),
760+
p_req("destination", param_node_id, &info->dest),
761+
p_req("amount_msat", param_msat, &info->amount),
762+
p_req("layers", param_layer_names, &info->layers),
763+
p_req("maxfee_msat", param_msat, &info->maxfee),
764+
p_req("final_cltv", param_u32, &info->finalcltv),
765+
p_opt_def("maxdelay", param_u32, &info->maxdelay,
766+
maxdelay_allowed),
767+
NULL))
768768
return command_param_failed();
769769

770+
if (amount_msat_is_zero(*info->amount)) {
771+
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
772+
"amount must be non-zero");
773+
}
774+
775+
if (command_check_only(cmd))
776+
return command_check_done(cmd);
777+
770778
if (*info->maxdelay > maxdelay_allowed) {
771779
return command_fail(cmd, PAY_USER_ERROR,
772780
"maximum delay allowed is %d",

tests/test_askrene.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,17 @@ def test_limits_fake_gossmap(node_factory, bitcoind):
986986
# Must deliver exact amount.
987987
assert sum(r['amount_msat'] for r in routes["routes"]) == 800_000_001
988988

989+
# Won't evaluate route for 0msat.
990+
with pytest.raises(RpcError, match="amount must be non-zero"):
991+
l1.rpc.getroutes(
992+
source=nodemap[0],
993+
destination=nodemap[2],
994+
amount_msat=0,
995+
layers=["localchans", "auto.sourcefree"],
996+
maxfee_msat=50_000_000,
997+
final_cltv=10,
998+
)
999+
9891000

9901001
def test_max_htlc(node_factory, bitcoind):
9911002
"""A route which looks good isn't actually, because of max htlc limits"""

0 commit comments

Comments
 (0)