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

fix: Opt pruneancient issues; #2800

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2010,11 +2010,11 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.DiffBlock = ctx.Uint64(DiffBlockFlag.Name)
}
if ctx.IsSet(PruneAncientDataFlag.Name) {
if cfg.SyncMode == ethconfig.FullSync {
cfg.PruneAncientData = ctx.Bool(PruneAncientDataFlag.Name)
} else {
log.Crit("pruneancient parameter can only be used with syncmode=full")
if cfg.SyncMode != ethconfig.FullSync {
log.Warn("pruneancient parameter can only be used with syncmode=full, force to full sync")
cfg.SyncMode = ethconfig.FullSync
}
cfg.PruneAncientData = ctx.Bool(PruneAncientDataFlag.Name)
}
if gcmode := ctx.String(GCModeFlag.Name); gcmode != "full" && gcmode != "archive" {
Fatalf("--%s must be either 'full' or 'archive'", GCModeFlag.Name)
Expand Down Expand Up @@ -2425,10 +2425,15 @@ func parseDBFeatures(cfg *ethconfig.Config, stack *node.Node) string {
var features []string
if cfg.StateScheme == rawdb.PathScheme {
features = append(features, "PBSS")
} else if cfg.StateScheme == rawdb.HashScheme {
features = append(features, "HBSS")
}
if stack.CheckIfMultiDataBase() {
features = append(features, "MultiDB")
}
if cfg.PruneAncientData {
features = append(features, "PruneAncient")
}
return strings.Join(features, "|")
}

Expand Down
9 changes: 6 additions & 3 deletions core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,13 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, ancient string, namespace st
// If the genesis hash is empty, we have a new key-value store, so nothing to
// validate in this method. If, however, the genesis hash is not nil, compare
// it to the freezer content.
// Only to check the followings when offset equal to 0, otherwise the block number
// Only to check the followings when offset/ancientTail equal to 0, otherwise the block number
// in ancientdb did not start with 0, no genesis block in ancientdb as well.

if kvgenesis, _ := db.Get(headerHashKey(0)); offset == 0 && len(kvgenesis) > 0 {
ancientTail, err := frdb.Tail()
if err != nil {
return nil, fmt.Errorf("failed to retrieve Tail from ancient %v", err)
}
if kvgenesis, _ := db.Get(headerHashKey(0)); (offset == 0 && ancientTail == 0) && len(kvgenesis) > 0 {
if frozen, _ := frdb.Ancients(); frozen > 0 {
// If the freezer already contains something, ensure that the genesis blocks
// match, otherwise we might mix up freezers across chains and destroy both
Expand Down
Loading