diff --git a/common/pseudorand.c b/common/pseudorand.c index dc8f6b17b..817a9e5bf 100644 --- a/common/pseudorand.c +++ b/common/pseudorand.c @@ -37,6 +37,13 @@ uint64_t pseudorand(uint64_t max) return isaac64_next_uint(&isaac64, max); } +uint64_t pseudorand_u64(void) +{ + init_if_needed(); + + return isaac64_next_uint64(&isaac64); +} + const struct siphash_seed *siphash_seed(void) { init_if_needed(); diff --git a/common/pseudorand.h b/common/pseudorand.h index d66435ed4..0a46223bf 100644 --- a/common/pseudorand.h +++ b/common/pseudorand.h @@ -8,6 +8,11 @@ */ uint64_t pseudorand(uint64_t max); +/** + * pseudorand - pseudo (guessable!) random number between 0 and UINT64_MAX. + */ +uint64_t pseudorand_u64(void); + /** * Get the siphash seed for hash tables. */ diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index 9289f6a57..735020228 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -1922,7 +1922,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, - fuzz, siphash_seed(), excluded, max_hops); + fuzz, pseudorand_u64(), excluded, max_hops); out = towire_gossip_getroute_reply(NULL, hops); daemon_conn_send(daemon->master, take(out)); diff --git a/gossipd/routing.c b/gossipd/routing.c index c9ce2ad99..1a23dd8c8 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -1496,7 +1496,7 @@ struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate, const struct pubkey *destination, const u64 msatoshi, double riskfactor, u32 final_cltv, - double fuzz, const struct siphash_seed *base_seed, + double fuzz, u64 seed, const struct short_channel_id_dir *excluded, size_t max_hops) { @@ -1507,9 +1507,12 @@ struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate, struct route_hop *hops; struct node *n; u64 *saved_capacity; + struct siphash_seed base_seed; saved_capacity = tal_arr(tmpctx, u64, tal_count(excluded)); + base_seed.u.u64[0] = base_seed.u.u64[1] = seed; + /* Temporarily set excluded channels' capacity to zero. */ for (size_t i = 0; i < tal_count(excluded); i++) { struct chan *chan = get_channel(rstate, &excluded[i].scid); @@ -1522,7 +1525,7 @@ struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate, route = find_route(ctx, rstate, source, destination, msatoshi, riskfactor / BLOCKS_PER_YEAR / 10000, - fuzz, base_seed, max_hops, &fee); + fuzz, &base_seed, max_hops, &fee); /* Now restore the capacity. */ for (size_t i = 0; i < tal_count(excluded); i++) { diff --git a/gossipd/routing.h b/gossipd/routing.h index 80c762243..038a9ea5a 100644 --- a/gossipd/routing.h +++ b/gossipd/routing.h @@ -264,7 +264,7 @@ struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate, const u64 msatoshi, double riskfactor, u32 final_cltv, double fuzz, - const struct siphash_seed *base_seed, + u64 seed, const struct short_channel_id_dir *excluded, size_t max_hops); /* Disable channel(s) based on the given routing failure. */