From 662bb0c565ae668b0c52e2dfd35fce770e57ed01 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 1 Feb 2019 16:23:38 +1030 Subject: [PATCH] gossipd: fix riskfactor passing. We used a u16, and a 1000 multiplier, which meant we wrapped at riskfactor 66. We also never undid the multiplier, so we ended up applying 1000x the riskfactor they specified. This changes us to pass the riskfactor with a 1M multiplier. The next patch changes the definition of riskfactor to be more useful. Signed-off-by: Rusty Russell --- gossipd/gossip_wire.csv | 3 ++- gossipd/gossipd.c | 6 +++--- lightningd/gossip_control.c | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/gossipd/gossip_wire.csv b/gossipd/gossip_wire.csv index 658f54681390..e86f1260ec83 100644 --- a/gossipd/gossip_wire.csv +++ b/gossipd/gossip_wire.csv @@ -29,7 +29,8 @@ gossip_getroute_request,3006 gossip_getroute_request,,source,struct pubkey gossip_getroute_request,,destination,struct pubkey gossip_getroute_request,,msatoshi,u64 -gossip_getroute_request,,riskfactor,u16 +# We don't pass doubles, so pass riskfactor * 1000000. +gossip_getroute_request,,riskfactor_by_million,u64 gossip_getroute_request,,final_cltv,u32 gossip_getroute_request,,fuzz,double gossip_getroute_request,,num_excluded,u16 diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index 73502022885b..556e12aedd3f 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -1894,7 +1894,7 @@ static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon, struct pubkey source, destination; u64 msatoshi; u32 final_cltv; - u16 riskfactor; + u64 riskfactor_by_million; u32 max_hops; u8 *out; struct route_hop *hops; @@ -1909,7 +1909,7 @@ static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon, * avoid being too predictable. */ if (!fromwire_gossip_getroute_request(msg, msg, &source, &destination, - &msatoshi, &riskfactor, + &msatoshi, &riskfactor_by_million, &final_cltv, &fuzz, &excluded, &max_hops)) @@ -1921,7 +1921,7 @@ static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon, /* routing.c does all the hard work; can return NULL. */ hops = get_route(tmpctx, daemon->rstate, &source, &destination, - msatoshi, riskfactor, final_cltv, + msatoshi, riskfactor_by_million / 1000000.0, final_cltv, fuzz, pseudorand_u64(), excluded, max_hops); out = towire_gossip_getroute_reply(NULL, hops); diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 3fc0a18ffaee..1b2a9b30fb54 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -352,7 +352,8 @@ static struct command_result *json_getroute(struct command *cmd, } u8 *req = towire_gossip_getroute_request(cmd, source, destination, - *msatoshi, *riskfactor * 1000, + *msatoshi, + *riskfactor * 1000000.0, *cltv, fuzz, excluded, *max_hops);