Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geth showing 0 eth balance after sync #16251

Closed
goldbutcold opened this issue Mar 5, 2018 · 9 comments
Closed

Geth showing 0 eth balance after sync #16251

goldbutcold opened this issue Mar 5, 2018 · 9 comments

Comments

@goldbutcold
Copy link

Hi,
I have problems with fetching of the account balance after sync. Hopefuly this is an appropriate thing to post here.

System information

Geth version: geth 1.8.1
OS & Version: Ubuntu 16.04

eth.syncing
{
currentBlock: 5199256,
highestBlock: 5199321,
knownStates: 4642,
pulledStates: 273,
startingBlock: 5198975
}

Expected behaviour

After finished fast sync, I would expect geth to show the balance of my account:
https://www.etherchain.org/account/0xf78a43329b7b84b690376d043d53425441ab6267

Actual behaviour

But instead I get 0.

web3.fromWei(eth.getBalance("0xf78a43329b7b84b690376d043d53425441ab6267"), "ether")
0
eth.accounts
["0xf3c54fa6e12a2e71946ef20e891e066e9f755979", "0xf78a43329b7b84b690376d043d53425441ab6267"]

I apologize in advance if this post does not belong here.

@karalabe
Copy link
Member

karalabe commented Mar 8, 2018

Syncing Ethereum is a pain point for many people, so I'll try to detail what's happening behind the scenes so there might be a bit less confusion.

The current default mode of sync for Geth is called fast sync. Instead of starting from the genesis block and reprocessing all the transactions that ever occurred (which could take weeks), fast sync downloads the blocks, and only verifies the associated proof-of-works. Downloading all the blocks is a straightforward and fast procedure and will relatively quickly reassemble the entire chain.

Many people falsely assume that because they have the blocks, they are in sync. Unfortunately this is not the case, since no transaction was executed, so we do not have any account state available (ie. balances, nonces, smart contract code and data). These need to be downloaded separately and cross checked with the latest blocks. This phase is called the state trie download and it actually runs concurrently with the block downloads; alas it take a lot longer nowadays than downloading the blocks.

So, what's the state trie? In the Ethereum mainnet, there are a ton of accounts already, which track the balance, nonce, etc of each user/contract. The accounts themselves are however insufficient to run a node, they need to be cryptographically linked to each block so that nodes can actually verify that the account's are not tampered with. This cryptographic linking is done by creating a tree data structure above the accounts, each level aggregating the layer below it into an ever smaller layer, until you reach the single root. This gigantic data structure containing all the accounts and the intermediate cryptographic proofs is called the state trie.

Ok, so why does this pose a problem? 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.

If you see that you are 64 blocks behind mainnet, you aren't yet synchronized, not even close. You are just done with the block download phase and still running the state downloads. You can see this yourself via the seemingly endless Imported state entries [...] stream of logs. You'll need to wait that out too before your node comes truly online.


Q: The node just hangs on importing state enties?!

A: The node doesn't hang, it just doesn't know how large the state trie is in advance so it keeps on going and going and going until it discovers and downloads the entire thing.

The reason is that a block in Ethereum only contains the state root, a single hash of the root node. When the node begins synchronizing, it knows about exactly 1 node and tries to download it. That node, can refer up to 16 new nodes, so in the next step, we'll know about 16 new nodes and try to download those. As we go along the download, most of the nodes will reference new ones that we didn't know about until then. This is why you might be tempted to think it's stuck on the same numbers. It is not, rather it's discovering and downloading the trie as it goes along.

Q: I'm stuck at 64 blocks behind mainnet?!

A: As explained above, you are not stuck, just finished with the block download phase, waiting for the state download phase to complete too. This latter phase nowadays take a lot longer than just getting the blocks.

Q: Why does downloading the state take so long, I have good bandwidth?

A: State sync is mostly limited by disk IO, not bandwidth.

The state trie in Ethereum contains hundreds of millions of nodes, most of which take the form of a single hash referencing up to 16 other hashes. This is a horrible way to store data on a disk, because there's almost no structure in it, just random numbers referencing even more random numbers. This makes any underlying database weep, as it cannot optimize storing and looking up the data in any meaningful way.

Not only is storing the data very suboptimal, but due to the 200 modification / second and pruning of past data, we cannot even download it is a properly pre-processed way to make it import faster without the underlying database shuffling it around too much. The end result is that even a fast sync nowadays incurs a huge disk IO cost, which is too much for a mechanical hard drive.

Q: Wait, so I can't run a full node on an HDD?

A: Unfortunately not. Doing a fast sync on an HDD will take more time than you're willing to wait with the current data schema. Even if you do wait it out, an HDD will not be able to keep up with the read/write requirements of transaction processing on mainnet.

You however should be able to run a light client on an HDD with minimal impact on system resources. If you wish to run a full node however, an SSD is your only option.

@Xealott
Copy link

Xealott commented Mar 21, 2018

@karalabe
Thank you very much for this explanation. I would love to see this disclaimer ("Don't try to run a full node on an HDD") put somewhere where new adopters can find it when they're downloading the install files. I think a lot of people (like me) will attempt to use an old machine with HDD to host a full node, and we could save everyone a lot of frustration, confusion, and mechanical wear-and-tear. Any suggestion as to how to go about this?

Thanks,
Xeal

@MateMstar
Copy link

Thank you for the explanation. It's hard to find those information bundled and explained so well.
But how do I know that this is done?
Or at least where can I see how many of the imported new state entries needs to be done?
I'm at processed=78300000 right now and it seems to getting slower, like it is done and only works with the new blocks and state entries. How do I know?

@arokapil
Copy link

What is the upper limit of state entries? is that something which varies from system to system?

INFO [03-25|19:59:31] Imported new state entries count=2092 elapsed=16.747ms processed=75720889 pending=15335 retry=2 duplicate=1431 unexpected=4066

@arokapil
Copy link

@MateMstar did it finished???
if yes, what was the upper limit..
i saw some thread of date 23rd feb saying ........
Yes, I'm in sync now.
Finally...
Finally...
Several hours to go from 0 to ~85 million knownStates

@jmooo
Copy link

jmooo commented Jun 5, 2018

@karalabe thanks for the great description above, that is very helpful! I'm also curious about trying to use the copydb function to move my already synced chain to another machine. If I use that method on the new machine I get the endless "imported state entries," but I've already sat through all that!

Essentially I want to copydb to shrink the chain on a non-archival node I've had online for several months (chaindata now ~400gb) down as small as possible (copydb gets it down to ~70gb), but I want a new node to then sync up the last couple thousand blocks to current and get online very quickly. Do I just have to live with my 400gb chaindata folder and copy the whole thing to be up-and-running without "imported state entries" delays?

Basically if I already have all the chain data, what's the fastest way get 2nd full node online with as small a chaindata folder as possible?

@MateMstar
Copy link

@arokapil

@MateMstar did it finished???
if yes, what was the upper limit..
i saw some thread of date 23rd feb saying ........
Yes, I'm in sync now.
Finally...
Finally...
Several hours to go from 0 to ~85 million knownStates

sorry I never finished it. It wasnt necessary for my purpose so I did my transactions in browsers and let the wallet be the wallet

@ghost
Copy link

ghost commented Oct 8, 2019

Thank you so much for your support. I read informative things in the aforementioned. I downloaded geth yesterday and stated running the process. I run it through the whole night and I am still running it. I am still too far in the tries sync (according to what I read). To get to the point, I noticed some blocks with "warn" and "fail" expressions.

Could you tell pleas what those mean. Below is an example of my blocks

  • ERROR[10-08|12:32:14.174] Failed to unregister sync peer peer=f0546b0a33dc0bf1 err="peer is not registered"
  • INFO [10-08|12:32:15.182] Imported new block receipts count=5 elapsed=876.281ms number=4439886 hash=158693…9dd40b age=1y11mo2w size=137.65KiB
  • INFO [10-08|12:32:17.689] Imported new state entries count=2355 elapsed=28.998ms
  • WARN [10-08|12:32:26.743] Dropping unsynced node during fast sync id=cb4cc76112db1e83

Thanks in advance

@huahuayu
Copy link
Contributor

huahuayu commented Jan 29, 2021

You however should be able to run a light client on an HDD with minimal impact on system resources. If you wish to run a full node however, an SSD is your only option.

@karalabe can I use aws s3 storage for ethereum block data storage? I mean aws s3 standard storage. I don't know if it's ssd or not.

when using fast sync, in the last 100 block phase, the io looks like not too big, why hdd is not a choice?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants