Skip to content

Multiple bitcoind instances can point to the same -walletdir on Windows #18622

@mtrycz

Description

@mtrycz

I was building Bitcoin Core on my Windows machine, on WSL/Ubuntu. I tried to run the tests and ran into a problem. The test in test/functional/wallet_multiwallet.py failed. Follows the output of the test:

mtrycz@LAPTOP-00AACAV2:~/git/bitcoin/test/functional$ ./test_runner.py wallet_multiwallet.py
Temporary test directory at /tmp/test_runner_₿_🏃_20200413_152720
Remaining jobs: [wallet_multiwallet.py]
1/1 - wallet_multiwallet.py failed, Duration: 9 s

stdout:
2020-04-13T13:27:20.407000Z TestFramework (INFO): Initializing test directory /tmp/test_runner_₿_🏃_20200413_152720/wallet_multiwallet_0
2020-04-13T13:27:24.947000Z TestFramework (INFO): Do not allow -zapwallettxes with multiwallet
2020-04-13T13:27:25.745000Z TestFramework (INFO): Do not allow -salvagewallet with multiwallet
2020-04-13T13:27:26.278000Z TestFramework (INFO): Do not allow -upgradewallet with multiwallet
2020-04-13T13:27:29.060000Z TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/home/mtrycz/git/bitcoin/test/functional/test_framework/test_framework.py", line 112, in main
    self.run_test()
  File "/home/mtrycz/git/bitcoin/test/functional/wallet_multiwallet.py", line 152, in run_test
    self.nodes[1].assert_start_raises_init_error(['-walletdir=' + competing_wallet_dir], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
  File "/home/mtrycz/git/bitcoin/test/functional/test_framework/test_node.py", line 460, in assert_start_raises_init_error
    self._raise_assertion_error(assert_msg)
  File "/home/mtrycz/git/bitcoin/test/functional/test_framework/test_node.py", line 157, in _raise_assertion_error
    raise AssertionError(self._node_msg(msg))
AssertionError: [node 1] bitcoind should have exited with expected error Error: Error initializing wallet database environment \"\S+competing_walletdir\"!
2020-04-13T13:27:29.113000Z TestFramework (INFO): Stopping nodes
2020-04-13T13:27:29.215000Z TestFramework (WARNING): Not cleaning up dir /tmp/test_runner_₿_🏃_20200413_152720/wallet_multiwallet_0
2020-04-13T13:27:29.215000Z TestFramework (ERROR): Test failed. Test logging available at /tmp/test_runner_₿_🏃_20200413_152720/wallet_multiwallet_0/test_framework.log
2020-04-13T13:27:29.215000Z TestFramework (ERROR): Hint: Call /home/mtrycz/git/bitcoin/test/functional/combine_logs.py '/tmp/test_runner_₿_🏃_20200413_152720/wallet_multiwallet_0' to consolidate all logs


stderr:



TEST                  | STATUS    | DURATION

wallet_multiwallet.py | ✖ Failed  | 9 s

ALL                   | ✖ Failed  | 9 s (accumulated)
Runtime: 9 s

I traced the cause to a node being able to open a wallet that is already open by another node.

To the best of my understanding mutliple bitcoind instances shouldn't be able to point to the same datadirs or walletdirs. On Windows it is possible to have multiple bitcoind instances to point to the same walletdir, leading to possible data corruption. To the best of my understanding this is not possible on Linux (can't confirm atm).

Manual test plan:

  1. Download the latest Windows release binaries (version v.0.19.1)
  2. Create two directories, for example C:\node0 and C:\node1; create a bitcoin.conf file in C:\node1 with a single line rpcport=8333 (otherwise the second node will fail for an unrelated reason)
  3. Open a command prompt and run bitcoind.exe -datadir=C:\node0 -walletdir=D:\bchwallettest
  4. Open a second prompt and run bitcoind.exe -datadir=C:\node1 -walletdir=D:\bchwallettest
  5. Expect the second node to fail at startup

I've run this test myself and can confirm that the second node erroneously starts. The bug was reproduced on Windows 10 Pro, both in cmd and in WSL shell, with the latest release v.0.19.1.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions