Why is my Ethereum block number 0 in geth, even though the sync is nearly complete?
Asked Answered
A

2

6
> w3.eth.syncing
AttributeDict({
  'currentBlock': 5787386,
  'highestBlock': 5787491,
  'knownStates': 138355583,
  'pulledStates': 138341120,
  'startingBlock': 5787335,
})

> w3.eth.blockNumber
0

I had done full sync but blocknumber is always 0.

Azaria answered 14/6, 2018 at 13:19 Comment(0)
U
5

Peter, the lead geth developer, posted a thorough response to this question here: Block number is always zero with fast syncmode. To add slightly more color to carver's answer, while you may have received the most recent block headers (eth.currentBlock), your node probably still has a lot of work remaining to download the entire state tree. To quote Peter:

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

Uhland answered 2/10, 2018 at 21:22 Comment(1)
This information is important and answers the problem for me. I was using the default fast sync mode and my node is simply never fully sync, or only for a brief time, because of the time it takes for the state processing. Need to get my latest block with eth_syncing method.Seductress
A
0

This is the same situation as Why is my ether balance 0 in geth, even though the sync is nearly complete? but with a slightly different "symptom".

To quote the important bit:

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.

Note that in addition to accounts and contracts, you also cannot retrieve any information about blocks until the sync is complete.

When your sync is fully complete, syncing will return false, like:

> w3.eth.syncing
False
Alveolate answered 18/6, 2018 at 21:16 Comment(3)
My sync is fully complete according to your definition but the blockNumber is still 0 even after restarting geth. Wat do?Votive
After waiting for roughly 5 minutes without touching it the w3.eth.syncing doesn't return False anymore and the sync is currently in progress again... Interesting :)Votive
Ah, I suppose it's possible that syncing will return false if your internet connection drops or something like that. So yeah, best to check both syncing and block number.Alveolate

© 2022 - 2024 — McMap. All rights reserved.