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 #28721

Closed
wants to merge 1 commit into from

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Dec 21, 2023

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, feeding responses via arguments instead.

Classic usage, with bad input (no delete, no error-msg):

[user@work go-ethereum]$ go run ./cmd/geth removedb  
INFO [12-21|20:59:58.447] Maximum peer count                       ETH=50 total=50
INFO [12-21|20:59:58.461] Set global gas cap                       cap=50,000,000
INFO [12-21|20:59:58.461] 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] foo
Remove 'state data'? [y/n] foo
INFO [12-21|21:00:00.203] 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] bar
Remove 'ancient chain'? [y/n] bar

New usage, bad input via arguments (no delete, no error-msg)::

INFO [12-21|21:00:03.546] Database deletion skipped                kind="ancient chain" paths=[/home/user/.ethereum/geth/chaindata/ancient/chain]
[user@work go-ethereum]$ go run ./cmd/geth removedb  foo,bar
INFO [12-21|21:00:09.465] Maximum peer count                       ETH=50 total=50
INFO [12-21|21:00:09.477] Set global gas cap                       cap=50,000,000
INFO [12-21|21:00:09.478] 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] foo
INFO [12-21|21:00:09.535] 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] bar
INFO [12-21|21:00:09.535] Database deletion skipped                kind="ancient chain" paths=[/home/user/.ethereum/geth/chaindata/ancient/chain]

Good input (yes, no)

[user@work go-ethereum]$ go run ./cmd/geth removedb  y,n
INFO [12-21|21:00:18.067] Maximum peer count                       ETH=50 total=50
INFO [12-21|21:00:18.080] Set global gas cap                       cap=50,000,000
INFO [12-21|21:00:18.080] 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-21|21:00:18.132] Folder is not existent                   path=/home/user/.ethereum/geth/chaindata/ancient/state
INFO [12-21|21:00:18.132] Database successfully deleted            kind="state data" paths=[/home/user/.ethereum/geth/chaindata] elapsed="192.382µs"
Location(s) of 'ancient chain': 
        - /home/user/.ethereum/geth/chaindata/ancient/chain

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

Good input yes, yes:

[user@work go-ethereum]$ go run ./cmd/geth removedb  y,y
INFO [12-21|21:00:23.108] Maximum peer count                       ETH=50 total=50
INFO [12-21|21:00:23.122] Set global gas cap                       cap=50,000,000
INFO [12-21|21:00:23.123] 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-21|21:00:23.179] Folder is not existent                   path=/home/user/.ethereum/geth/chaindata/ancient/state
INFO [12-21|21:00:23.179] Database successfully deleted            kind="state data" paths=[/home/user/.ethereum/geth/chaindata] elapsed="937.441µs"
Location(s) of 'ancient chain': 
        - /home/user/.ethereum/geth/chaindata/ancient/chain

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

Only one input (prompts for second input):

[user@work go-ethereum]$ go run ./cmd/geth removedb  n
INFO [12-21|21:03:57.814] Maximum peer count                       ETH=50 total=50
INFO [12-21|21:03:57.863] Set global gas cap                       cap=50,000,000
INFO [12-21|21:03:57.864] 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-21|21:03:57.927] 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] 

Copy link
Member

@rjl493456442 rjl493456442 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(base) ➜  project geth removedb --datadir ./sepolia y,n
INFO [12-22|11:39:13.785] Maximum peer count                       ETH=50 total=50
INFO [12-22|11:39:13.798] Set global gas cap                       cap=50,000,000
INFO [12-22|11:39:13.798] Initializing the KZG library             backend=gokzg
Location(s) of 'state data':
	- /Users/mac/project/sepolia/geth/chaindata
	- /Users/mac/project/sepolia/geth/chaindata/ancient/state

Remove 'state data'? [y/n] y
INFO [12-22|11:39:13.843] Database successfully deleted            kind="state data" paths="[/Users/mac/project/sepolia/geth/chaindata /Users/mac/project/sepolia/geth/chaindata/ancient/state]" elapsed=1.483ms
Location(s) of 'ancient chain':
	- /Users/mac/project/sepolia/geth/chaindata/ancient/chain

Remove 'ancient chain'? [y/n] n
INFO [12-22|11:39:13.843] Database deletion skipped                kind="ancient chain" paths=[/Users/mac/project/sepolia/geth/chaindata/ancient/chain]

Looks good to me

@holiman
Copy link
Contributor Author

holiman commented Dec 22, 2023

After considering it some more: this PR is not good.

  • The use of y,n is too implicit. It assumes an ordering that can never be changed, and if we add / remove / reorder questions in removedb, we break people's setup. It will cause compat problems going forward.
  • The use if y,n as arguments deviates from our existing cli parameters. Inventing one more argument type on top of the existing cli.v2 things is not good UX.

A better solution would be to use explicit cli.v2 flags, like such:

geth removedb --remove.state

where remove.state, remove.chain are booleans:

  • If not specified, user is queried
  • If specified as true, it's deleted
  • If specified as `false, not deleted

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

2 participants