Skip to content

Commit

Permalink
lightningd: --dev-low-prio-anchor-blocks and test for low-priority an…
Browse files Browse the repository at this point in the history
…chors.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Nov 26, 2024
1 parent de30f9c commit 20257c3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lightningd/anchorspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions lightningd/lightningd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 8 additions & 4 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
29 changes: 29 additions & 0 deletions tests/test_closing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4219,3 +4219,32 @@ def censoring_sendrawtx(r):

# 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))

0 comments on commit 20257c3

Please sign in to comment.