Skip to content

Commit

Permalink
gossipd: fix riskfactor passing.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Feb 6, 2019
1 parent 706debf commit 662bb0c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion gossipd/gossip_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 662bb0c

Please sign in to comment.