mycroft/chainstate

Balance accuracy problem

hioma opened this issue · 3 comments

hioma commented

First of all, thank you for your project.
I am using a newer version (bitcoin-core 0.18.0 for windows, haha), but it's chainstate seems compatible. I got own balances file through your tool, but some addresses have a little different balance, for example, after

cut -d';' -f3,4 cs.out | \
    sort | \
    awk -F ';' '{ if ($1 != cur) { if (cur != "") { printf "%s;%.0f\n", cur, sum }; sum = 0; cur = $1 }; sum += $2 } END { printf "%s;%.0f\n", cur, sum }' | \
    sort -t ';' -k 2 -g -r > ${BALANCES_FILE}

and head balances-* | grep "3Nxwenay9Z8Lc9JBiywExpnEFiLp6Afp8v\|1FeexV6bAHb8ybZjqQMjJrcCrHGW9sb6uF\|3D2oetdNuZUqQHPJmcMDDHYoqkyNVsFk9r" I received this:

3Nxwenay9Z8Lc9JBiywExpnEFiLp6Afp8v;10784828923592
1FeexV6bAHb8ybZjqQMjJrcCrHGW9sb6uF;7995720060915
3D2oetdNuZUqQHPJmcMDDHYoqkyNVsFk9r;7689307218486

But it's balances are 107848289_03408_, 79957200_36267_ and 7689307_172632_.
My BitcoinCore was correctly synced, state directory size: 3603436444, blocks: 266965543715, uname -a: Linux 388e60c19d8b 4.9.13-moby #1 SMP Tue Mar 21 21:21:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Do you have any ideas? Can you reproduce the issue?
Now I am syncing 0.15.0 version to try it's chainstate, but it takes time a little.

Hello,

how do you compare balances ? What is your reference ?

If you are using any online explorer, be aware they are not using the same datasource: Most of them are using the sum of received & spent coin, while chainstate is using the spendable transactions only (which makes more sense IMO).

Some transactions are unspendable in the blockchain, due to bugs, tests, etc. and Bitcoin Core considers them unspendable; Therefore they are not in the chainstate DB (and not reported in the computed balance) while shown in the explorers.

Also, as it takes some time for balances to compute, a new block might have been generated & balances might have already change, especially for those accounts that are owned by exchanges and have a lot of activity in it: Their balances change at every block received.

I don't close the issue, and I may take a look at it if a find some free time. Thanks

hioma commented

Thanks for the disclosure, I didn't know such nuances.
You are right, I used online explorers as reference. I think, provided addresses doesn't have a lot of activity (1-2 hundreds of transactions for 2/3 addresses, one per few days), and two of them have last transactions in July:
https://www.blockchain.com/ru/btc/address/3Nxwenay9Z8Lc9JBiywExpnEFiLp6Afp8v
https://www.blockchain.com/ru/btc/address/1FeexV6bAHb8ybZjqQMjJrcCrHGW9sb6uF
https://www.blockchain.com/ru/btc/address/3D2oetdNuZUqQHPJmcMDDHYoqkyNVsFk9r

hello @hioma - I detected & fixed a problem in number conversions that should fix some accuracy problems especially in big numbers like the one you are describing in the issue. The fix was commited and pushed: 77b1158.

I'm now closing the issue, feel free someday to have a look if you still want to. Thanks!