Walletwasabi: Balance incorrect

Created on 2 Apr 2020  路  19Comments  路  Source: zkSNACKs/WalletWasabi

General Description

After the wallet synchronized the balance is incorrect.

How To Reproduce?

  1. Go to your favorite wallet file.
  2. Edit the file, delete all HDPubKeys.
  3. Start Wasabi and immediately click load.
  4. The wallet is shown with zero balance (which is correct) because it is not synced.
  5. Wait until synchronization
  6. At the end, you will have a partial balance.
  7. Restart Wasabi, Load wallet, you will have the correct balance.

UPDATE!

I got many cases when the balance incorrect even after restart and it is not fixed on its own.

Screenshots

After sync done
image
After restart:
image

Operating System

win10

Wasabi Version

v1.1.11. rc1

debug priority

Most helpful comment

Yes, I did the same and the balance is correct. However it is good to understand why. The problem is this wallet is old (it is not an excuse, i just want to explain the problem).

Time ago @yahiheb found a defect in the Wasabi keys gap filling that caused incorrect balances because it was simply not counting the gaps size and then Wasabi failed to calculate the balances. That was fixed by me and Wasabi counts and fills the gaps okay after that, however wallets containing transactions before that date can have bigger gaps and they need to use a bigger mingap when restoring/rescanning.

All 19 comments

My investigation so far.
The filters LGTM.
After loading my wallet:

  "BlockchainState": {
    "Network": "TestNet",
    "Height": "1693522"
  },

However in the index file ImmatureIndex.dat the last line is:
1693632:0000000000000153b1d0932bbd23bfccb16bcdefa26ce0865293fa241b992db1:1a525520c9634229ad6112bbca4e64ecfd07ae9d934a39672a164706903bbd1bb98156507bb437641f24414bafef24956c910387a7feac17ac6a471d89632a992f7443c0c1163a:00000000000001108cfe99538edc5543d73630737691e8340222cf2ee5fce49d:1585835647

This seems to be not the problem it is intended behavior. The last 101 blocks are immature thus not written into the file:

https://github.com/molnard/WalletWasabi/blob/1530cbf0714cf0c14b79e269bd8f1dd0b4b408b8/WalletWasabi/Blockchain/Keys/KeyManager.cs#L695

This is related to KeyStates and Gaplimit.
I deleted all the HDPubKeys and start the wallet then load the wallet. After that, I restarted the wallet and load again. After the third load, I got the correct balance.

See my wallet file changes here:
https://github.com/molnard/WasabiTestNetWallet/commits/master

This is not a bug. After deleting the wallet's keys you have to reset the Height to 0 in order to make wasabi to reconstruct the keys.

Did you also set back the height to 0 in the wallet file? If not, then it's ok and this can be closed. If yes, then it's not ok.

Maybe I did not but now I made 2 tests. And I still have problems.

Take my testnet wallet, delete the keys, set the height to zero, load the wallet, restart wasabi again and again and watch the balance change - until it settles about 0.47521752

https://github.com/molnard/WasabiTestNetWallet/commits/master

If you check the commits there, they are reflecting the changes by restarting Wasabi - you might can get a clue.

I see the behaviour

I noticed incorrect behavior too. When I first loaded (with blockchain 0) then the balance was 0.05x, then I restarted it and now it's 0.5x. After multiple restarts it settled for 0.5x.

Also the loading status is ruined. It's now pretty random.

I elevated the gap limit for 63 (same what we use for recovery) and 0.47x, correct balance appeared at first load, so this issue can be closed.

Yes, I did the same and the balance is correct. However it is good to understand why. The problem is this wallet is old (it is not an excuse, i just want to explain the problem).

Time ago @yahiheb found a defect in the Wasabi keys gap filling that caused incorrect balances because it was simply not counting the gaps size and then Wasabi failed to calculate the balances. That was fixed by me and Wasabi counts and fills the gaps okay after that, however wallets containing transactions before that date can have bigger gaps and they need to use a bigger mingap when restoring/rescanning.

@lontivero we don't guarantee max gap limit, we only do min gap limit, hence the name.

Coinjoins can inflate the gap limit when necessary for privacy and it was even more often inflated in the past, now at least we're having a best effort to not inflate it, but inflation is still possible.

The only strange thing is what I experienced: different balance after restart, but the explanation is simple, too.

At first load that's when you generate keys dynamically. At the second load the keys are already generated and we go through all the txs, so more keys are indexed against the same txs.

This is related to that I am using this wallet on 3 different computers?

No.

This is because there is a bigger gap between keys than the specified in the wallet file (21). This can be because as Adam says coinjoins can inflate the gap, what is true. IMO this is because before December 2019 Wasabi was generating keys out of the gap because it was not filling them and was not able to find the keys correctly.

I need a bit more explanation. How is that possible that after the restart it gets better? Can't we just scan further like it does when I restart the wallet?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nopara73 picture nopara73  路  3Comments

yahiheb picture yahiheb  路  3Comments

MaxHillebrand picture MaxHillebrand  路  3Comments

MaxHillebrand picture MaxHillebrand  路  3Comments

kenny47 picture kenny47  路  3Comments