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, core/rawdb: add dbDeleteTrieState #2302

Merged
merged 2 commits into from
Mar 20, 2024

Conversation

weiihann
Copy link
Contributor

@weiihann weiihann commented Mar 18, 2024

Description

This PR adds a feature to convert full node to fast node by introducing a new CLI tool called delete-trie-state. The tool will delete all PBSS key-value pairs and ancient state stores from the database.

Rationale

This is particularly useful when users want to switch from full node to fast node by deleting the trie state from the database, reducing disk space occupied.

Example

Usage: ./geth --datadir db delete-trie-state

...
INFO [03-18|16:06:39.783] Opened ancient database                  database=/datadir_test/geth/chaindata/ancient/chain readonly=false frozen=909,979
INFO [03-18|16:06:43.759] Deleted trie state                       count=1,683,851 elapsed=3.971s
INFO [03-18|16:06:43.759] Removing ancient state database          path=/datadir_test/geth/chaindata/ancient/state
INFO [03-18|16:06:43.862] State database successfully deleted      path=/datadir_test/geth/chaindata/ancient/state elapsed=103.202ms

Changes

Also added an additional NoTries logic check in SetupGenesisBlockWithOverride to prevent committing the genesis block again. For custom networks, this will result in an error because !triedb.Initialized(header.Root) returns true due to an empty trie database, so we need to skip committing if it's a fast node.

@weiihann weiihann marked this pull request as draft March 18, 2024 08:13
@weiihann weiihann marked this pull request as ready for review March 18, 2024 08:25
cmd/geth/dbcmd.go Outdated Show resolved Hide resolved
cmd/geth/dbcmd.go Outdated Show resolved Hide resolved
@weiihann weiihann requested a review from fynnss March 19, 2024 10:36
Copy link
Contributor

@flywukong flywukong left a comment

Choose a reason for hiding this comment

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

LGTM

@buddh0 buddh0 merged commit 6978f00 into bnb-chain:develop Mar 20, 2024
6 of 7 checks passed
@Pjrich1313 Pjrich1313 mentioned this pull request Mar 27, 2024
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.

5 participants