From 36730ddb6dce2398b6b4c83ff756617f45c9d6d7 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 27 Jul 2018 06:57:37 +0930 Subject: [PATCH] gossipd: dev-suppress-gossip. Useful for testing that we only get an update via the error message. Signed-off-by: Rusty Russell --- gossipd/gossip.c | 22 ++++++++++++++++++++++ gossipd/gossip_wire.csv | 3 +++ lightningd/gossip_control.c | 20 ++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/gossipd/gossip.c b/gossipd/gossip.c index b511684d4..4d15b1611 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -60,6 +60,7 @@ #if DEVELOPER static u32 max_scids_encode_bytes = -1U; +static bool suppress_gossip = false; #endif struct local_update { @@ -908,6 +909,11 @@ static bool maybe_queue_gossip(struct peer *peer) if (peer->gossip_timer) return false; +#if DEVELOPER + if (suppress_gossip) + return false; +#endif + next = next_broadcast(peer->daemon->rstate->broadcasts, peer->gossip_timestamp_min, peer->gossip_timestamp_max, @@ -1731,6 +1737,18 @@ static struct io_plan *dev_set_max_scids_encode_size(struct io_conn *conn, status_trace("Set max_scids_encode_bytes to %u", max_scids_encode_bytes); return daemon_conn_read_next(conn, &daemon->master); } + +static struct io_plan *dev_gossip_suppress(struct io_conn *conn, + struct daemon *daemon, + const u8 *msg) +{ + if (!fromwire_gossip_dev_suppress(msg)) + master_badmsg(WIRE_GOSSIP_DEV_SUPPRESS, msg); + + status_unusual("Suppressing all gossip"); + suppress_gossip = true; + return daemon_conn_read_next(conn, &daemon->master); +} #endif /* DEVELOPER */ static void gossip_send_keepalive_update(struct routing_state *rstate, @@ -2126,12 +2144,16 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master case WIRE_GOSSIP_DEV_SET_MAX_SCIDS_ENCODE_SIZE: return dev_set_max_scids_encode_size(conn, daemon, daemon->master.msg_in); + case WIRE_GOSSIP_DEV_SUPPRESS: + return dev_gossip_suppress(conn, daemon, + daemon->master.msg_in); #else case WIRE_GOSSIP_PING: case WIRE_GOSSIP_QUERY_SCIDS: case WIRE_GOSSIP_SEND_TIMESTAMP_FILTER: case WIRE_GOSSIP_QUERY_CHANNEL_RANGE: case WIRE_GOSSIP_DEV_SET_MAX_SCIDS_ENCODE_SIZE: + case WIRE_GOSSIP_DEV_SUPPRESS: break; #endif /* !DEVELOPER */ diff --git a/gossipd/gossip_wire.csv b/gossipd/gossip_wire.csv index 993e3f50f..193596500 100644 --- a/gossipd/gossip_wire.csv +++ b/gossipd/gossip_wire.csv @@ -160,3 +160,6 @@ gossip_mark_channel_unroutable,,channel,struct short_channel_id # master -> gossipd: a potential funding outpoint was spent, please forget the eventual channel gossip_outpoint_spent,3024 gossip_outpoint_spent,,short_channel_id,struct short_channel_id + +# master -> gossipd: stop gossip timers. +gossip_dev_suppress,3032 diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 62919465a..c72b80d52 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -115,6 +115,7 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) case WIRE_GOSSIP_QUERY_CHANNEL_RANGE: case WIRE_GOSSIP_SEND_TIMESTAMP_FILTER: case WIRE_GOSSIP_DEV_SET_MAX_SCIDS_ENCODE_SIZE: + case WIRE_GOSSIP_DEV_SUPPRESS: /* This is a reply, so never gets through to here. */ case WIRE_GOSSIP_GET_UPDATE_REPLY: case WIRE_GOSSIP_GETNODES_REPLY: @@ -594,4 +595,23 @@ static const struct json_command dev_set_max_scids_encode_size = { "Set {max} bytes of short_channel_ids per reply_channel_range" }; AUTODATA(json_command, &dev_set_max_scids_encode_size); + +static void json_dev_suppress_gossip(struct command *cmd, + const char *buffer, + const jsmntok_t *params) +{ + if (!param(cmd, buffer, params, NULL)) + return; + + subd_send_msg(cmd->ld->gossip, take(towire_gossip_dev_suppress(NULL))); + + command_success(cmd, null_response(cmd)); +} + +static const struct json_command dev_suppress_gossip = { + "dev-suppress-gossip", + json_dev_suppress_gossip, + "Stop this node from sending any more gossip." +}; +AUTODATA(json_command, &dev_suppress_gossip); #endif /* DEVELOPER */