Skip to content

Commit 642ca0a

Browse files
committed
pytest: test for slow start when closing tx and large number of addresses.
From Whitslack's "startup takes 15 minutes" bug report, we can see that wallet_can_spend is extremely slow. We exacerbate this by setting a large bip32_max_index: ``` 91.29% 0.02% lightningd lightningd [.] wallet_can_spend | --91.27%--wallet_can_spend | |--47.81%--scriptpubkey_p2tr_derkey | | | |--42.80%--scriptpubkey_p2tr ... |--42.16%--bip32_key_from_parent ``` Signed-off-by: Rusty Russell <[email protected]>
1 parent 36b3883 commit 642ca0a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/test_closing.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import re
1919
import subprocess
2020
import threading
21+
import time
2122
import unittest
2223

2324

@@ -4237,3 +4238,42 @@ def censoring_sendrawtx(r):
42374238
bitcoind.generate_block(1)
42384239
height = bitcoind.rpc.getblockchaininfo()['blocks']
42394240
l1.daemon.wait_for_log(r"Low-priority anchorspend aiming for block {} \(feerate 7500\)".format(height + 12))
4241+
4242+
4243+
@pytest.mark.slow_test
4244+
@pytest.mark.xfail(strict=True)
4245+
@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "Depends on sqlite3 database location")
4246+
def test_slow_startup_many_addresses(node_factory, bitcoind):
4247+
l1, l2 = node_factory.get_nodes(2)
4248+
4249+
# Use really high key, to make scanning work hard.
4250+
l1.stop()
4251+
l1.db_manip("INSERT INTO vars (name, intval) VALUES ('bip32_max_index', 10000);")
4252+
l1.start()
4253+
4254+
NUM_CHANS = 20
4255+
FUND = 100000
4256+
4257+
addr = l1.rpc.newaddr()['bech32']
4258+
bitcoind.rpc.sendtoaddress(addr, (FUND * NUM_CHANS + 1000000) / 10**8)
4259+
4260+
bitcoind.generate_block(1)
4261+
sync_blockheight(bitcoind, [l1])
4262+
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
4263+
4264+
channels = []
4265+
for _ in range(NUM_CHANS):
4266+
channels.append(l1.rpc.fundchannel(l2.info['id'], FUND)['channel_id'])
4267+
bitcoind.generate_block(1)
4268+
wait_for(lambda: all([c['state'] == 'CHANNELD_NORMAL' for c in l1.rpc.listpeerchannels()['channels']]))
4269+
4270+
for c in channels:
4271+
l1.rpc.close(c)
4272+
4273+
l1.stop()
4274+
start = time.time()
4275+
l1.start()
4276+
end = time.time()
4277+
4278+
# Normally less than a second: give it 10.
4279+
assert end - start < 10

0 commit comments

Comments
 (0)