Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 9 additions & 26 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*~ Welcome to the gossip daemon: keeper of maps!
*
* This is the last "global" daemon; it has three purposes.
* This is the last "global" daemon; it has one main purpose: to
* maintain the append-only gossip_store file for other daemons and
* plugins to read the global network map.
*
* 1. To determine routes for payments when lightningd asks.
* 2. The second purpose is to receive gossip from peers (via their
* per-peer daemons) and send it out to them.
* 3. Talk to `connectd` to to answer address queries for nodes.
* To do this, it gets gossip messages forwarded from connectd, makes
* gossip queries to peers, and can ask connect out to random peers to
* get more gossip.
*
* The gossip protocol itself is fairly simple, but has some twists which
* add complexity to this daemon.
Expand All @@ -14,7 +15,6 @@
#include <ccan/tal/str/str.h>
#include <common/clock_time.h>
#include <common/daemon_conn.h>
#include <common/ecdh_hsmd.h>
#include <common/memleak.h>
#include <common/status.h>
#include <common/subdaemon.h>
Expand Down Expand Up @@ -368,21 +368,6 @@ static void master_or_connectd_gone(struct daemon_conn *dc UNUSED)
exit(2);
}

/* We don't check this when loading from the gossip_store: that would break
* our canned tests, and usually old gossip is better than no gossip */
bool timestamp_reasonable(const struct daemon *daemon, u32 timestamp)
{
u64 now = clock_time().ts.tv_sec;

/* More than one day ahead? */
if (timestamp > now + 24*60*60)
return false;
/* More than 2 weeks behind? */
if (timestamp < now - GOSSIP_PRUNE_INTERVAL(daemon->dev_fast_gossip_prune))
return false;
return true;
}

/*~ Parse init message from lightningd: starts the daemon properly. */
static void gossip_init(struct daemon *daemon, const u8 *msg)
{
Expand Down Expand Up @@ -591,9 +576,6 @@ int main(int argc, char *argv[])
daemon->deferred_txouts = tal_arr(daemon, struct short_channel_id, 0);
daemon->current_blockheight = 0; /* i.e. unknown */

/* Tell the ecdh() function how to talk to hsmd */
ecdh_hsmd_setup(HSM_FD, status_failed);

/* Note the use of time_mono() here. That's a monotonic clock, which
* is really useful: it can only be used to measure relative events
* (there's no correspondence to time-since-Ken-grew-a-beard or
Expand All @@ -620,8 +602,9 @@ int main(int argc, char *argv[])
}
}

/*~ Note that the actual routing stuff is in routing.c; you might want to
* check that out later.
/*~ Note that the production of the gossip_store file is in gossmap_manage.c
* and gossip_store.c, and the (highly optimized!) read side is in
* common/gossmap.c; you might want to check those out later.
*
* But that's the last of the global daemons. We now move on to the first of
* the per-peer daemons: openingd/openingd.c.
Expand Down
12 changes: 2 additions & 10 deletions gossipd/gossipd.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
#include <lightningd/options.h>
#include <wire/peer_wire.h>

/* We talk to `hsmd` to sign our gossip messages with the node key */
#define HSM_FD 3
/* connectd asks us for help finding nodes, and gossip fds for new peers */
#define CONNECTD_FD 4
#define CONNECTD2_FD 5
/* connectd forwards gossip messages to us. */
#define CONNECTD_FD 3

struct chan;
struct peer;
Expand Down Expand Up @@ -161,9 +158,4 @@ void tell_lightningd_peer_update(struct daemon *daemon,
struct amount_msat htlc_minimum,
struct amount_msat htlc_maximum);

/**
* Is this gossip timestamp reasonable?
*/
bool timestamp_reasonable(const struct daemon *daemon, u32 timestamp);

#endif /* LIGHTNING_GOSSIPD_GOSSIPD_H */
15 changes: 15 additions & 0 deletions gossipd/gossmap_manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,21 @@ static const char *process_channel_update(const tal_t *ctx,
return NULL;
}

/* We don't check this when loading from the gossip_store: that would break
* our canned tests, and usually old gossip is better than no gossip */
static bool timestamp_reasonable(const struct daemon *daemon, u32 timestamp)
{
u64 now = clock_time().ts.tv_sec;

/* More than one day ahead? */
if (timestamp > now + 24*60*60)
return false;
/* More than 2 weeks behind? */
if (timestamp < now - GOSSIP_PRUNE_INTERVAL(daemon->dev_fast_gossip_prune))
return false;
return true;
}

const char *gossmap_manage_channel_update(const tal_t *ctx,
struct gossmap_manage *gm,
const u8 *update TAKES,
Expand Down
5 changes: 1 addition & 4 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,11 @@ static void gossipd_init_done(struct subd *gossipd,
void gossip_init(struct lightningd *ld, int connectd_fd)
{
u8 *msg;
int hsmfd;
void *ret;

hsmfd = hsm_get_global_fd(ld, HSM_PERM_ECDH|HSM_PERM_SIGN_GOSSIP);

ld->gossip = new_global_subd(ld, "lightning_gossipd",
gossipd_wire_name, gossip_msg,
take(&hsmfd), take(&connectd_fd), NULL);
take(&connectd_fd), NULL);
if (!ld->gossip)
err(1, "Could not subdaemon gossip");

Expand Down
Loading