Skip to content
This repository was archived by the owner on Apr 17, 2020. It is now read-only.

Commit 147eace

Browse files
committed
developer: consolidiate gossip timing options into one --dev-fast-gossip.
It's generally clearer to have simple hardcoded numbers with an #if DEVELOPER around it, than apparent variables which aren't, really. Interestingly, our pruning test was always kinda broken: we have to pass two cycles, since l2 will refresh the channel once to avoid pruning. Do the more obvious thing, and cut the network in half and check that l1 and l3 time out. Signed-off-by: Rusty Russell <[email protected]>
1 parent 8139164 commit 147eace

33 files changed

+138
-149
lines changed

channeld/channel_wire.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ msgdata,channel_init,upfront_shutdown_script_len,u16,
6868
msgdata,channel_init,upfront_shutdown_script,u8,upfront_shutdown_script_len
6969
msgdata,channel_init,remote_ann_node_sig,?secp256k1_ecdsa_signature,
7070
msgdata,channel_init,remote_ann_bitcoin_sig,?secp256k1_ecdsa_signature,
71-
msgdata,channel_init,announce_delay,u32,
7271
msgdata,channel_init,option_static_remotekey,bool,
72+
msgdata,channel_init,dev_fast_gossip,bool,
7373

7474
# master->channeld funding hit new depth(funding locked if >= lock depth)
7575
msgtype,channel_funding_depth,1002

channeld/channeld.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ struct peer {
110110
u64 commit_timer_attempts;
111111
u32 commit_msec;
112112

113-
/* How long to delay before broadcasting announcement? */
114-
u32 announce_delay;
115-
116113
/* Are we expecting a pong? */
117114
bool expecting_pong;
118115

@@ -505,7 +502,7 @@ static void channel_announcement_negotiate(struct peer *peer)
505502

506503
/* Give other nodes time to notice new block. */
507504
notleak(new_reltimer(&peer->timers, peer,
508-
time_from_sec(peer->announce_delay),
505+
time_from_sec(GOSSIP_ANNOUNCE_DELAY(dev_fast_gossip)),
509506
announce_channel, peer));
510507
}
511508
}
@@ -3000,8 +2997,8 @@ static void init_channel(struct peer *peer)
30002997
&peer->remote_upfront_shutdown_script,
30012998
&remote_ann_node_sig,
30022999
&remote_ann_bitcoin_sig,
3003-
&peer->announce_delay,
3004-
&option_static_remotekey)) {
3000+
&option_static_remotekey,
3001+
&dev_fast_gossip)) {
30053002
master_badmsg(WIRE_CHANNEL_INIT, msg);
30063003
}
30073004
/* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = HSM */

closingd/closing_wire.csv

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ msgdata,closing_init,channel_reestablish,u8,channel_reestablish_len
3030
msgdata,closing_init,final_scriptpubkey_len,u16,
3131
msgdata,closing_init,final_scriptpubkey,u8,final_scriptpubkey_len
3232
msgdata,closing_init,last_remote_secret,secret,
33+
msgdata,closing_init,dev_fast_gossip,bool,
3334

3435
# We received an offer, save signature.
3536
msgtype,closing_received_signature,2002

closingd/closingd.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,8 @@ int main(int argc, char *argv[])
605605
&revocations_received,
606606
&channel_reestablish,
607607
&final_scriptpubkey,
608-
&last_remote_per_commit_secret))
608+
&last_remote_per_commit_secret,
609+
&dev_fast_gossip))
609610
master_badmsg(WIRE_CLOSING_INIT, msg);
610611

611612
/* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = hsmd */

common/per_peer_state.c

+4-10
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
#include <ccan/fdpass/fdpass.h>
33
#include <common/gossip_rcvd_filter.h>
44
#include <common/per_peer_state.h>
5+
#include <gossipd/gossip_constants.h>
56
#include <unistd.h>
67
#include <wire/wire.h>
78

9+
bool dev_fast_gossip = false;
10+
811
static void destroy_per_peer_state(struct per_peer_state *pps)
912
{
1013
if (pps->peer_fd != -1)
@@ -66,9 +69,6 @@ void fromwire_gossip_state(const u8 **cursor, size_t *max,
6669
void towire_per_peer_state(u8 **pptr, const struct per_peer_state *pps)
6770
{
6871
towire_crypto_state(pptr, &pps->cs);
69-
#if DEVELOPER
70-
towire_u32(pptr, pps->dev_gossip_broadcast_msec);
71-
#endif
7272
towire_bool(pptr, pps->gs != NULL);
7373
if (pps->gs)
7474
towire_gossip_state(pptr, pps->gs);
@@ -93,9 +93,6 @@ struct per_peer_state *fromwire_per_peer_state(const tal_t *ctx,
9393

9494
fromwire_crypto_state(cursor, max, &cs);
9595
pps = new_per_peer_state(ctx, &cs);
96-
#if DEVELOPER
97-
pps->dev_gossip_broadcast_msec = fromwire_u32(cursor, max);
98-
#endif
9996
if (fromwire_bool(cursor, max)) {
10097
pps->gs = tal(pps, struct gossip_state);
10198
fromwire_gossip_state(cursor, max, pps->gs);
@@ -135,11 +132,8 @@ bool time_to_next_gossip(const struct per_peer_state *pps,
135132
*/
136133
void per_peer_state_reset_gossip_timer(struct per_peer_state *pps)
137134
{
138-
struct timerel t = time_from_sec(60);
135+
struct timerel t = time_from_sec(GOSSIP_FLUSH_INTERVAL(dev_fast_gossip));
139136

140-
#if DEVELOPER
141-
t = time_from_msec(pps->dev_gossip_broadcast_msec);
142-
#endif
143137
pps->gs->next_gossip = timemono_add(time_mono(), t);
144138
gossip_rcvd_filter_age(pps->grf);
145139
}

common/per_peer_state.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ struct per_peer_state {
2222
struct gossip_state *gs;
2323
/* Cache of msgs we have received, to avoid re-xmitting from store */
2424
struct gossip_rcvd_filter *grf;
25-
#if DEVELOPER
26-
/* Normally 60000, but adjustable for dev mode */
27-
u32 dev_gossip_broadcast_msec;
28-
#endif /* DEVELOPER */
2925
/* If not -1, closed on freeing */
3026
int peer_fd, gossip_fd, gossip_store_fd;
3127
};
@@ -60,4 +56,8 @@ bool time_to_next_gossip(const struct per_peer_state *pps,
6056

6157
/* Reset pps->next_gossip now we've drained gossip_store */
6258
void per_peer_state_reset_gossip_timer(struct per_peer_state *pps);
59+
60+
/* Used to speed up gossip iff DEVELOPER*/
61+
extern bool dev_fast_gossip;
62+
6363
#endif /* LIGHTNING_COMMON_PER_PEER_STATE_H */

connectd/connectd.c

-4
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,6 @@ struct io_plan *peer_connected(struct io_conn *conn,
439439

440440
/* This contains the per-peer state info; gossipd fills in pps->gs */
441441
pps = new_per_peer_state(tmpctx, cs);
442-
#if DEVELOPER
443-
/* Overridden by lightningd, but initialize to keep valgrind happy */
444-
pps->dev_gossip_broadcast_msec = 0;
445-
#endif
446442

447443
/* If gossipd can't give us a file descriptor, we give up connecting. */
448444
if (!get_gossipfds(daemon, id, localfeatures, pps))

gossipd/gossip_constants.h

+37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#ifndef LIGHTNING_GOSSIPD_GOSSIP_CONSTANTS_H
22
#define LIGHTNING_GOSSIPD_GOSSIP_CONSTANTS_H
3+
#include <common/utils.h>
34

45
/* BOLT #4:
56
*
@@ -40,4 +41,40 @@
4041
*/
4142
#define ANNOUNCE_MIN_DEPTH 6
4243

44+
/* Gossip timing constants. These can be overridden in --enable-developer
45+
* configurations with --dev-fast-gossip, otherwise the argument is ignored */
46+
#define DEV_FAST_GOSSIP(dev_fast_gossip_flag, fast, normal) \
47+
IFDEV((dev_fast_gossip_flag) ? (fast) : (normal), (normal))
48+
49+
/* How close we can generate gossip msgs (5 minutes) */
50+
#define GOSSIP_MIN_INTERVAL(dev_fast_gossip_flag) \
51+
DEV_FAST_GOSSIP(dev_fast_gossip_flag, 5, 300)
52+
53+
/* BOLT #7:
54+
*
55+
* - SHOULD flush outgoing gossip messages once every 60 seconds,
56+
* independently of the arrival times of the messages.
57+
*/
58+
#define GOSSIP_FLUSH_INTERVAL(dev_fast_gossip_flag) \
59+
DEV_FAST_GOSSIP(dev_fast_gossip_flag, 1, 60)
60+
61+
/* BOLT #7:
62+
*
63+
* A node:
64+
* - if a channel's latest `channel_update`s `timestamp` is older than two weeks
65+
* (1209600 seconds):
66+
* - MAY prune the channel.
67+
* - MAY ignore the channel.
68+
*/
69+
#define GOSSIP_PRUNE_INTERVAL(dev_fast_gossip_flag) \
70+
DEV_FAST_GOSSIP(dev_fast_gossip_flag, 90, 1209600)
71+
72+
/* How long after seeing lockin until we announce the channel. */
73+
#define GOSSIP_ANNOUNCE_DELAY(dev_fast_gossip_flag) \
74+
DEV_FAST_GOSSIP(dev_fast_gossip_flag, 1, 60)
75+
76+
/* How long before deadline should we send refresh update? 1 day normally */
77+
#define GOSSIP_BEFORE_DEADLINE(dev_fast_gossip_flag) \
78+
DEV_FAST_GOSSIP(dev_fast_gossip_flag, 30, 24*60*60)
79+
4380
#endif /* LIGHTNING_GOSSIPD_GOSSIP_CONSTANTS_H */

gossipd/gossip_wire.csv

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ msgdata,gossipctl_init,gflen,u16,
1010
msgdata,gossipctl_init,globalfeatures,u8,gflen
1111
msgdata,gossipctl_init,rgb,u8,3
1212
msgdata,gossipctl_init,alias,u8,32
13-
msgdata,gossipctl_init,update_channel_interval,u32,
14-
msgdata,gossipctl_init,gossip_min_interval,u32,
1513
msgdata,gossipctl_init,num_announcable,u16,
1614
msgdata,gossipctl_init,announcable,wireaddr,num_announcable
1715
msgdata,gossipctl_init,dev_gossip_time,?u32,
16+
msgdata,gossipctl_init,dev_fast_gossip,bool,
1817

1918
# In developer mode, we can mess with time.
2019
msgtype,gossip_dev_set_time,3001

gossipd/gossipd.c

+11-21
Original file line numberDiff line numberDiff line change
@@ -1832,16 +1832,13 @@ static void gossip_refresh_network(struct daemon *daemon)
18321832
s64 highwater;
18331833
struct node *n;
18341834

1835-
/* For DEVELOPER testing, this can be set really short; otherwise, we
1836-
* set it to 1 day before deadline. */
1837-
if (daemon->rstate->prune_timeout < 24*3600)
1838-
highwater = now - daemon->rstate->prune_timeout / 2;
1839-
else
1840-
highwater = now - (daemon->rstate->prune_timeout - 24*3600);
1835+
/* Send out 1 day before deadline */
1836+
highwater = now - (GOSSIP_PRUNE_INTERVAL(daemon->rstate->dev_fast_gossip)
1837+
- GOSSIP_BEFORE_DEADLINE(daemon->rstate->dev_fast_gossip));
18411838

1842-
/* Schedule next run now (prune_timeout is 2 weeks) */
1839+
/* Schedule next run now */
18431840
notleak(new_reltimer(&daemon->timers, daemon,
1844-
time_from_sec(daemon->rstate->prune_timeout/4),
1841+
time_from_sec(GOSSIP_PRUNE_INTERVAL(daemon->rstate->dev_fast_gossip)/4),
18451842
gossip_refresh_network, daemon));
18461843

18471844
/* Find myself in the network */
@@ -1980,32 +1977,25 @@ static struct io_plan *gossip_init(struct io_conn *conn,
19801977
struct daemon *daemon,
19811978
const u8 *msg)
19821979
{
1983-
u32 update_channel_interval;
19841980
u32 *dev_gossip_time;
1981+
bool dev_fast_gossip;
19851982

19861983
if (!fromwire_gossipctl_init(daemon, msg,
19871984
&daemon->chain_hash,
19881985
&daemon->id, &daemon->globalfeatures,
19891986
daemon->rgb,
19901987
daemon->alias,
1991-
/* 1 week in seconds
1992-
* (unless --dev-channel-update-interval) */
1993-
&update_channel_interval,
1994-
/* 5 minutes, or
1995-
* --dev-broadcast-interval * 5 seconds */
1996-
&daemon->gossip_min_interval,
19971988
&daemon->announcable,
1998-
&dev_gossip_time)) {
1989+
&dev_gossip_time, &dev_fast_gossip)) {
19991990
master_badmsg(WIRE_GOSSIPCTL_INIT, msg);
20001991
}
20011992

2002-
/* Prune time (usually 2 weeks) is twice update time */
20031993
daemon->rstate = new_routing_state(daemon,
20041994
chainparams_by_chainhash(&daemon->chain_hash),
20051995
&daemon->id,
2006-
update_channel_interval * 2,
20071996
&daemon->peers,
2008-
take(dev_gossip_time));
1997+
take(dev_gossip_time),
1998+
dev_fast_gossip);
20091999

20102000
/* Load stored gossip messages */
20112001
if (!gossip_store_load(daemon->rstate, daemon->rstate->gs))
@@ -2018,9 +2008,9 @@ static struct io_plan *gossip_init(struct io_conn *conn,
20182008
* or addresses might have changed!) */
20192009
maybe_send_own_node_announce(daemon);
20202010

2021-
/* Start the weekly refresh timer. */
2011+
/* Start the twice- weekly refresh timer. */
20222012
notleak(new_reltimer(&daemon->timers, daemon,
2023-
time_from_sec(daemon->rstate->prune_timeout/4),
2013+
time_from_sec(GOSSIP_PRUNE_INTERVAL(daemon->rstate->dev_fast_gossip) / 4),
20242014
gossip_refresh_network, daemon));
20252015

20262016
return daemon_conn_read_next(conn, daemon->master);

gossipd/gossipd.h

-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ struct daemon {
3333
/* Timers: we batch gossip, and also refresh announcements */
3434
struct timers timers;
3535

36-
/* Minimum interval for generating updated gossip */
37-
u32 gossip_min_interval;
38-
3936
/* Global features to list in node_announcement. */
4037
u8 *globalfeatures;
4138

gossipd/make_gossip.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ static void update_own_node_announcement(struct daemon *daemon)
170170
* previous `node_announcement` it has previously created.
171171
*/
172172
/* We do better: never send them within more than 5 minutes. */
173-
next = self->bcast.timestamp + daemon->gossip_min_interval;
173+
next = self->bcast.timestamp
174+
+ GOSSIP_MIN_INTERVAL(daemon->rstate->dev_fast_gossip);
174175

175176
if (timestamp < next) {
176177
status_debug("node_announcement: delaying %u secs",
@@ -260,7 +261,7 @@ static void update_local_channel(struct local_cupdate *lc /* frees! */)
260261
/* Create an unsigned channel_update: we backdate enables, so
261262
* we can always send a disable in an emergency. */
262263
if (!lc->disable)
263-
timestamp -= daemon->gossip_min_interval;
264+
timestamp -= GOSSIP_MIN_INTERVAL(daemon->rstate->dev_fast_gossip);
264265

265266
/* BOLT #7:
266267
*
@@ -321,7 +322,8 @@ static void update_local_channel(struct local_cupdate *lc /* frees! */)
321322
}
322323

323324
/* Is it too soon to send another update? */
324-
next = hc->bcast.timestamp + daemon->gossip_min_interval;
325+
next = hc->bcast.timestamp
326+
+ GOSSIP_MIN_INTERVAL(daemon->rstate->dev_fast_gossip);
325327

326328
if (timestamp < next) {
327329
status_debug("channel_update %s/%u: delaying %u secs",

gossipd/routing.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static bool timestamp_reasonable(struct routing_state *rstate, u32 timestamp)
205205
if (timestamp > now + 24*60*60)
206206
return false;
207207
/* More than 2 weeks behind? */
208-
if (timestamp < now - rstate->prune_timeout)
208+
if (timestamp < now - GOSSIP_PRUNE_INTERVAL(rstate->dev_fast_gossip))
209209
return false;
210210
return true;
211211
}
@@ -234,16 +234,15 @@ static void memleak_help_routing_tables(struct htable *memtable,
234234
struct routing_state *new_routing_state(const tal_t *ctx,
235235
const struct chainparams *chainparams,
236236
const struct node_id *local_id,
237-
u32 prune_timeout,
238237
struct list_head *peers,
239-
const u32 *dev_gossip_time TAKES)
238+
const u32 *dev_gossip_time TAKES,
239+
bool dev_fast_gossip)
240240
{
241241
struct routing_state *rstate = tal(ctx, struct routing_state);
242242
rstate->nodes = new_node_map(rstate);
243243
rstate->gs = gossip_store_new(rstate, peers);
244244
rstate->chainparams = chainparams;
245245
rstate->local_id = *local_id;
246-
rstate->prune_timeout = prune_timeout;
247246
rstate->local_channel_announced = false;
248247

249248
pending_cannouncement_map_init(&rstate->pending_cannouncements);
@@ -263,6 +262,7 @@ struct routing_state *new_routing_state(const tal_t *ctx,
263262
rstate->gossip_time->ts.tv_nsec = 0;
264263
} else
265264
rstate->gossip_time = NULL;
265+
rstate->dev_fast_gossip = dev_fast_gossip;
266266
#endif
267267
tal_add_destructor(rstate, destroy_routing_state);
268268
memleak_add_helper(rstate, memleak_help_routing_tables);
@@ -2000,7 +2000,7 @@ bool routing_add_channel_update(struct routing_state *rstate,
20002000
}
20012001

20022002
/* Allow redundant updates once every 7 days */
2003-
if (timestamp < hc->bcast.timestamp + rstate->prune_timeout / 2
2003+
if (timestamp < hc->bcast.timestamp + GOSSIP_PRUNE_INTERVAL(rstate->dev_fast_gossip) / 2
20042004
&& !cupdate_different(rstate->gs, hc, update)) {
20052005
status_debug("Ignoring redundant update for %s/%u"
20062006
" (last %u, now %u)",
@@ -2351,7 +2351,7 @@ bool routing_add_node_announcement(struct routing_state *rstate,
23512351
}
23522352

23532353
/* Allow redundant updates once every 7 days */
2354-
if (timestamp < node->bcast.timestamp + rstate->prune_timeout / 2
2354+
if (timestamp < node->bcast.timestamp + GOSSIP_PRUNE_INTERVAL(rstate->dev_fast_gossip) / 2
23552355
&& !nannounce_different(rstate->gs, node, msg)) {
23562356
status_debug("Ignoring redundant nannounce for %s"
23572357
" (last %u, now %u)",
@@ -2698,7 +2698,7 @@ void route_prune(struct routing_state *rstate)
26982698
{
26992699
u64 now = gossip_time_now(rstate).ts.tv_sec;
27002700
/* Anything below this highwater mark ought to be pruned */
2701-
const s64 highwater = now - rstate->prune_timeout;
2701+
const s64 highwater = now - GOSSIP_PRUNE_INTERVAL(rstate->dev_fast_gossip);
27022702
struct chan **pruned = tal_arr(tmpctx, struct chan *, 0);
27032703
u64 idx;
27042704

0 commit comments

Comments
 (0)