Skip to content

Instantly share code, notes, and snippets.

@yorickdowne
Last active August 25, 2022 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorickdowne/7cf74dd2ea12f89504c0bec191de6dc7 to your computer and use it in GitHub Desktop.
Save yorickdowne/7cf74dd2ea12f89504c0bec191de6dc7 to your computer and use it in GitHub Desktop.
Reset Geth head with eth-docker

Overview

Geth 1.10.23 fixes a bug in 1.10.22, which would have resulted in missing state in its database. The Go-Ethereum team recommends to roll the chain back and let Geth catch up again, if and only if you had updated to 1.10.22. If you did not, just update to 1.10.23 now and call it done.

This is how to roll back to a previous block when using eth-docker.

Update Geth to 1.10.23

./ethd update and ./ethd up should do it.

Enable debug API

Make sure the API is not exposed to Internet, as having debug open can easily be abused.

nano geth.yml and add debug to the --http.api, so it looks like this

      - --http.api
      - web3,eth,net,debug

Restart Geth: ./ethd up

Run logs

I recommend opening a second terminal window and running ./ethd logs -f --tail 50 execution so you can see how the reset behaves.

Enter the Geth container and reset head

docker ps and find the Geth container, then get into bash in it via docker exec -it CONTAINER bash, e.g. docker exec -it eth-docker_execution_1 bash

geth attach http://localhost:8545, you should now be in the Geth console

debug.setHead("0xEAC1A8"), or to whichever block number in hex you wish to reset. This example attempts to reset to block 15389000. This will take a while, possibly a few minutes. You expect to see Rewinding blockchain target=15,385,000, with your target block, in logs.

It should return with null and have succeeded. Rely on the logs you have running in another window to see whether it's now catching up from that block.

If you see Error: Post "http://localhost:8545": EOF, it may not have been successful. In that case you expect to see that Geth is not importing chain segments and "catching up", in logs. Even so a restart of Geth may get it to successfully catch up again from this point.

exit to exit the Geth console, then exit again to leave the container

If reset failed

If reset did not work, you'll need to, alas, resync from scratch. Use the logs to judge whether Geth is successfully catching up or showing signs of DB corruption.

./ethd stop then docker volume ls, find the Geth volume and docker volume rm it, e.g. docker volume rm eth-docker_geth-eth1-data.

./ethd up and Geth will resync from scratch.

Undo changes and check logs

git restore geth.yml to undo the debug API, another ./ethd up so Geth no longer runs with it, then ./ethd logs -f --tail 50 execution to see that Geth is working normally and catching up again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment