balance wrong after unloading wallet and loading it again #15591

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

    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.

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

     0btc@ubuntu:~$ bitcoin-cli  -getinfo
     1{
     2  "version": 170100,
     3  "protocolversion": 70015,
     4  "walletversion": 159900,
     5  "balance": 0.02861762,
     6...
     7
     8btc@ubuntu:~$ bitcoin-cli  loadwallet wallet2
     9btc@ubuntu:~$ bitcoin-cli unloadwallet ""
    10btc@ubuntu:~$ bitcoin-cli loadwallet ""
    11btc@ubuntu:~$ bitcoin-cli unloadwallet wallet2
    12btc@ubuntu:~$ bitcoin-cli  -getinfo
    13{
    14  "version": 170100,
    15  "protocolversion": 70015,
    16  "walletversion": 159900,
    17  "balance": 0.01012607,
    18...
    

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

    ubuntu package for bionic

  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:

     0$ ./bitcoind -regtest -datadir=../datadir &
     1$ ./bitcoin-cli -regtest -datadir=../datadir -getinfo
     2{
     3  "version": 189900,
     4  "protocolversion": 70015,
     5  "blocks": 200,
     6  "chain": "regtest",
     7  "walletversion": 169900,
     8  "balance": 4999.99996680,
     9   ...
    10}
    11$ ./bitcoin-cli -regtest -datadir=../datadir unloadwallet ""
    12$ ./bitcoin-cli -regtest -datadir=../datadir loadwallet ""
    13$ ./bitcoin-cli -regtest -datadir=../datadir -getinfo
    14{
    15  "version": 189900,
    16  "protocolversion": 70015,
    17  "blocks": 200,
    18  "chain": "regtest",
    19  "walletversion": 169900,
    20  "balance": 4950.00000000,
    21   ...
    22}
    

    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?

    0     // 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:

     0# generate on test1
     1bitcoind -regtest -wallet=test1 &
     2bitcoin-cli -regtest getnewaddress
     3bitcoin-cli -regtest generatetoaddress 101 $(bitcoin-cli -regtest getnewaddress)
     4
     5# create test2, get receiving address and unload the wallet
     6bitcoin-cli -regtest createwallet test2
     7A=$(bitcoin-cli -regtest -rpcwallet=test2 getnewaddress)
     8bitcoin-cli -regtest -rpcwallet=test2 unloadwallet
     9
    10# send value to the above address and check balance
    11bitcoin-cli -regtest sendtoaddress $A 1
    12bitcoin-cli -regtest loadwallet test2
    13bitcoin-cli -regtest -rpcwallet=test2 getwalletinfo
    14{
    15  "walletname": "test2",
    16  "walletversion": 169900,
    17  "balance": 0.00000000,
    18  "unconfirmed_balance": 0.00000000,
    19  ...
    20
    21# restart now with wallet test2 and check balance
    22bitcoin-cli -regtest stop
    23bitcoind -regtest -wallet=test2
    24bitcoin-cli -regtest getwalletinfo
    25{
    26  "walletname": "test2",
    27  "walletversion": 169900,
    28  "balance": 0.00000000,
    29  "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: 2024-12-22 12:12 UTC

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