From 7bbfef5054ec222d6675b52fa6953e06aba6fef0 Mon Sep 17 00:00:00 2001 From: niftynei Date: Sat, 23 Jul 2022 11:21:31 -0500 Subject: [PATCH] tests: flake fix; l1 was waiting too long to reconnect We were waiting too long for the reconnect to happen (60s default), which caused this test to timeout. When testing, let's speed up the reconnect. L2 tried to reconnect but didn't have connection information in its gossip -- is there a way to ask/save connection data from a node you're making a channel with that doesn't rely on their node_announcement? --- lightningd/connect_control.c | 4 +++- lightningd/connect_control.h | 5 +++++ lightningd/lightningd.c | 1 + lightningd/lightningd.h | 3 +++ lightningd/options.c | 4 ++++ tests/test_misc.py | 4 ++-- 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lightningd/connect_control.c b/lightningd/connect_control.c index 3370200e2..36ec83bdc 100644 --- a/lightningd/connect_control.c +++ b/lightningd/connect_control.c @@ -364,8 +364,10 @@ static void connect_failed(struct lightningd *ld, u32 delay; if (seconds_to_delay) delay = *seconds_to_delay; + else if (peer->delay_reconnect) + delay = DEV_FAST_RECONNECT(ld->dev_fast_reconnect, 3, 60); else - delay = peer->delay_reconnect ? 60 : 1; + delay = 1; log_peer_debug(ld->log, id, "Reconnecting in %u seconds", delay); try_reconnect(peer, peer, delay, addrhint); } else diff --git a/lightningd/connect_control.h b/lightningd/connect_control.h index 4a3adb07b..5eaa3c98d 100644 --- a/lightningd/connect_control.h +++ b/lightningd/connect_control.h @@ -3,12 +3,17 @@ #include "config.h" #include #include +#include struct lightningd; struct peer; struct pubkey; struct wireaddr_internal; +/* Speedy reconnect timeout! */ +#define DEV_FAST_RECONNECT(dev_fast_reconnect_flag, fast, normal) \ + IFDEV((dev_fast_reconnect_flag) ? (fast) : (normal), (normal)) + /* Returns fd for gossipd to talk to connectd */ int connectd_init(struct lightningd *ld); void connectd_activate(struct lightningd *ld); diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index e15a0309a..eccf43800 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -125,6 +125,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx) ld->dev_gossip_time = 0; ld->dev_fast_gossip = false; ld->dev_fast_gossip_prune = false; + ld->dev_fast_reconnect = false; ld->dev_force_privkey = NULL; ld->dev_force_bip32_seed = NULL; ld->dev_force_channel_secrets = NULL; diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index 5440384b7..401dba808 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -244,6 +244,9 @@ struct lightningd { bool dev_fast_gossip; bool dev_fast_gossip_prune; + /* Speedup reconnect delay, for testing. */ + bool dev_fast_reconnect; + /* This is the forced private key for the node. */ struct privkey *dev_force_privkey; diff --git a/lightningd/options.c b/lightningd/options.c index 7fc77e26b..45a01ca45 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -691,6 +691,10 @@ static void dev_register_opts(struct lightningd *ld) opt_register_noarg("--dev-no-reconnect", opt_set_invbool, &ld->reconnect, "Disable automatic reconnect-attempts by this node, but accept incoming"); + opt_register_noarg("--dev-fast-reconnect", opt_set_bool, + &ld->dev_fast_reconnect, + "Make default reconnect delay 3 (not 60) seconds"); + opt_register_noarg("--dev-fail-on-subdaemon-fail", opt_set_bool, &ld->dev_subdaemon_fail, opt_hidden); opt_register_arg("--dev-disconnect=", opt_subd_dev_disconnect, diff --git a/tests/test_misc.py b/tests/test_misc.py index 263c9e439..8607a6c9d 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -1132,7 +1132,7 @@ def test_funding_reorg_private(node_factory, bitcoind): l2.daemon.wait_for_log(r'Deleting channel') -@pytest.mark.developer("needs DEVELOPER=1") +@pytest.mark.developer("needs DEVELOPER=1", "uses --dev-fast-reconnect") @pytest.mark.openchannel('v1') @pytest.mark.openchannel('v2') def test_funding_reorg_remote_lags(node_factory, bitcoind): @@ -1140,7 +1140,7 @@ def test_funding_reorg_remote_lags(node_factory, bitcoind): """ # may_reconnect so channeld will restart; bad gossip can happen due to reorg opts = {'funding-confirms': 1, 'may_reconnect': True, 'allow_bad_gossip': True, - 'allow_warning': True} + 'allow_warning': True, 'dev-fast-reconnect': None} l1, l2 = node_factory.line_graph(2, fundchannel=False, opts=opts) l1.fundwallet(10000000) sync_blockheight(bitcoind, [l1]) # height 102