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

cmd/geth: make it possible to autopilot removedb #28725

Merged
merged 2 commits into from Jan 9, 2024

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Dec 22, 2023

Supersedes #28721

When managing geth over docker, sometimes it's desirable to do a partial wipe: delete state but retain freezer data. This can be a bit tricky: the ansible scripts to delete files individually are slow, a faster way to do it is to

  • move the freezer-data somewhere else,
  • delete the chaindata
  • create the chaindata
  • move back the freezer-data

This "works" but it's clumsy, and now that we have both block-data and state-data in freezer, it's a bit incomplete, the correct thing to do would be to save only the block-data, not the state-data.

This PR implements an alternative way to achieve the same thing, by making it possible to run geth removedb non-interactive, using boolean options instead.


Explicitly removing chain (it asks about state, no question about chain):

[user@work go-ethereum]$ go run ./cmd/geth removedb --remove.chain
INFO [12-22|08:12:19.779] Maximum peer count                       ETH=50 total=50
INFO [12-22|08:12:19.837] Set global gas cap                       cap=50,000,000
INFO [12-22|08:12:19.838] Initializing the KZG library             backend=gokzg
Location(s) of 'state data': 
	- /home/user/.ethereum/geth/chaindata
	- /home/user/.ethereum/geth/chaindata/ancient/state

Remove 'state data'? [y/n] n 
Remove 'state data'? [y/n] n
INFO [12-22|08:12:31.010] Database deletion skipped                kind="state data" paths="[/home/user/.ethereum/geth/chaindata /home/user/.ethereum/geth/chaindata/ancient/state]"
Location(s) of 'ancient chain': 
	- /home/user/.ethereum/geth/chaindata/ancient/chain

Remove 'ancient chain'? [y/n] y
INFO [12-22|08:12:31.012] Folder is not existent                   path=/home/user/.ethereum/geth/chaindata/ancient/chain
INFO [12-22|08:12:31.012] Database successfully deleted            kind="ancient chain" paths=[] elapsed=1.797ms

Both specified, so no question asked (but it's still printed):

[user@work go-ethereum]$ go run ./cmd/geth removedb --remove.chain=false --remove.state=false
INFO [12-22|08:12:45.883] Maximum peer count                       ETH=50 total=50
INFO [12-22|08:12:45.899] Set global gas cap                       cap=50,000,000
INFO [12-22|08:12:45.900] Initializing the KZG library             backend=gokzg
Location(s) of 'state data': 
	- /home/user/.ethereum/geth/chaindata
	- /home/user/.ethereum/geth/chaindata/ancient/state

Remove 'state data'? [y/n] n
INFO [12-22|08:12:45.950] Database deletion skipped                kind="state data" paths="[/home/user/.ethereum/geth/chaindata /home/user/.ethereum/geth/chaindata/ancient/state]"
Location(s) of 'ancient chain': 
	- /home/user/.ethereum/geth/chaindata/ancient/chain

Remove 'ancient chain'? [y/n] n
INFO [12-22|08:12:45.951] Database deletion skipped                kind="ancient chain" paths=[/home/user/.ethereum/geth/chaindata/ancient/chain]

Both specified for deletion:

[user@work go-ethereum]$ go run ./cmd/geth removedb --remove.chain=true --remove.state=true
INFO [12-22|08:12:57.571] Maximum peer count                       ETH=50 total=50
INFO [12-22|08:12:57.584] Set global gas cap                       cap=50,000,000
INFO [12-22|08:12:57.584] Initializing the KZG library             backend=gokzg
Location(s) of 'state data': 
	- /home/user/.ethereum/geth/chaindata
	- /home/user/.ethereum/geth/chaindata/ancient/state

Remove 'state data'? [y/n] y
INFO [12-22|08:12:57.633] Folder is not existent                   path=/home/user/.ethereum/geth/chaindata/ancient/state
INFO [12-22|08:12:57.633] Database successfully deleted            kind="state data" paths=[/home/user/.ethereum/geth/chaindata] elapsed="218.429µs"
Location(s) of 'ancient chain': 
	- /home/user/.ethereum/geth/chaindata/ancient/chain

Remove 'ancient chain'? [y/n] y
INFO [12-22|08:12:57.634] Folder is not existent                   path=/home/user/.ethereum/geth/chaindata/ancient/chain
INFO [12-22|08:12:57.634] Database successfully deleted            kind="ancient chain" paths=[]                                    elapsed="31.8µs"

Nothing specified:

[user@work go-ethereum]$ go run ./cmd/geth removedb 
INFO [12-22|08:13:13.461] Maximum peer count                       ETH=50 total=50
INFO [12-22|08:13:13.471] Set global gas cap                       cap=50,000,000
INFO [12-22|08:13:13.471] Initializing the KZG library             backend=gokzg
Location(s) of 'state data': 
	- /home/user/.ethereum/geth/chaindata
	- /home/user/.ethereum/geth/chaindata/ancient/state

Remove 'state data'? [y/n] ^C^C
^C
Fatal: prompt aborted

cmd/geth/dbcmd.go Outdated Show resolved Hide resolved
@holiman holiman added this to the 1.13.8 milestone Jan 8, 2024
@holiman holiman merged commit 1010a79 into ethereum:master Jan 9, 2024
1 of 3 checks passed
@MariusVanDerWijden MariusVanDerWijden modified the milestones: 1.13.8, 1.13.9 Jan 10, 2024
Dergarcon pushed a commit to specialmechanisms/mev-geth-0x2mev that referenced this pull request Jan 31, 2024
When managing geth, it is sometimes desirable to do a partial wipe; deleting state but retaining freezer data. A partial wipe can be somewhat tricky to accomplish. 

This change implements the ability to perform partial wipe by making it possible to run geth removedb non-interactive, using command line options instead.
maoueh pushed a commit to streamingfast/go-ethereum that referenced this pull request Apr 29, 2024
When managing geth, it is sometimes desirable to do a partial wipe; deleting state but retaining freezer data. A partial wipe can be somewhat tricky to accomplish. 

This change implements the ability to perform partial wipe by making it possible to run geth removedb non-interactive, using command line options instead.
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

Successfully merging this pull request may close these issues.

None yet

3 participants