gossipd: remove #if DEVELOPER in favor of runtime flag.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-09-21 15:06:27 +09:30
parent f2d8f37f1f
commit 1fc603ea6e
9 changed files with 54 additions and 70 deletions

View File

@ -37,10 +37,10 @@
*/
#define ANNOUNCE_MIN_DEPTH 6
/* Gossip timing constants. These can be overridden in --enable-developer
* configurations with --dev-fast-gossip, otherwise the argument is ignored */
/* Gossip timing constants. These can be overridden using --developer
* with --dev-fast-gossip */
#define DEV_FAST_GOSSIP(dev_fast_gossip_flag, fast, normal) \
IFDEV((dev_fast_gossip_flag) ? (fast) : (normal), (normal))
((dev_fast_gossip_flag) ? (fast) : (normal))
/* How close we can generate gossip msgs (5 minutes) */
#define GOSSIP_MIN_INTERVAL(dev_fast_gossip_flag) \

View File

@ -366,7 +366,7 @@ static void setup_force_nannounce_regen_timer(struct daemon *daemon)
struct timerel regen_time;
/* For developers we can force a regen every 24 seconds to test */
if (IFDEV(daemon->rstate->dev_fast_gossip_prune, false))
if (daemon->rstate->dev_fast_gossip_prune)
regen_time = time_from_sec(24);
else
regen_time = time_from_sec(24 * 3600);

View File

@ -705,10 +705,8 @@ static void mark_zombie(struct gossip_store *gs,
assert(gs->writable);
assert(index);
#if DEVELOPER
const u8 *msg = gossip_store_get(tmpctx, gs, index);
assert(fromwire_peektype(msg) == expected_type);
#endif
if (pread(gs->fd, &beflags, sizeof(beflags), index) != sizeof(beflags))
status_failed(STATUS_FAIL_INTERNAL_ERROR,

View File

@ -955,7 +955,6 @@ static void new_blockheight(struct daemon *daemon, const u8 *msg)
take(towire_gossipd_new_blockheight_reply(NULL)));
}
#if DEVELOPER
static void dev_gossip_memleak(struct daemon *daemon, const u8 *msg)
{
struct htable *memtable;
@ -988,12 +987,11 @@ static void dev_gossip_set_time(struct daemon *daemon, const u8 *msg)
if (!fromwire_gossipd_dev_set_time(msg, &time))
master_badmsg(WIRE_GOSSIPD_DEV_SET_TIME, msg);
if (!daemon->rstate->gossip_time)
daemon->rstate->gossip_time = tal(daemon->rstate, struct timeabs);
daemon->rstate->gossip_time->ts.tv_sec = time;
daemon->rstate->gossip_time->ts.tv_nsec = 0;
if (!daemon->rstate->dev_gossip_time)
daemon->rstate->dev_gossip_time = tal(daemon->rstate, struct timeabs);
daemon->rstate->dev_gossip_time->ts.tv_sec = time;
daemon->rstate->dev_gossip_time->ts.tv_nsec = 0;
}
#endif /* DEVELOPER */
/*~ We queue incoming channel_announcement pending confirmation from lightningd
* that it really is an unspent output. Here's its reply. */
@ -1192,26 +1190,30 @@ static struct io_plan *recv_req(struct io_conn *conn,
case WIRE_GOSSIPD_DISCOVERED_IP:
handle_discovered_ip(daemon, msg);
goto done;
#if DEVELOPER
case WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE:
if (daemon->developer) {
dev_set_max_scids_encode_size(daemon, msg);
goto done;
}
/* fall thru */
case WIRE_GOSSIPD_DEV_MEMLEAK:
if (daemon->developer) {
dev_gossip_memleak(daemon, msg);
goto done;
}
/* fall thru */
case WIRE_GOSSIPD_DEV_COMPACT_STORE:
if (daemon->developer) {
dev_compact_store(daemon, msg);
goto done;
}
/* fall thru */
case WIRE_GOSSIPD_DEV_SET_TIME:
if (daemon->developer) {
dev_gossip_set_time(daemon, msg);
goto done;
#else
case WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE:
case WIRE_GOSSIPD_DEV_MEMLEAK:
case WIRE_GOSSIPD_DEV_COMPACT_STORE:
case WIRE_GOSSIPD_DEV_SET_TIME:
break;
#endif /* !DEVELOPER */
}
/* fall thru */
/* We send these, we don't receive them */
case WIRE_GOSSIPD_INIT_CUPDATE:
@ -1236,13 +1238,15 @@ done:
int main(int argc, char *argv[])
{
struct daemon *daemon;
bool developer;
setup_locale();
struct daemon *daemon;
subdaemon_setup(argc, argv);
developer = subdaemon_setup(argc, argv);
daemon = tal(NULL, struct daemon);
daemon->developer = developer;
daemon->peers = tal(daemon, struct peer_node_id_map);
peer_node_id_map_init(daemon->peers);
daemon->deferred_txouts = tal_arr(daemon, struct short_channel_id, 0);

View File

@ -38,6 +38,9 @@ struct daemon {
/* Peers we are gossiping to: id is unique */
struct peer_node_id_map *peers;
/* --developer? */
bool developer;
/* Current blockheight: 0 means we're not up-to-date. */
u32 current_blockheight;

View File

@ -16,9 +16,7 @@
#include <gossipd/routing.h>
#include <zlib.h>
#if DEVELOPER
static u32 dev_max_encoding_bytes = -1U;
#endif
/* BOLT #7:
*
@ -59,10 +57,8 @@ static void encoding_add_query_flag(u8 **encoded, bigsize_t flag)
static bool encoding_end(const u8 *encoded, size_t max_bytes)
{
#if DEVELOPER
if (tal_count(encoded) > dev_max_encoding_bytes)
return false;
#endif
return tal_count(encoded) <= max_bytes;
}
@ -407,13 +403,11 @@ static size_t max_entries(enum query_option_flags query_option_flags)
per_entry_size += sizeof(struct channel_update_checksums);
}
#if DEVELOPER
if (max_encoded_bytes > dev_max_encoding_bytes)
max_encoded_bytes = dev_max_encoding_bytes;
/* Always let one through! */
if (max_encoded_bytes < per_entry_size)
max_encoded_bytes = per_entry_size;
#endif
return max_encoded_bytes / per_entry_size;
}
@ -1103,15 +1097,14 @@ bool query_channel_range(struct daemon *daemon,
return true;
}
#if DEVELOPER
/* This is a testing hack to allow us to artificially lower the maximum bytes
* of short_channel_ids we'll encode, using dev_set_max_scids_encode_size. */
void dev_set_max_scids_encode_size(struct daemon *daemon, const u8 *msg)
{
assert(daemon->developer);
if (!fromwire_gossipd_dev_set_max_scids_encode_size(msg,
&dev_max_encoding_bytes))
master_badmsg(WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE, msg);
status_debug("Set max_scids_encode_bytes to %u", dev_max_encoding_bytes);
}
#endif /* DEVELOPER */

View File

@ -52,11 +52,6 @@ bool query_short_channel_ids(struct daemon *daemon,
const u8 *query_flags,
void (*cb)(struct peer *peer_, bool complete));
#if DEVELOPER
struct io_plan *query_scids_req(struct io_conn *conn,
struct daemon *daemon,
const u8 *msg);
struct io_plan *dev_query_channel_range(struct io_conn *conn,
struct daemon *daemon,
const u8 *msg);
@ -64,6 +59,5 @@ struct io_plan *dev_query_channel_range(struct io_conn *conn,
/* This is a testing hack to allow us to artificially lower the maximum bytes
* of short_channel_ids we'll encode, using dev_set_max_scids_encode_size. */
void dev_set_max_scids_encode_size(struct daemon *daemon, const u8 *msg);
#endif /* DEVELOPER */
#endif /* LIGHTNING_GOSSIPD_QUERIES_H */

View File

@ -309,16 +309,15 @@ struct routing_state *new_routing_state(const tal_t *ctx,
rstate->pending_node_map = tal(ctx, struct pending_node_map);
pending_node_map_init(rstate->pending_node_map);
#if DEVELOPER
if (dev_gossip_time) {
rstate->gossip_time = tal(rstate, struct timeabs);
rstate->gossip_time->ts.tv_sec = *dev_gossip_time;
rstate->gossip_time->ts.tv_nsec = 0;
assert(daemon->developer);
rstate->dev_gossip_time = tal(rstate, struct timeabs);
rstate->dev_gossip_time->ts.tv_sec = *dev_gossip_time;
rstate->dev_gossip_time->ts.tv_nsec = 0;
} else
rstate->gossip_time = NULL;
rstate->dev_gossip_time = NULL;
rstate->dev_fast_gossip = dev_fast_gossip;
rstate->dev_fast_gossip_prune = dev_fast_gossip_prune;
#endif
tal_add_destructor(rstate, destroy_routing_state);
memleak_add_helper(rstate, memleak_help_routing_tables);
@ -545,22 +544,19 @@ static void remove_chan_from_node(struct routing_state *rstate,
}
}
#if DEVELOPER
/* We make sure that free_chan is called on this chan! */
/* With --developer, we make sure that free_chan is called on this chan! */
static void destroy_chan_check(struct chan *chan)
{
assert(chan->sat.satoshis == (unsigned long)chan); /* Raw: dev-hack */
}
#endif
static void free_chans_from_node(struct routing_state *rstate, struct chan *chan)
{
remove_chan_from_node(rstate, chan->nodes[0], chan);
remove_chan_from_node(rstate, chan->nodes[1], chan);
#if DEVELOPER
if (rstate->daemon->developer)
chan->sat.satoshis = (unsigned long)chan; /* Raw: dev-hack */
#endif
}
/* We used to make this a tal_add_destructor2, but that costs 40 bytes per
@ -605,9 +601,9 @@ struct chan *new_chan(struct routing_state *rstate,
int n1idx = node_id_idx(id1, id2);
struct node *n1, *n2;
#if DEVELOPER
if (rstate->daemon->developer)
tal_add_destructor(chan, destroy_chan_check);
#endif
/* We should never add a channel twice */
assert(!uintmap_get(&rstate->chanmap, scid->u64));
@ -2188,10 +2184,9 @@ bool routing_add_private_channel(struct routing_state *rstate,
struct timeabs gossip_time_now(const struct routing_state *rstate)
{
#if DEVELOPER
if (rstate->gossip_time)
return *rstate->gossip_time;
#endif
if (rstate->dev_gossip_time)
return *rstate->dev_gossip_time;
return time_now();
}
@ -2238,9 +2233,8 @@ void remove_all_gossip(struct routing_state *rstate)
/* Now free all the channels. */
while ((c = uintmap_first(&rstate->chanmap, &index)) != NULL) {
uintmap_del(&rstate->chanmap, index);
#if DEVELOPER
if (rstate->daemon->developer)
c->sat = amount_sat((unsigned long)c);
#endif
tal_free(c);
}

View File

@ -232,16 +232,14 @@ struct routing_state {
/* Channels which are closed, but we're waiting 12 blocks */
struct dying_channel *dying_channels;
#if DEVELOPER
/* Override local time for gossip messages */
struct timeabs *gossip_time;
struct timeabs *dev_gossip_time;
/* Speed up gossip. */
bool dev_fast_gossip;
/* Speed up pruning. */
bool dev_fast_gossip_prune;
#endif
};
/* Which direction are we? False if neither. */