Skip to content

Commit 40aad27

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 b6c1ffa commit 40aad27

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

plugins/askrene/askrene.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -753,16 +753,24 @@ static struct command_result *json_getroutes(struct command *cmd,
753753
{
754754
struct getroutes_info *info = tal(cmd, struct getroutes_info);
755755

756-
if (!param(cmd, buffer, params,
757-
p_req("source", param_node_id, &info->source),
758-
p_req("destination", param_node_id, &info->dest),
759-
p_req("amount_msat", param_msat, &info->amount),
760-
p_req("layers", param_layer_names, &info->layers),
761-
p_req("maxfee_msat", param_msat, &info->maxfee),
762-
p_req("final_cltv", param_u32, &info->finalcltv),
763-
NULL))
756+
if (!param_check(cmd, buffer, params,
757+
p_req("source", param_node_id, &info->source),
758+
p_req("destination", param_node_id, &info->dest),
759+
p_req("amount_msat", param_msat, &info->amount),
760+
p_req("layers", param_layer_names, &info->layers),
761+
p_req("maxfee_msat", param_msat, &info->maxfee),
762+
p_req("final_cltv", param_u32, &info->finalcltv),
763+
NULL))
764764
return command_param_failed();
765765

766+
if (amount_msat_is_zero(*info->amount)) {
767+
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
768+
"amount must be non-zero");
769+
}
770+
771+
if (command_check_only(cmd))
772+
return command_check_done(cmd);
773+
766774
info->cmd = cmd;
767775
info->additional_costs = tal(info, struct additional_cost_htable);
768776
additional_cost_htable_init(info->additional_costs);

tests/test_askrene.py

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

940+
# Won't evaluate route for 0msat.
941+
with pytest.raises(RpcError, match="amount must be non-zero"):
942+
l1.rpc.getroutes(
943+
source=nodemap[0],
944+
destination=nodemap[2],
945+
amount_msat=0,
946+
layers=["localchans", "auto.sourcefree"],
947+
maxfee_msat=50_000_000,
948+
final_cltv=10,
949+
)
950+
940951

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

0 commit comments

Comments
 (0)