gossipd: increase randomness in route selection.

We have a seed, which is for (future!) unit testing consistency.  This
makes it change every time, so our pay_direct_test is more useful.

I tried restarting the noed around the loop, but it tended to fail
rebinding to the same port for some reason?

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-02-01 13:06:18 +10:30
committed by Christian Decker
parent 38a2f6c616
commit 6a26b0c18d
5 changed files with 19 additions and 4 deletions

View File

@@ -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();

View File

@@ -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.
*/

View File

@@ -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));

View File

@@ -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++) {

View File

@@ -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. */