Browse Source

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>
fix-test_pay_direct-flake
Rusty Russell 6 years ago
committed by Christian Decker
parent
commit
6a26b0c18d
  1. 7
      common/pseudorand.c
  2. 5
      common/pseudorand.h
  3. 2
      gossipd/gossipd.c
  4. 7
      gossipd/routing.c
  5. 2
      gossipd/routing.h

7
common/pseudorand.c

@ -37,6 +37,13 @@ uint64_t pseudorand(uint64_t max)
return isaac64_next_uint(&isaac64, 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) const struct siphash_seed *siphash_seed(void)
{ {
init_if_needed(); init_if_needed();

5
common/pseudorand.h

@ -8,6 +8,11 @@
*/ */
uint64_t pseudorand(uint64_t max); 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. * Get the siphash seed for hash tables.
*/ */

2
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. */ /* routing.c does all the hard work; can return NULL. */
hops = get_route(tmpctx, daemon->rstate, &source, &destination, hops = get_route(tmpctx, daemon->rstate, &source, &destination,
msatoshi, riskfactor, final_cltv, msatoshi, riskfactor, final_cltv,
fuzz, siphash_seed(), excluded, max_hops); fuzz, pseudorand_u64(), excluded, max_hops);
out = towire_gossip_getroute_reply(NULL, hops); out = towire_gossip_getroute_reply(NULL, hops);
daemon_conn_send(daemon->master, take(out)); daemon_conn_send(daemon->master, take(out));

7
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 struct pubkey *destination,
const u64 msatoshi, double riskfactor, const u64 msatoshi, double riskfactor,
u32 final_cltv, u32 final_cltv,
double fuzz, const struct siphash_seed *base_seed, double fuzz, u64 seed,
const struct short_channel_id_dir *excluded, const struct short_channel_id_dir *excluded,
size_t max_hops) 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 route_hop *hops;
struct node *n; struct node *n;
u64 *saved_capacity; u64 *saved_capacity;
struct siphash_seed base_seed;
saved_capacity = tal_arr(tmpctx, u64, tal_count(excluded)); 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. */ /* Temporarily set excluded channels' capacity to zero. */
for (size_t i = 0; i < tal_count(excluded); i++) { for (size_t i = 0; i < tal_count(excluded); i++) {
struct chan *chan = get_channel(rstate, &excluded[i].scid); 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, route = find_route(ctx, rstate, source, destination, msatoshi,
riskfactor / BLOCKS_PER_YEAR / 10000, riskfactor / BLOCKS_PER_YEAR / 10000,
fuzz, base_seed, max_hops, &fee); fuzz, &base_seed, max_hops, &fee);
/* Now restore the capacity. */ /* Now restore the capacity. */
for (size_t i = 0; i < tal_count(excluded); i++) { for (size_t i = 0; i < tal_count(excluded); i++) {

2
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, const u64 msatoshi, double riskfactor,
u32 final_cltv, u32 final_cltv,
double fuzz, double fuzz,
const struct siphash_seed *base_seed, u64 seed,
const struct short_channel_id_dir *excluded, const struct short_channel_id_dir *excluded,
size_t max_hops); size_t max_hops);
/* Disable channel(s) based on the given routing failure. */ /* Disable channel(s) based on the given routing failure. */

Loading…
Cancel
Save