mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-06 06:34:22 +01:00
gossipd: put ->daemon pointer into routing_state.
They're closely tied, and duplicating fields was really ugly. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -812,8 +812,7 @@ static void gossip_init(struct daemon *daemon, const u8 *msg)
|
||||
}
|
||||
|
||||
daemon->rstate = new_routing_state(daemon,
|
||||
&daemon->id,
|
||||
&daemon->timers,
|
||||
daemon,
|
||||
take(dev_gossip_time),
|
||||
dev_fast_gossip,
|
||||
dev_fast_gossip_prune);
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <common/wire_error.h>
|
||||
#include <gossipd/gossip_generation.h>
|
||||
#include <gossipd/gossip_store_wiregen.h>
|
||||
#include <gossipd/gossipd.h>
|
||||
#include <gossipd/gossipd_wiregen.h>
|
||||
#include <gossipd/routing.h>
|
||||
|
||||
@@ -250,7 +249,7 @@ static void txout_failure_age(struct routing_state *rstate)
|
||||
uintmap_init(&rstate->txout_failures);
|
||||
rstate->num_txout_failures = 0;
|
||||
|
||||
rstate->txout_failure_timer = new_reltimer(rstate->timers,
|
||||
rstate->txout_failure_timer = new_reltimer(&rstate->daemon->timers,
|
||||
rstate, time_from_sec(3600),
|
||||
txout_failure_age, rstate);
|
||||
}
|
||||
@@ -280,16 +279,14 @@ static bool in_txout_failures(struct routing_state *rstate,
|
||||
}
|
||||
|
||||
struct routing_state *new_routing_state(const tal_t *ctx,
|
||||
const struct node_id *local_id,
|
||||
struct timers *timers,
|
||||
struct daemon *daemon,
|
||||
const u32 *dev_gossip_time TAKES,
|
||||
bool dev_fast_gossip,
|
||||
bool dev_fast_gossip_prune)
|
||||
{
|
||||
struct routing_state *rstate = tal(ctx, struct routing_state);
|
||||
rstate->daemon = daemon;
|
||||
rstate->nodes = new_node_map(rstate);
|
||||
rstate->timers = timers;
|
||||
rstate->local_id = *local_id;
|
||||
rstate->gs = gossip_store_new(rstate);
|
||||
rstate->local_channel_announced = false;
|
||||
rstate->last_timestamp = 0;
|
||||
@@ -2101,14 +2098,14 @@ bool routing_add_private_channel(struct routing_state *rstate,
|
||||
/* Make sure this id (if any) was allowed to create this */
|
||||
if (id) {
|
||||
struct node_id expected[2];
|
||||
int cmp = node_id_cmp(&rstate->local_id, id);
|
||||
int cmp = node_id_cmp(&rstate->daemon->id, id);
|
||||
|
||||
if (cmp < 0) {
|
||||
expected[0] = rstate->local_id;
|
||||
expected[0] = rstate->daemon->id;
|
||||
expected[1] = *id;
|
||||
} else if (cmp > 0) {
|
||||
expected[0] = *id;
|
||||
expected[1] = rstate->local_id;
|
||||
expected[1] = rstate->daemon->id;
|
||||
} else {
|
||||
/* lightningd sets id, so this is fatal */
|
||||
status_failed(STATUS_FAIL_MASTER_IO,
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <common/route.h>
|
||||
#include <gossipd/broadcast.h>
|
||||
#include <gossipd/gossip_store.h>
|
||||
#include <gossipd/gossipd.h>
|
||||
#include <wire/onion_wire.h>
|
||||
#include <wire/wire.h>
|
||||
|
||||
@@ -196,8 +197,7 @@ static inline int half_chan_idx(const struct node *n, const struct chan *chan)
|
||||
}
|
||||
|
||||
struct routing_state {
|
||||
/* TImers base from struct gossipd. */
|
||||
struct timers *timers;
|
||||
struct daemon *daemon;
|
||||
|
||||
/* All known nodes. */
|
||||
struct node_map *nodes;
|
||||
@@ -211,9 +211,6 @@ struct routing_state {
|
||||
/* Gossip store */
|
||||
struct gossip_store *gs;
|
||||
|
||||
/* Our own ID so we can identify local channels */
|
||||
struct node_id local_id;
|
||||
|
||||
/* A map of channels indexed by short_channel_ids */
|
||||
UINTMAP(struct chan *) chanmap;
|
||||
|
||||
@@ -254,7 +251,7 @@ static inline bool local_direction(struct routing_state *rstate,
|
||||
int *direction)
|
||||
{
|
||||
for (int dir = 0; dir <= 1; (dir)++) {
|
||||
if (node_id_eq(&chan->nodes[dir]->id, &rstate->local_id)) {
|
||||
if (node_id_eq(&chan->nodes[dir]->id, &rstate->daemon->id)) {
|
||||
if (direction)
|
||||
*direction = dir;
|
||||
return true;
|
||||
@@ -271,8 +268,7 @@ get_channel(const struct routing_state *rstate,
|
||||
}
|
||||
|
||||
struct routing_state *new_routing_state(const tal_t *ctx,
|
||||
const struct node_id *local_id,
|
||||
struct timers *timers,
|
||||
struct daemon *daemon,
|
||||
const u32 *dev_gossip_time TAKES,
|
||||
bool dev_fast_gossip,
|
||||
bool dev_fast_gossip_prune);
|
||||
|
||||
@@ -108,16 +108,15 @@ struct gossip_store *gossip_store_new(struct routing_state *rstate UNNEEDED)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct routing_state *rstate;
|
||||
struct timers timers;
|
||||
struct timer *t;
|
||||
struct short_channel_id scid1, scid2;
|
||||
struct daemon *daemon;
|
||||
|
||||
common_setup(argv[0]);
|
||||
|
||||
timers_init(&timers, time_mono());
|
||||
/* Random uninitalized node_id, we don't reference it. */
|
||||
rstate = new_routing_state(tmpctx, tal(tmpctx, struct node_id),
|
||||
&timers, NULL, false, false);
|
||||
daemon = tal(tmpctx, struct daemon);
|
||||
timers_init(&daemon->timers, time_mono());
|
||||
rstate = new_routing_state(tmpctx, daemon, NULL, false, false);
|
||||
|
||||
scid1.u64 = 100;
|
||||
scid2.u64 = 200;
|
||||
@@ -135,8 +134,9 @@ int main(int argc, char *argv[])
|
||||
assert(rstate->num_txout_failures == 2);
|
||||
|
||||
/* Move time forward 1 hour. */
|
||||
t = timers_expire(&timers, timemono_add(time_mono(),
|
||||
time_from_sec(3601)));
|
||||
t = timers_expire(&daemon->timers,
|
||||
timemono_add(time_mono(),
|
||||
time_from_sec(3601)));
|
||||
assert(t);
|
||||
timer_expired(t);
|
||||
|
||||
@@ -145,8 +145,9 @@ int main(int argc, char *argv[])
|
||||
assert(in_txout_failures(rstate, &scid1));
|
||||
assert(rstate->num_txout_failures == 1);
|
||||
|
||||
t = timers_expire(&timers, timemono_add(time_mono(),
|
||||
time_from_sec(3601)));
|
||||
t = timers_expire(&daemon->timers,
|
||||
timemono_add(time_mono(),
|
||||
time_from_sec(3601)));
|
||||
assert(t);
|
||||
timer_expired(t);
|
||||
|
||||
@@ -155,7 +156,9 @@ int main(int argc, char *argv[])
|
||||
assert(rstate->num_txout_failures == 1);
|
||||
assert(!in_txout_failures(rstate, &scid2));
|
||||
|
||||
tal_free(rstate);
|
||||
timers_cleanup(&daemon->timers);
|
||||
common_shutdown();
|
||||
timers_cleanup(&timers);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user