balance wrong after unloading wallet and loading it again #15591

issue benwilliams opened this issue on March 13, 2019
  1. benwilliams commented at 12:34 PM on March 13, 2019: none

    <!-- This issue tracker is only for technical issues related to Bitcoin Core. General bitcoin questions and/or support requests are best directed to the Bitcoin StackExchange at https://bitcoin.stackexchange.com. For reporting security issues, please read instructions at https://bitcoincore.org/en/contact/. If the node is "stuck" during sync or giving "block checksum mismatch" errors, please ensure your hardware is stable by running memtest and observe CPU temperature with a load-test tool such as linpack before creating an issue! -->

    <!-- Describe the issue -->

    Have two wallets used by this instance of bitcoind. The default wallet has balance 0.02861762. Initially reported balance is correct but after unloading the wallet and then loading it again, the balance is wrong. Neither of the wallets have the reported balance.

    <!--- What behavior did you expect? -->

    I expected the balance to be the same as initially reported.

    btc@ubuntu:~$ bitcoin-cli  -getinfo
    {
      "version": 170100,
      "protocolversion": 70015,
      "walletversion": 159900,
      "balance": 0.02861762,
    ...
    
    btc@ubuntu:~$ bitcoin-cli  loadwallet wallet2
    btc@ubuntu:~$ bitcoin-cli unloadwallet ""
    btc@ubuntu:~$ bitcoin-cli loadwallet ""
    btc@ubuntu:~$ bitcoin-cli unloadwallet wallet2
    btc@ubuntu:~$ bitcoin-cli  -getinfo
    {
      "version": 170100,
      "protocolversion": 70015,
      "walletversion": 159900,
      "balance": 0.01012607,
    ...
    

    The balance 0.01012607 is wrong and I have no idea where that number came from. Restarting the process results in correct balance again.

    <!--- What was the actual behavior (provide screenshots if the issue is GUI-related)? -->

    <!--- How reliably can you reproduce the issue, what are the steps to do so? -->

    <!-- What version of Bitcoin Core are you using, where did you get it (website, self-compiled, etc)? -->

    ubuntu package for bionic

    <!-- What type of machine are you observing the error on (OS/CPU and disk type)? -->

    <!-- For the GUI-related issue on Linux provide names and versions of a distro, a desktop environment and a graphical shell (if relevant). -->

    <!-- Any extra information that might be useful in the debugging process. -->

    <!--- This is normally the contents of a `debug.log` or `config.log` file. Raw text or a link to a pastebin type site are preferred. -->

  2. fanquake added the label Wallet on Mar 14, 2019
  3. fanquake assigned meshcollider on Mar 14, 2019
  4. benwilliams commented at 11:48 AM on March 16, 2019: none

    The issue is no longer happening. I repeated the exact same steps as before and it is working correctly now and unable to replicate it again. I still have the terminal window open to prove it occurred and I'm not going crazy. The wallets were originally on Intel hardware and were moved onto a newer OS on AMD hardware. Surely that wouldn't have caused issues?

  5. meshcollider commented at 8:09 AM on March 18, 2019: contributor

    I've managed to replicate similar inconsistency following your method. EDIT: I've also managed to achieve this simply by unloading and then loading the wallet:

    $ ./bitcoind -regtest -datadir=../datadir &
    $ ./bitcoin-cli -regtest -datadir=../datadir -getinfo
    {
      "version": 189900,
      "protocolversion": 70015,
      "blocks": 200,
      "chain": "regtest",
      "walletversion": 169900,
      "balance": 4999.99996680,
       ...
    }
    $ ./bitcoin-cli -regtest -datadir=../datadir unloadwallet ""
    $ ./bitcoin-cli -regtest -datadir=../datadir loadwallet ""
    $ ./bitcoin-cli -regtest -datadir=../datadir -getinfo
    {
      "version": 189900,
      "protocolversion": 70015,
      "blocks": 200,
      "chain": "regtest",
      "walletversion": 169900,
      "balance": 4950.00000000,
       ...
    }
    

    Notice the second balance is nearly 50 BTC less than the first. I'll look into this.

  6. MarcoFalke added this to the milestone 0.18.0 on Mar 22, 2019
  7. MarcoFalke commented at 8:22 PM on March 22, 2019: member

    Assigned milestone 0.18.0

  8. MarcoFalke commented at 8:24 PM on March 22, 2019: member

    Is this a regression from 0.17.1?

  9. promag commented at 11:38 PM on March 22, 2019: member

    @MarcoFalke the issue exists since loadwallet was added, so should also be fixed in 0.17.2 and 0.18 rc3.

    The problem is that dynamically loaded wallet don't see mempool transactions.

    It's more clear if you use getwalletinfo (instead of -getinfo) and observe unconfirmed_balance.

    Not sure what should be the right fix. There is https://github.com/bitcoin/bitcoin/blob/68520597ccf8ff3f6e8a7ad6869b06bf2012ae8a/src/wallet/wallet.cpp#L4399-L4404 but should it also do?

         // Add mempool transactions that aren't yet in the wallet
    
  10. promag commented at 11:53 PM on March 22, 2019: member

    To reproduce, use one wallet test1 to send a transaction to another wallet test2 while test2 is unloaded, then load test2:

    # generate on test1
    bitcoind -regtest -wallet=test1 &
    bitcoin-cli -regtest getnewaddress
    bitcoin-cli -regtest generatetoaddress 101 $(bitcoin-cli -regtest getnewaddress)
    
    # create test2, get receiving address and unload the wallet
    bitcoin-cli -regtest createwallet test2
    A=$(bitcoin-cli -regtest -rpcwallet=test2 getnewaddress)
    bitcoin-cli -regtest -rpcwallet=test2 unloadwallet
    
    # send value to the above address and check balance
    bitcoin-cli -regtest sendtoaddress $A 1
    bitcoin-cli -regtest loadwallet test2
    bitcoin-cli -regtest -rpcwallet=test2 getwalletinfo
    {
      "walletname": "test2",
      "walletversion": 169900,
      "balance": 0.00000000,
      "unconfirmed_balance": 0.00000000,
      ...
    
    # restart now with wallet test2 and check balance
    bitcoin-cli -regtest stop
    bitcoind -regtest -wallet=test2
    bitcoin-cli -regtest getwalletinfo
    {
      "walletname": "test2",
      "walletversion": 169900,
      "balance": 0.00000000,
      "unconfirmed_balance": 1.00000000,
    

    Note: I've run the above in branch 0.17.

  11. MarcoFalke closed this on Apr 1, 2019

  12. MarcoFalke referenced this in commit 5a2a9b5b06 on Apr 1, 2019
  13. DrahtBot locked this on Dec 16, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-21 18:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me