Skip to content

Commit

Permalink
connectd: take dev-suppress-gossip from gossipd.
Browse files Browse the repository at this point in the history
Gossipd didn't actually suppress all gossip, resulting in a flake!
Doing it in connectd now makes much more sense.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Mar 31, 2022
1 parent 3383f3e commit c0f7880
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 62 deletions.
11 changes: 11 additions & 0 deletions connectd/connectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,7 @@ static void connect_init(struct daemon *daemon, const u8 *msg)
#if DEVELOPER
/*~ Clearly mark this as a developer-only flag! */
daemon->dev_fast_gossip = dev_fast_gossip;
daemon->dev_suppress_gossip = false;
#endif

if (!pubkey_from_node_id(&daemon->mykey, &daemon->id))
Expand Down Expand Up @@ -1978,6 +1979,11 @@ static void dev_connect_memleak(struct daemon *daemon, const u8 *msg)
take(towire_connectd_dev_memleak_reply(NULL,
found_leak)));
}

static void dev_suppress_gossip(struct daemon *daemon, const u8 *msg)
{
daemon->dev_suppress_gossip = true;
}
#endif /* DEVELOPER */

static struct io_plan *recv_req(struct io_conn *conn,
Expand Down Expand Up @@ -2029,6 +2035,11 @@ static struct io_plan *recv_req(struct io_conn *conn,
#if DEVELOPER
dev_connect_memleak(daemon, msg);
goto out;
#endif
case WIRE_CONNECTD_DEV_SUPPRESS_GOSSIP:
#if DEVELOPER
dev_suppress_gossip(daemon, msg);
goto out;
#endif
/* We send these, we don't receive them */
case WIRE_CONNECTD_INIT_REPLY:
Expand Down
3 changes: 3 additions & 0 deletions connectd/connectd.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ struct daemon {
#if DEVELOPER
/* Hack to speed up gossip timer */
bool dev_fast_gossip;

/* A testing hack */
bool dev_suppress_gossip;
#endif
};

Expand Down
4 changes: 4 additions & 0 deletions connectd/connectd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,7 @@ msgtype,connectd_custommsg_out,2011
msgdata,connectd_custommsg_out,id,node_id,
msgdata,connectd_custommsg_out,msg_len,u16,
msgdata,connectd_custommsg_out,msg,u8,msg_len

# master -> connect: stop sending gossip.
msgtype,connectd_dev_suppress_gossip,2032

4 changes: 2 additions & 2 deletions connectd/multiplex.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void setup_peer_gossip_store(struct peer *peer,
}

peer->gs.gossip_timer = gossip_stream_timer(peer);
peer->gs.active = true;
peer->gs.active = IFDEV(!peer->daemon->dev_suppress_gossip, true);
peer->gs.timestamp_min = 0;
peer->gs.timestamp_max = UINT32_MAX;

Expand Down Expand Up @@ -344,7 +344,7 @@ static struct io_plan *encrypt_and_send(struct peer *peer,
/* Kicks off write_to_peer() to look for more gossip to send from store */
static void wake_gossip(struct peer *peer)
{
peer->gs.active = true;
peer->gs.active = IFDEV(!peer->daemon->dev_suppress_gossip, true);
io_wake(peer->peer_outq);

/* And go again in 60 seconds (from now, now when we finish!) */
Expand Down
14 changes: 0 additions & 14 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,16 +805,6 @@ static void new_blockheight(struct daemon *daemon, const u8 *msg)
}

#if DEVELOPER
/* Another testing hack */
static void dev_gossip_suppress(struct daemon *daemon, const u8 *msg)
{
if (!fromwire_gossipd_dev_suppress(msg))
master_badmsg(WIRE_GOSSIPD_DEV_SUPPRESS, msg);

status_unusual("Suppressing all gossip");
dev_suppress_gossip = true;
}

static void dev_gossip_memleak(struct daemon *daemon, const u8 *msg)
{
struct htable *memtable;
Expand Down Expand Up @@ -1058,9 +1048,6 @@ static struct io_plan *recv_req(struct io_conn *conn,
case WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE:
dev_set_max_scids_encode_size(daemon, msg);
goto done;
case WIRE_GOSSIPD_DEV_SUPPRESS:
dev_gossip_suppress(daemon, msg);
goto done;
case WIRE_GOSSIPD_DEV_MEMLEAK:
dev_gossip_memleak(daemon, msg);
goto done;
Expand All @@ -1072,7 +1059,6 @@ static struct io_plan *recv_req(struct io_conn *conn,
goto done;
#else
case WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE:
case WIRE_GOSSIPD_DEV_SUPPRESS:
case WIRE_GOSSIPD_DEV_MEMLEAK:
case WIRE_GOSSIPD_DEV_COMPACT_STORE:
case WIRE_GOSSIPD_DEV_SET_TIME:
Expand Down
3 changes: 0 additions & 3 deletions gossipd/gossipd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ msgdata,gossipd_get_txout_reply,outscript,u8,len
msgtype,gossipd_outpoint_spent,3024
msgdata,gossipd_outpoint_spent,short_channel_id,short_channel_id,

# master -> gossipd: stop gossip timers.
msgtype,gossipd_dev_suppress,3032

# master -> gossipd: do you have a memleak?
msgtype,gossipd_dev_memleak,3033

Expand Down
18 changes: 0 additions & 18 deletions gossipd/seeker.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ enum seeker_state {
ASKING_FOR_STALE_SCIDS,
};

#if DEVELOPER
bool dev_suppress_gossip;
#endif

/* Gossip we're seeking at the moment. */
struct seeker {
struct daemon *daemon;
Expand Down Expand Up @@ -215,11 +211,6 @@ static void enable_gossip_stream(struct seeker *seeker, struct peer *peer)
u32 start = seeker->daemon->rstate->last_timestamp;
u8 *msg;

#if DEVELOPER
if (dev_suppress_gossip)
return;
#endif

if (start > polltime)
start -= polltime;
else
Expand Down Expand Up @@ -870,11 +861,6 @@ static bool seek_any_unknown_nodes(struct seeker *seeker)
/* Periodic timer to see how our gossip is going. */
static void seeker_check(struct seeker *seeker)
{
#if DEVELOPER
if (dev_suppress_gossip)
goto out;
#endif

/* We don't do anything until we're synced. */
if (seeker->daemon->current_blockheight == 0)
goto out;
Expand Down Expand Up @@ -914,10 +900,6 @@ void seeker_setup_peer_gossip(struct seeker *seeker, struct peer *peer)
if (!peer->gossip_queries_feature)
return;

#if DEVELOPER
if (dev_suppress_gossip)
return;
#endif
/* Don't start gossiping until we're synced. */
if (seeker->daemon->current_blockheight == 0)
return;
Expand Down
3 changes: 0 additions & 3 deletions gossipd/seeker.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,4 @@ bool add_unknown_scid(struct seeker *seeker,
const struct short_channel_id *scid,
struct peer *peer);

/* A testing hack */
extern bool dev_suppress_gossip;

#endif /* LIGHTNING_GOSSIPD_SEEKER_H */
25 changes: 25 additions & 0 deletions lightningd/connect_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ static unsigned connectd_msg(struct subd *connectd, const u8 *msg, const int *fd
case WIRE_CONNECTD_CONNECT_TO_PEER:
case WIRE_CONNECTD_DISCARD_PEER:
case WIRE_CONNECTD_DEV_MEMLEAK:
case WIRE_CONNECTD_DEV_SUPPRESS_GOSSIP:
case WIRE_CONNECTD_PEER_FINAL_MSG:
case WIRE_CONNECTD_PEER_MAKE_ACTIVE:
case WIRE_CONNECTD_PING:
Expand Down Expand Up @@ -710,3 +711,27 @@ static const struct json_command dev_sendcustommsg_command = {
AUTODATA(json_command, &dev_sendcustommsg_command);
#endif /* DEVELOPER */
#endif /* COMPAT_V0100 */

#if DEVELOPER
static struct command_result *json_dev_suppress_gossip(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
if (!param(cmd, buffer, params, NULL))
return command_param_failed();

subd_send_msg(cmd->ld->connectd,
take(towire_connectd_dev_suppress_gossip(NULL)));

return command_success(cmd, json_stream_success(cmd));
}

static const struct json_command dev_suppress_gossip = {
"dev-suppress-gossip",
"developer",
json_dev_suppress_gossip,
"Stop this node from sending any more gossip."
};
AUTODATA(json_command, &dev_suppress_gossip);
#endif /* DEVELOPER */
22 changes: 0 additions & 22 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
case WIRE_GOSSIPD_OUTPOINT_SPENT:
case WIRE_GOSSIPD_NEW_LEASE_RATES:
case WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE:
case WIRE_GOSSIPD_DEV_SUPPRESS:
case WIRE_GOSSIPD_LOCAL_CHANNEL_CLOSE:
case WIRE_GOSSIPD_DEV_MEMLEAK:
case WIRE_GOSSIPD_DEV_COMPACT_STORE:
Expand Down Expand Up @@ -503,27 +502,6 @@ static const struct json_command dev_set_max_scids_encode_size = {
};
AUTODATA(json_command, &dev_set_max_scids_encode_size);

static struct command_result *json_dev_suppress_gossip(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
if (!param(cmd, buffer, params, NULL))
return command_param_failed();

subd_send_msg(cmd->ld->gossip, take(towire_gossipd_dev_suppress(NULL)));

return command_success(cmd, json_stream_success(cmd));
}

static const struct json_command dev_suppress_gossip = {
"dev-suppress-gossip",
"developer",
json_dev_suppress_gossip,
"Stop this node from sending any more gossip."
};
AUTODATA(json_command, &dev_suppress_gossip);

static void dev_compact_gossip_store_reply(struct subd *gossip UNUSED,
const u8 *reply,
const int *fds UNUSED,
Expand Down

0 comments on commit c0f7880

Please sign in to comment.