ethereum / go-ethereum

Go implementation of the Ethereum protocol
https://geth.ethereum.org
GNU Lesser General Public License v3.0
47.24k stars 20k forks source link

Synced geth node gives '0' balance for every address #16697

Closed friko16 closed 6 years ago

friko16 commented 6 years ago

Hi there, Maybe it's not the right place, but I don't know if it's a bug or simply some silly mistake from my side. The thing is I have fully sunced geth node, and still in geth console I see '0' balance for every possible address I tried ( on etherscan.io there is ether ).

First I ran this command to sync geth:

geth --rpcport "8080" --port "30303" --rpcapi "db,eth,net,web3" --ws --wsorigins "*"

then, after it was synced:

> eth.syncing { currentBlock: 5571710, highestBlock: 5571775, knownStates: 39712500, pulledStates: 39690562, startingBlock: 5571697 }

I ran > eth.getBalance("0x8271B2E8CBe29396e9563229030c89679B9470db") 0

which returned to me 0 balance, whereas it does have some ether: https://etherscan.io/address/0x8271b2e8cbe29396e9563229030c89679b9470db

Why is that ? It does seem that my geth doesn't have the same state as the mainnet. The same discrapencies happened when I tried to read other accounts.

my spec: Geth/v1.8.2-stable-b8b9f7f4/linux-amd64/go1.9.4 Ubuntu

console logs when starting geth:

`> ~/.ethereum  geth --rpcport "8080" --port "30303" --rpcapi "db,eth,net,web3" --ws --wsorigins "*"

INFO [05-07|13:52:02] Maximum peer count ETH=25 LES=0 total=25

INFO [05-07|13:52:02] Starting peer-to-peer node instance=Geth/v1.8.2-stable-b8b9f7f4/linux-amd64/go1.9.4

INFO [05-07|13:52:02] Allocated cache and file handles database=/home/friko/.ethereum/geth/chaindata cache=768 handles=512

INFO [05-07|13:52:02] Initialised chain configuration config="{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP 155: 2675000 EIP158: 2675000 Byzantium: 4370000 Constantinople: Engine: ethash}"

INFO [05-07|13:52:02] Disk storage enabled for ethash caches dir=/home/friko/.ethereum/geth/ethash count=3

INFO [05-07|13:52:02] Disk storage enabled for ethash DAGs dir=/home/friko/.ethash count=2

INFO [05-07|13:52:02] Initialising Ethereum protocol versions="[63 62]" network=1

INFO [05-07|13:52:02] Loaded most recent local header number=5571763 hash=a89930…7f038e td=4054135703900854882765

INFO [05-07|13:52:02] Loaded most recent local full block number=0 hash=d4e567…cb8fa3 td=17179869184

INFO [05-07|13:52:02] Loaded most recent local fast block number=5571697 hash=922f14…20a7da td=4053921059280692968410

INFO [05-07|13:52:02] Loaded local transaction journal transactions=0 dropped=0

INFO [05-07|13:52:02] Regenerated local transaction journal transactions=0 accounts=0

INFO [05-07|13:52:02] Starting P2P networking

INFO [05-07|13:52:04] UDP listener up self=enode://2c68b3f9d8ca313b07f7986563666dde18d5ae99f8f668dcabe9c3144e06bd4c94ae57dc734 6e8ffca01936f37727fac009a91ff558e509edc6b7785db3379f9@192.168.1.169:30303

INFO [05-07|13:52:04] RLPx listener up self=enode://2c68b3f9d8ca313b07f7986563666dde18d5ae99f8f668dcabe9c3144e06bd4c94ae57dc734 6e8ffca01936f37727fac009a91ff558e509edc6b7785db3379f9@192.168.1.169:30303

INFO [05-07|13:52:04] IPC endpoint opened url=/home/friko/.ethereum/geth.ipc

INFO [05-07|13:52:04] WebSocket endpoint opened url=ws://127.0.0.1:8546

INFO [05-07|13:52:11] Etherbase automatically configured address=0xdF230AC904512b5644fc64165c2515124D348C53

INFO [05-07|13:52:34] Block synchronisation started

INFO [05-07|13:52:36] Imported new block headers count=0 elapsed=6.097ms number=5571775 hash=770a45…f2782b ignor`

maybe it's also worth mentioning,I previously used this geth binary to run a private network with custom config file( using

geth init ./CustomGenesis.json )

and I played a bit with it, like I setup my own gasprice etc. but when I try to connect to mainnet I am not using the config file with geth ( I hope so, as I don't run the 'init ./CustomGenesis.json' parameter ), so I hope it does not affect my geth running on mainnet.

carver commented 6 years ago

after it was synced

Note that your node is not fully synced yet. eth.syncing will return false when it is fully synced.

Check out this brief StackExchange explanation (which includes a link to the comment with the full background)

karalabe commented 6 years ago

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.