Skip to content

Commit

Permalink
gossipd: dev-suppress-gossip.
Browse files Browse the repository at this point in the history
Useful for testing that we only get an update via the error message.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Jul 27, 2018
1 parent 162879d commit 36730dd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions gossipd/gossip.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

#if DEVELOPER
static u32 max_scids_encode_bytes = -1U;
static bool suppress_gossip = false;
#endif

struct local_update {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 */

Expand Down
3 changes: 3 additions & 0 deletions gossipd/gossip_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 */

0 comments on commit 36730dd

Please sign in to comment.