From cf52b7161f164e96376794862bdb3b14cd4177ec Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 17 Sep 2018 03:45:01 +0200 Subject: [PATCH] json-rpc: Remove upper limit for percentage The `json_tok_percentage` parser is used for the `fuzzpercent` in `getroute` and `maxfeepercent` in `pay`. In both cases it seems reasonable to allow values larger than 100%. This has bitten users in the past when they transferred single satoshis to things like satoshis.place over a route longer than 2 hops. --- lightningd/gossip_control.c | 2 +- lightningd/json.c | 7 +++---- lightningd/test/run-param.c | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 83357b59e..39e91ad4c 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -327,7 +327,7 @@ static const struct json_command getroute_command = { json_getroute, "Show route to {id} for {msatoshi}, using {riskfactor} and optional {cltv} (default 9). " "If specified search from {fromid} otherwise use this node as source. " - "Randomize the route with up to {fuzzpercent} (0.0 -> 100.0, default 5.0) " + "Randomize the route with up to {fuzzpercent} (default 5.0) " "using {seed} as an arbitrary-size string seed." }; AUTODATA(json_command, &getroute_command); diff --git a/lightningd/json.c b/lightningd/json.c index d99ab9ec1..b0ac53246 100644 --- a/lightningd/json.c +++ b/lightningd/json.c @@ -238,12 +238,11 @@ bool json_tok_percent(struct command *cmd, const char *name, double **num) { *num = tal(cmd, double); - if (json_to_double(buffer, tok, *num)) - if (**num >= 0.0 && **num <= 100.0) - return true; + if (json_to_double(buffer, tok, *num) && **num >= 0.0) + return true; command_fail(cmd, JSONRPC2_INVALID_PARAMS, - "'%s' should be a double in range [0.0, 100.0], not '%.*s'", + "'%s' should be a positive double, not '%.*s'", name, tok->end - tok->start, buffer + tok->start); return false; } diff --git a/lightningd/test/run-param.c b/lightningd/test/run-param.c index 6b6576ec5..033ec56dd 100644 --- a/lightningd/test/run-param.c +++ b/lightningd/test/run-param.c @@ -502,8 +502,8 @@ static void json_tok_tests(void) test_cb(json_tok_percent, double, "[ 1.01 ]", 1.01, true); test_cb(json_tok_percent, double, "[ 99.99 ]", 99.99, true); test_cb(json_tok_percent, double, "[ 100.0 ]", 100, true); - test_cb(json_tok_percent, double, "[ 100.001 ]", 0, false); - test_cb(json_tok_percent, double, "[ 1000 ]", 0, false); + test_cb(json_tok_percent, double, "[ 100.001 ]", 100.001, true); + test_cb(json_tok_percent, double, "[ 1000 ]", 1000, true); test_cb(json_tok_percent, double, "[ 'wow' ]", 0, false); }