diff --git a/lightningd/anchorspend.c b/lightningd/anchorspend.c index dccd98268..aa64c4316 100644 --- a/lightningd/anchorspend.c +++ b/lightningd/anchorspend.c @@ -219,7 +219,7 @@ struct anchor_details *create_anchor_details(const tal_t *ctx, final_deadline = adet->vals[tal_count(adet->vals) - 1].block; /* "Two weeks later" */ - v.block = final_deadline + 2016; + v.block = final_deadline + ld->dev_low_prio_anchor_blocks; v.msat = AMOUNT_MSAT(0); v.important = false; tal_arr_expand(&adet->vals, v); diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index c8b1eda2a..aa6ab1824 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -143,6 +143,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx) ld->dev_no_htlc_timeout = false; ld->dev_no_version_checks = false; ld->dev_max_funding_unconfirmed = 2016; + ld->dev_low_prio_anchor_blocks = 2016; ld->dev_ignore_modern_onion = false; ld->dev_disable_commit = -1; ld->dev_no_ping_timer = false; diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index 37ae7b930..6834aa38a 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -307,6 +307,9 @@ struct lightningd { bool dev_throttle_gossip; bool dev_suppress_gossip; + /* How long to aim for low-priority commitment closes */ + u32 dev_low_prio_anchor_blocks; + /* Speedup reconnect delay, for testing. */ bool dev_fast_reconnect; diff --git a/lightningd/options.c b/lightningd/options.c index 65c2986e8..a2c0f46af 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -969,15 +969,19 @@ static void dev_register_opts(struct lightningd *ld) opt_set_bool, &ld->dev_limit_connections_inflight, "Throttle connection limiting down for testing."); + clnopt_witharg("--autoconnect-seeker-peers", OPT_SHOWINT, + opt_set_u32, opt_show_u32, + &ld->autoconnect_seeker_peers, + "Seeker autoconnects to maintain this minimum number of gossip peers"); + clnopt_witharg("--dev-low-prio-anchor-blocks", OPT_DEV|OPT_SHOWINT, + opt_set_u32, opt_show_u32, + &ld->dev_low_prio_anchor_blocks, + "How many blocks to aim for low-priority anchor closes (default: 2016)"); /* This is handled directly in daemon_developer_mode(), so we ignore it here */ clnopt_noarg("--dev-debug-self", OPT_DEV, opt_ignore, NULL, "Fire up a terminal window with a debugger in it on initialization"); - clnopt_witharg("--autoconnect-seeker-peers", OPT_SHOWINT, - opt_set_u32, opt_show_u32, - &ld->autoconnect_seeker_peers, - "Seeker autoconnects to maintain this minimum number of gossip peers"); } static const struct config testnet_config = { diff --git a/tests/test_closing.py b/tests/test_closing.py index 90883c840..047d9e420 100644 --- a/tests/test_closing.py +++ b/tests/test_closing.py @@ -4219,3 +4219,32 @@ def test_onchain_slow_anchor(node_factory, bitcoind): # We will have a super-low-prio anchor spend. l1.daemon.wait_for_log(r"Low-priority anchorspend aiming for block {} \(feerate 253\)".format(close_start_depth + 2016)) + + # Restart with reduced block time. + l1.stop() + l1.daemon.opts['dev-low-prio-anchor-blocks'] = 20 + l1.start() + + l1.daemon.wait_for_log("Low-priority anchorspend aiming for block {}".format(close_start_depth + 20)) + l1.daemon.wait_for_log("Anchorspend for local commit tx") + + # Won't go under 12 blocks though. + + # Make sure it sees all these blocks at once, to avoid test flakes! + l1.stop() + bitcoind.generate_block(7) + l1.start() + + height = bitcoind.rpc.getblockchaininfo()['blocks'] + l1.daemon.wait_for_log(r"Low-priority anchorspend aiming for block {} \(feerate 7458\)".format(height + 13)) + l1.daemon.wait_for_log(r"Anchorspend for local commit tx fee 12335sat \(w=714\), commit_tx fee 4545sat \(w=768\): package feerate 11390 perkw") + assert not l1.daemon.is_in_log("Low-priority anchorspend aiming for block {}".format(height + 12)) + + bitcoind.generate_block(1) + height = bitcoind.rpc.getblockchaininfo()['blocks'] + l1.daemon.wait_for_log(r"Low-priority anchorspend aiming for block {} \(feerate 7500\)".format(height + 12)) + # Note: fee is too similar, so won't try to RBF, so no "Anchorspend for local commit tx" + + bitcoind.generate_block(1) + height = bitcoind.rpc.getblockchaininfo()['blocks'] + l1.daemon.wait_for_log(r"Low-priority anchorspend aiming for block {} \(feerate 7500\)".format(height + 12))