11

I am currently running the latest geth 1.8.1 Iceberg version.

I set up a private ethereum network as per tutorial and everything including mining works fine, but every time I restart geth - the chain resets back to block number 0, all the mining transactions have gone missing and no ETH balance as well, but transactions are recorded in the logs. Please help me to figure out the issue.

  • 1
    this shouldn't happen because if the hash of the block 0 doesn't match, it stops adding blocks. do a web3.eth.getBlock(0) if the Hash of the block is 0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3 , then you are connecting to Ethereum's main net. If not you are connected to your private net. Once you connected to your private net the blockchain can't be rewritten just like you are describing. – Nulik Feb 18 '18 at 2:15
  • 1
    How do you launch geth? Are you sure you are connecting to geth and not to ganache? – Ismael Feb 18 '18 at 18:30
  • 1
    geth --datadir "$ethereum_home/EthMasterChain" --networkid 5657 --rpc --rpcapi db,eth,net,web3,personal --cache=1024 --rpcport 8545 --rpcaddr 127.0.0.1 --rpccorsdomain "*" – Saliya Perera Feb 22 '18 at 8:20
  • 1
    Actually the problem was solved by downgrading geth to version 1.7.3-stable now everything is fine should have been a bug in the 1.8 Iceberg version – Saliya Perera Feb 22 '18 at 8:21
8

No need to downgrade your geth to an older version.
Like Murat Ögat said:

Every time you terminate geth, up to 128 blocks can be lost, with default settings.

and this is also mentioned in various places in https://github.com/ethereum/go-ethereum/releases:

Tracing and pruning: By default, state for the last 128 blocks kept in memory.

The solution is: add --gcmode archive when you launch geth

2

I think it's by design - when you restart a private network with a genesis block, it all resets.

Try using ganache-cli for running a private ethereum network - it has a parameter --db that you can set to a folder to store the state database, so that it will preserve the state between restarts.

https://github.com/trufflesuite/ganache-cli - the readme is very helpful for installing/setting up and running the network

  • 1
    A private network with geth will continue working where you left after a restart, if you use the same parameters that were uses when you launched it. – Ismael Feb 18 '18 at 18:29
  • 1
    I haven't ever used geth, just ganache – Andrey Feb 18 '18 at 18:38
  • 1
    In the answer geth is mentioned, but it is not clear if they are using geth or ganache. – Ismael Feb 19 '18 at 0:35
2

This may happen if you are mining less than 128 blocks. Every time you terminate geth, up to 128 blocks can be lost, with default settings. (I do not know how to change this)

So if you always mine less than 128, you may always have to start from 0. Let it mine more than that, and check to which past head the chain blockchain rewinds. It was 263->136 in my case.

I'm also on version 1.8.1-stable

  • 1
    When you say "mine" I think you mean "sync" :-) – Richard Horrocks Feb 26 '18 at 11:22
  • 1
    Might be. But I'm on my private chain where eth.blockNumber returns 263 before and 136 after restart. I am running one node only for now. I still don't know how to fix this without downgrading. Is this really a bug in 1.8.1? – Murat Ögat Feb 26 '18 at 11:27
  • 1
    Ah, actually, you might be right. If you're only running a single node, and that's the only mining node, then my comment doesn't make sense. If you were running a multi-node system, and the non-mining nodes were also being reset, then my comment would make sense. – Richard Horrocks Feb 26 '18 at 11:42
2

Make sure you are closing it correctly, I had the same issue. Use CTRL+D to shut down Geth

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.