I tried loading up all my wallet files at once to see how well it worked, then ran ‘getbalance’ on each of them. The balances of some were reported as being zero when they should have been non-zero.
I believe the root cause is that I loaded up some old backups of the funded wallets as well as the up to date versions.
Is that behavior meant to be supported? Or should each wallet have been created separately?
My guess is that the wallet database gets some kind of unique ID assigned to it when it is created, and loading up an old backup alongside the current version means I have two wallets with the same “unique” ID loaded at once, causing problems.
As an example, I have two wallets: wallet.dat.finex
and wallet.dat.finex2
. One is an old copy of the other. I loaded up a single third wallet, let it sync 3 blocks, shut down, then loaded the two finex
wallets together. I had added debug to see why rescanning was being skipped in some cases.
wallet.cpp
has this test to decide whether the rescan is necessary:
if (chainActive.Tip() && chainActive.Tip() != pindexRescan)
In the debug output I saw:
2017-09-30 16:32:36 [wallet.dat.finex] rescan? checking tip()
2017-09-30 16:32:36 [wallet.dat.finex] rescan? maybe: chainActive.Tip() is true
2017-09-30 16:32:36 [wallet.dat.finex] rescan? yes: 0x7f60bf3f3db0 (487616) != 0x7f60d3d4aad0 (487613)
2017-09-30 16:32:36 [wallet.dat.finex2] rescan? checking tip()
2017-09-30 16:32:36 [wallet.dat.finex2] rescan? maybe: chainActive.Tip() is true
2017-09-30 16:32:36 [wallet.dat.finex2] rescan? no: 0x7f60bf3f3db0 (487616) == 0x7f60bf3f3db0 (487616)
so the finex
wallet gets 3 blocks rescanned, but the finex2
wallet doesn’t, even though it needs a rescan. I guess they share a CWalletDB walletdb(*walletInstance->dbw);
.
I stopped looking into it here, because maybe the solution is going to be “stop loading copies of a wallet at the same time”.