From 9bddfc20483c59c1098f072a72445fcca0802f0e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 31 Mar 2022 16:26:22 +1030 Subject: [PATCH] connectd: take dev-suppress-gossip from gossipd. 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 --- connectd/connectd.c | 11 +++++++++++ connectd/connectd.h | 2 ++ connectd/connectd_wire.csv | 4 ++++ connectd/multiplex.c | 4 ++-- gossipd/gossipd.c | 14 -------------- gossipd/gossipd_wire.csv | 3 --- gossipd/seeker.c | 18 ------------------ gossipd/seeker.h | 3 --- lightningd/connect_control.c | 25 +++++++++++++++++++++++++ lightningd/gossip_control.c | 22 ---------------------- 10 files changed, 44 insertions(+), 62 deletions(-) diff --git a/connectd/connectd.c b/connectd/connectd.c index 71f0d8976..0e3781f65 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -1547,6 +1547,7 @@ static void connect_init(struct daemon *daemon, const u8 *msg) /*~ Clearly mark these as developer-only flags! */ daemon->dev_fast_gossip = dev_fast_gossip; daemon->dev_no_ping_timer = dev_no_ping_timer; + daemon->dev_suppress_gossip = false; #endif if (!pubkey_from_node_id(&daemon->mykey, &daemon->id)) @@ -1980,6 +1981,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, @@ -2031,6 +2037,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: diff --git a/connectd/connectd.h b/connectd/connectd.h index ce1fd44e2..df039f02e 100644 --- a/connectd/connectd.h +++ b/connectd/connectd.h @@ -193,6 +193,8 @@ struct daemon { bool dev_fast_gossip; /* Hack to avoid ping timeouts */ bool dev_no_ping_timer; + /* Hack to no longer send gossip */ + bool dev_suppress_gossip; #endif }; diff --git a/connectd/connectd_wire.csv b/connectd/connectd_wire.csv index dbb660095..07751e2e5 100644 --- a/connectd/connectd_wire.csv +++ b/connectd/connectd_wire.csv @@ -153,3 +153,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 + diff --git a/connectd/multiplex.c b/connectd/multiplex.c index 959638e08..71664438f 100644 --- a/connectd/multiplex.c +++ b/connectd/multiplex.c @@ -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; @@ -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!) */ diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index 606c5a38a..a776d294f 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -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; @@ -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; @@ -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: diff --git a/gossipd/gossipd_wire.csv b/gossipd/gossipd_wire.csv index 19e4a01f2..7ce110b67 100644 --- a/gossipd/gossipd_wire.csv +++ b/gossipd/gossipd_wire.csv @@ -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 diff --git a/gossipd/seeker.c b/gossipd/seeker.c index fbff2dd1a..c2ad30b42 100644 --- a/gossipd/seeker.c +++ b/gossipd/seeker.c @@ -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; @@ -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 @@ -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; @@ -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; diff --git a/gossipd/seeker.h b/gossipd/seeker.h index 87fa89fc9..14673427f 100644 --- a/gossipd/seeker.h +++ b/gossipd/seeker.h @@ -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 */ diff --git a/lightningd/connect_control.c b/lightningd/connect_control.c index 1f8e80c74..38fb2c342 100644 --- a/lightningd/connect_control.c +++ b/lightningd/connect_control.c @@ -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: @@ -711,3 +712,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 */ diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 90f7352bd..9b36baf74 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -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: @@ -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,