Skip to content

Commit

Permalink
subdaemons: don't stream gossip_store at all.
Browse files Browse the repository at this point in the history
We now let gossipd do it.

This also means there's nothing left in 'struct per_peer_state' to
send across the wire (the fds are sent separately), so that gets
removed from wire messages too.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jan 20, 2022
1 parent 029d65c commit 6115ed0
Show file tree
Hide file tree
Showing 35 changed files with 148 additions and 510 deletions.
39 changes: 14 additions & 25 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <common/peer_billboard.h>
#include <common/peer_failed.h>
#include <common/peer_io.h>
#include <common/per_peer_state.h>
#include <common/ping.h>
#include <common/private_channel_announcement.h>
#include <common/read_peer_msg.h>
Expand All @@ -45,9 +46,9 @@
#include <wire/peer_wire.h>
#include <wire/wire_sync.h>

/* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = HSM */
/* stdin == requests, 3 == peer, 4 = gossip, 5 = HSM */
#define MASTER_FD STDIN_FILENO
#define HSM_FD 6
#define HSM_FD 5

enum pong_expect_type {
/* We weren't expecting a ping reply */
Expand Down Expand Up @@ -160,6 +161,9 @@ struct peer {
#if DEVELOPER
/* If set, don't fire commit counter when this hits 0 */
u32 *dev_disable_commit;

/* If set, send channel_announcement after 1 second, not 30 */
bool dev_fast_gossip;
#endif
/* Information used for reestablishment. */
bool last_was_revoke;
Expand Down Expand Up @@ -638,7 +642,7 @@ static void channel_announcement_negotiate(struct peer *peer)

/* Give other nodes time to notice new block. */
notleak(new_reltimer(&peer->timers, peer,
time_from_sec(GOSSIP_ANNOUNCE_DELAY(dev_fast_gossip)),
time_from_sec(GOSSIP_ANNOUNCE_DELAY(peer->dev_fast_gossip)),
announce_channel, peer));
}
}
Expand Down Expand Up @@ -980,7 +984,7 @@ static void send_shutdown_complete(struct peer *peer)
{
/* Now we can tell master shutdown is complete. */
wire_sync_write(MASTER_FD,
take(towire_channeld_shutdown_complete(NULL, peer->pps)));
take(towire_channeld_shutdown_complete(NULL)));
per_peer_state_fdpass_send(MASTER_FD, peer->pps);
close(MASTER_FD);
}
Expand Down Expand Up @@ -3839,6 +3843,7 @@ static void init_channel(struct peer *peer)
u8 *reestablish_only;
struct channel_type *channel_type;
u32 *dev_disable_commit; /* Always NULL */
bool dev_fast_gossip;
#if !DEVELOPER
bool dev_fail_process_onionpacket; /* Ignored */
#endif
Expand All @@ -3862,7 +3867,6 @@ static void init_channel(struct peer *peer)
&peer->feerate_max,
&peer->feerate_penalty,
&peer->their_commit_sig,
&peer->pps,
&funding_pubkey[REMOTE],
&points[REMOTE],
&peer->remote_per_commit,
Expand Down Expand Up @@ -3910,6 +3914,7 @@ static void init_channel(struct peer *peer)

#if DEVELOPER
peer->dev_disable_commit = dev_disable_commit;
peer->dev_fast_gossip = dev_fast_gossip;
#endif

status_debug("option_static_remotekey = %u, option_anchor_outputs = %u",
Expand All @@ -3924,8 +3929,9 @@ static void init_channel(struct peer *peer)
tal_dup(peer, struct penalty_base, &pbases[i]));
tal_free(pbases);

/* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = HSM */
per_peer_state_set_fds(peer->pps, 3, 4, 5);
/* stdin == requests, 3 == peer, 4 = gossip */
peer->pps = new_per_peer_state(peer);
per_peer_state_set_fds(peer->pps, 3, 4);

status_debug("init %s: remote_per_commit = %s, old_remote_per_commit = %s"
" next_idx_local = %"PRIu64
Expand Down Expand Up @@ -4019,14 +4025,6 @@ static void init_channel(struct peer *peer)
billboard_update(peer);
}

static void try_read_gossip_store(struct peer *peer)
{
u8 *msg = gossip_store_next(tmpctx, peer->pps);

if (msg)
peer_write(peer->pps, take(msg));
}

int main(int argc, char *argv[])
{
setup_locale();
Expand Down Expand Up @@ -4088,7 +4086,6 @@ int main(int argc, char *argv[])
struct timeval timeout, *tptr;
struct timer *expired;
const u8 *msg;
struct timerel trel;
struct timemono now = time_mono();

/* Free any temporary allocations */
Expand Down Expand Up @@ -4120,13 +4117,6 @@ int main(int argc, char *argv[])
tptr = &timeout;
}

/* If timer to next gossip is sooner, use that instead. */
if (time_to_next_gossip(peer->pps, &trel)
&& (!tptr || time_less(trel, timeval_to_timerel(*tptr)))) {
timeout = timerel_to_timeval(trel);
tptr = &timeout;
}

if (select(nfds, &rfds, NULL, NULL, tptr) < 0) {
/* Signals OK, eg. SIGUSR1 */
if (errno == EINTR)
Expand Down Expand Up @@ -4154,8 +4144,7 @@ int main(int argc, char *argv[])
if (!msg)
peer_failed_connection_lost();
handle_gossip_msg(peer->pps, take(msg));
} else /* Lowest priority: stream from store. */
try_read_gossip_store(peer);
}
}

/* We only exit when shutdown is complete. */
Expand Down
3 changes: 0 additions & 3 deletions channeld/channeld_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <common/derive_basepoints.h>
#include <common/features.h>
#include <common/fee_states.h>
#include <common/per_peer_state.h>

# Begin! (passes gossipd-client fd)
msgtype,channeld_init,1000
Expand All @@ -28,7 +27,6 @@ msgdata,channeld_init,feerate_min,u32,
msgdata,channeld_init,feerate_max,u32,
msgdata,channeld_init,feerate_penalty,u32,
msgdata,channeld_init,first_commit_sig,bitcoin_signature,
msgdata,channeld_init,per_peer_state,per_peer_state,
msgdata,channeld_init,remote_fundingkey,pubkey,
msgdata,channeld_init,remote_basepoints,basepoints,
msgdata,channeld_init,remote_per_commit,pubkey,
Expand Down Expand Up @@ -187,7 +185,6 @@ msgdata,channeld_got_shutdown,wrong_funding,?bitcoin_outpoint,

# Shutdown is complete, ready for closing negotiation. + peer_fd & gossip_fd.
msgtype,channeld_shutdown_complete,1025
msgdata,channeld_shutdown_complete,per_peer_state,per_peer_state,

# Re-enable commit timer.
msgtype,channeld_dev_reenable_commit,1026
Expand Down
11 changes: 5 additions & 6 deletions closingd/closingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
#include <wire/peer_wire.h>
#include <wire/wire_sync.h>

/* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = hsmd */
/* stdin == requests, 3 == peer, 4 = gossip, 5 = hsmd */
#define REQ_FD STDIN_FILENO
#define HSM_FD 6
#define HSM_FD 5

static void notify(enum log_level level, const char *fmt, ...)
{
Expand Down Expand Up @@ -897,7 +897,6 @@ int main(int argc, char *argv[])
msg = wire_sync_read(tmpctx, REQ_FD);
if (!fromwire_closingd_init(ctx, msg,
&chainparams,
&pps,
&channel_id,
&funding,
&funding_sats,
Expand All @@ -914,12 +913,12 @@ int main(int argc, char *argv[])
&fee_negotiation_step,
&fee_negotiation_step_unit,
&use_quickclose,
&dev_fast_gossip,
&wrong_funding))
master_badmsg(WIRE_CLOSINGD_INIT, msg);

/* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = hsmd */
per_peer_state_set_fds(notleak(pps), 3, 4, 5);
/* stdin == requests, 3 == peer, 4 = gossip, 5 = hsmd */
pps = notleak(new_per_peer_state(ctx));
per_peer_state_set_fds(pps, 3, 4);

funding_wscript = bitcoin_redeem_2of2(ctx,
&funding_pubkey[LOCAL],
Expand Down
3 changes: 0 additions & 3 deletions closingd/closingd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
#include <common/channel_id.h>
#include <common/cryptomsg.h>
#include <common/htlc_wire.h>
#include <common/per_peer_state.h>
#include <common/status_wire.h>
# Begin! (passes peer fd, gossipd-client fd)
msgtype,closingd_init,2001
msgdata,closingd_init,chainparams,chainparams,
msgdata,closingd_init,pps,per_peer_state,
msgdata,closingd_init,channel_id,channel_id,
msgdata,closingd_init,funding,bitcoin_outpoint,
msgdata,closingd_init,funding_satoshi,amount_sat,
Expand All @@ -28,7 +26,6 @@ msgdata,closingd_init,remote_scriptpubkey,u8,remote_scriptpubkey_len
msgdata,closingd_init,fee_negotiation_step,u64,
msgdata,closingd_init,fee_negotiation_step_unit,u8,
msgdata,closingd_init,use_quickclose,bool,
msgdata,closingd_init,dev_fast_gossip,bool,
msgdata,closingd_init,shutdown_wrong_funding,?bitcoin_outpoint,

# Message for any commands waiting.
Expand Down
51 changes: 0 additions & 51 deletions common/gossip_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,6 @@
#include <unistd.h>
#include <wire/peer_wire.h>

void gossip_setup_timestamp_filter(struct per_peer_state *pps,
u32 first_timestamp,
u32 timestamp_range)
{
/* If this is the first filter, we gossip sync immediately. */
if (!pps->gs) {
pps->gs = tal(pps, struct gossip_state);
pps->gs->next_gossip = time_mono();
}

pps->gs->timestamp_min = first_timestamp;
pps->gs->timestamp_max = first_timestamp + timestamp_range - 1;
/* Make sure we never leave it on an impossible value. */
if (pps->gs->timestamp_max < pps->gs->timestamp_min)
pps->gs->timestamp_max = UINT32_MAX;

/* BOLT #7:
*
* The receiver:
* - SHOULD send all gossip messages whose `timestamp` is greater or
* equal to `first_timestamp`, and less than `first_timestamp` plus
* `timestamp_range`.
* - MAY wait for the next outgoing gossip flush to send these.
* ...
* - SHOULD restrict future gossip messages to those whose `timestamp`
* is greater or equal to `first_timestamp`, and less than
* `first_timestamp` plus `timestamp_range`.
*/

/* Restart just after header. */
lseek(pps->gossip_store_fd, 1, SEEK_SET);
}

static bool timestamp_filter(const struct gossip_state *gs, u32 timestamp)
{
/* BOLT #7:
Expand Down Expand Up @@ -182,24 +149,6 @@ u8 *gossip_store_iter(const tal_t *ctx,
return msg;
}

u8 *gossip_store_next(const tal_t *ctx, struct per_peer_state *pps)
{
u8 *msg;

/* Don't read until we're initialized. */
if (!pps->gs)
return NULL;

/* FIXME: We are only caller using off == NULL */
msg = gossip_store_iter(ctx, &pps->gossip_store_fd,
pps->gs, pps->grf, NULL);

if (!msg)
per_peer_state_reset_gossip_timer(pps);

return msg;
}

size_t find_gossip_store_end(int gossip_store_fd, size_t off)
{
/* We cheat and read first two bytes of message too. */
Expand Down
16 changes: 0 additions & 16 deletions common/gossip_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>

struct per_peer_state;
struct gossip_state;
struct gossip_rcvd_filter;

Expand Down Expand Up @@ -37,14 +36,6 @@ struct gossip_hdr {
beint32_t timestamp; /* timestamp of msg. */
};

/**
* Direct store accessor: loads gossip msg from store.
*
* Returns NULL and resets time_to_next_gossip(pps) if there are no
* more gossip msgs.
*/
u8 *gossip_store_next(const tal_t *ctx, struct per_peer_state *pps);

/**
* Direct store accessor: loads gossip msg from store.
*
Expand All @@ -56,13 +47,6 @@ u8 *gossip_store_iter(const tal_t *ctx,
struct gossip_rcvd_filter *grf,
size_t *off);

/**
* Sets up the tiemstamp filter once they told us to set it.(
*/
void gossip_setup_timestamp_filter(struct per_peer_state *pps,
u32 first_timestamp,
u32 timestamp_range);

/**
* Gossipd will be writing to this, and it's not atomic! Safest
* way to find the "end" is to walk through.
Expand Down
4 changes: 1 addition & 3 deletions common/peer_failed.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ peer_fatal_continue(const u8 *msg TAKES, const struct per_peer_state *pps)

status_send_fd(pps->peer_fd);
status_send_fd(pps->gossip_fd);
status_send_fd(pps->gossip_store_fd);
exit(0x80 | (reason & 0xFF));
}

Expand All @@ -44,7 +43,6 @@ peer_failed(struct per_peer_state *pps,
msg = towire_status_peer_error(NULL, channel_id,
desc,
warn,
pps,
msg);
peer_billboard(true, desc);
peer_fatal_continue(take(msg), pps);
Expand Down Expand Up @@ -87,7 +85,7 @@ void peer_failed_received_errmsg(struct per_peer_state *pps,
{
u8 *msg;

msg = towire_status_peer_error(NULL, channel_id, desc, warning, pps,
msg = towire_status_peer_error(NULL, channel_id, desc, warning,
NULL);
peer_billboard(true, "Received %s", desc);
peer_fatal_continue(take(msg), pps);
Expand Down
1 change: 0 additions & 1 deletion common/peer_status_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ msgdata,status_peer_error,channel,channel_id,
msgdata,status_peer_error,desc,wirestring,
# Take a deep breath, then try reconnecting to the precious little snowflake.
msgdata,status_peer_error,warning,bool,
msgdata,status_peer_error,pps,per_peer_state,
msgdata,status_peer_error,len,u16,
msgdata,status_peer_error,error_for_them,u8,len
Loading

0 comments on commit 6115ed0

Please sign in to comment.