Skip to content

Commit

Permalink
fix: Opt pruneancient issues; (#2800)
Browse files Browse the repository at this point in the history
  • Loading branch information
galaio authored Dec 16, 2024
1 parent 0ad0e9f commit e052b5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
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

0 comments on commit e052b5d

Please sign in to comment.