From e4950db9a36b2fd4784f8cf00e196fa4f1b80817 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 2 Dec 2020 16:44:45 +1030 Subject: [PATCH] pytest: recreate wallet on bitcoind restart. Doesn't seem to stick in master. Andy Chow suggested we simply turn off wallet on older versions, and always create/load. ``` [gw8] [ 40%] FAILED tests/test_misc.py::test_bitcoind_goes_backwards ============================================================= FAILURES ============================================================== ___________________________________________________ test_bitcoind_goes_backwards ____________________________________________________ [gw8] linux -- Python 3.8.5 /usr/bin/python3 node_factory = bitcoind = def test_bitcoind_goes_backwards(node_factory, bitcoind): """Check that we refuse to acknowledge bitcoind giving a shorter chain without explicit rescan""" l1 = node_factory.get_node(may_fail=True, allow_broken_log=True) bitcoind.generate_block(10) sync_blockheight(bitcoind, [l1]) l1.stop() # Now shrink chain (invalidateblock leaves 'headers' field until restart) bitcoind.rpc.invalidateblock(bitcoind.rpc.getblockhash(105)) # Restart without killing proxies bitcoind.rpc.stop() TailableProc.stop(bitcoind) bitcoind.start() # Will simply refuse to start. with pytest.raises(ValueError): l1.start() # Nor will it start with if we ask for a reindex of fewer blocks. l1.daemon.opts['rescan'] = 3 with pytest.raises(ValueError): l1.start() # This will force it, however. l1.daemon.opts['rescan'] = -100 l1.start() # Now mess with bitcoind at runtime. > bitcoind.generate_block(6) tests/test_misc.py:1307: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ contrib/pyln-testing/pyln/testing/utils.py:399: in generate_block return self.rpc.generatetoaddress(numblocks, self.rpc.getnewaddress()) contrib/pyln-testing/pyln/testing/utils.py:322: in f return proxy._call(name, *args) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , service_name = 'getnewaddress', args = () postdata = '{"version": "1.1", "method": "getnewaddress", "params": [], "id": 1}' headers = {'Authorization': b'Basic cnBjdXNlcjpycGNwYXNz', 'Content-type': 'application/json', 'Host': 'localhost', 'User-Agent': 'AuthServiceProxy/0.1'} response = {'error': {'code': -18, 'message': 'No wallet is loaded. Load a wallet using loadwallet or create a new one with createwallet. (Note: A default wallet is no longer automatically created)'}, 'id': 1, 'result': None} ``` --- contrib/pyln-testing/pyln/testing/fixtures.py | 8 -------- contrib/pyln-testing/pyln/testing/utils.py | 8 +++++++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/contrib/pyln-testing/pyln/testing/fixtures.py b/contrib/pyln-testing/pyln/testing/fixtures.py index 2353dcf61..ea6ccdc5f 100644 --- a/contrib/pyln-testing/pyln/testing/fixtures.py +++ b/contrib/pyln-testing/pyln/testing/fixtures.py @@ -138,14 +138,6 @@ def bitcoind(directory, teardown_checks): raise ValueError("elementsd is too old. At least version 160000 (v0.16.0)" " is needed, current version is {}".format(info['version'])) - # Make sure we have a wallet, starting with 0.21 there is no default wallet - # anymore. - # FIXME: if we update the testsuite to use the upcoming 0.21 release we - # could switch to descriptor wallets and speed bitcoind operations - # consequently. - if not bitcoind.rpc.listwallets(): - bitcoind.rpc.createwallet("lightningd-tests") - info = bitcoind.rpc.getblockchaininfo() # Make sure we have some spendable funds if info['blocks'] < 101: diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py index e45f41728..733edb449 100644 --- a/contrib/pyln-testing/pyln/testing/utils.py +++ b/contrib/pyln-testing/pyln/testing/utils.py @@ -1,5 +1,6 @@ from bitcoin.core import COIN # type: ignore from bitcoin.rpc import RawProxy as BitcoinProxy # type: ignore +from bitcoin.rpc import JSONRPCError from pyln.client import RpcError from pyln.testing.btcproxy import BitcoinRpcProxy from collections import OrderedDict @@ -351,7 +352,7 @@ class BitcoinD(TailableProc): '-logtimestamps', '-nolisten', '-txindex', - '-wallet="test"', + '-nowallet', '-addresstype=bech32' ] # For up to and including 0.16.1, this needs to be in main section. @@ -369,6 +370,10 @@ class BitcoinD(TailableProc): self.wait_for_log("Done loading", timeout=TIMEOUT) logging.info("BitcoinD started") + try: + self.rpc.createwallet("lightningd-tests") + except JSONRPCError: + self.rpc.loadwallet("lightningd-tests") def stop(self): for p in self.proxies: @@ -461,6 +466,7 @@ class ElementsD(BitcoinD): '-server', '-logtimestamps', '-nolisten', + '-nowallet', '-validatepegin=0', '-con_blocksubsidy=5000000000', ]