[Ethereum] Why is the ether balance 0 in geth, even though the sync is nearly complete

balancesfast-syncgo-ethereum

My geth --fast sync is nearly complete, and the balance shows correctly on Etherscan.

I was running geth on linux and haven't synced in a while, so I deleted the chaindata and updated the wallet and started re-syncing with geth --fast. Even after what seemed like a full sync my balance showed 0. I can see the account has more than 0 ether on Etherscan.

I copied my keystore file to a Windows machine and tried Ethereum Wallet, same thing is happening. The last transaction was at about block 3800000, I am synced up to 235 blocks left and still have a 0 balance. The sync is also stuck, can't seem to get the last 235 blocks, but my balance should be showing the full amount right now.

Losing my mind right now, it's a lot of money. Even if my keystore was somehow corrupted, the wallet should still show the balance since that is public info. I also verified I'm on the main network.

Best Answer

geth --fast has an interesting effect: geth cannot provide any information about accounts or contracts until the sync is fully complete.

Try querying the balance again after eth.syncing returns false.


Why?

The "fast" sync looks nearly complete because the reported current block is based on the best header you have. But that doesn't give you any information about how much of the account state data you have downloaded.

geth can sync the blocks much faster than it can download the state. An excerpt from @karalabe's explanation why:

This trie data structure is an intricate interlink of hundreds of millions of tiny cryptographic proofs (trie nodes). To truly have a synchronized node, you need to download all the account data, as well as all the tiny cryptographic proofs to verify that noone in the network is trying to cheat you. This itself is already a crazy number of data items. The part where it gets even messier is that this data is constantly morphing: at every block (15s), about 1000 nodes are deleted from this trie and about 2000 new ones are added. This means your node needs to synchronize a dataset that is changing 200 times per second. The worst part is that while you are synchronizing, the network is moving forward, and state that you begun to download might disappear while you're downloading, so your node needs to constantly follow the network while trying to gather all the recent data. But until you actually do gather all the data, your local node is not usable since it cannot cryptographically prove anything about any accounts.