Skip to content

Commit

Permalink
core: remove some unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
jingjunLi committed Mar 8, 2024
1 parent 36dfef4 commit 8668912
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 52 deletions.
6 changes: 3 additions & 3 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,20 @@ func initGenesis(ctx *cli.Context) error {
overrides.OverrideVerkle = &v
}
for _, name := range []string{"chaindata", "lightchaindata"} {
chaindb, err := stack.OpenDatabaseWithFreezer(name, 0, 0, ctx.String(utils.AncientFlag.Name), "", false, false, false, false, false, false)
chaindb, err := stack.OpenDatabaseWithFreezer(name, 0, 0, ctx.String(utils.AncientFlag.Name), "", false, false, false, false)
if err != nil {
utils.Fatalf("Failed to open database: %v", err)
}
defer chaindb.Close()

// if the trie data dir has been set, new trie db with a new state database
if ctx.IsSet(utils.SeparateDBFlag.Name) {
statediskdb, dbErr := stack.OpenDatabaseWithFreezer(name+"/state", 0, 0, "", "", false, false, false, false, false, false)
statediskdb, dbErr := stack.OpenDatabaseWithFreezer(name+"/state", 0, 0, "", "", false, false, false, false)
if dbErr != nil {
utils.Fatalf("Failed to open separate trie database: %v", dbErr)
}
chaindb.SetStateStore(statediskdb)
blockdb, err := stack.OpenDatabaseWithFreezer(name+"/block", 0, 0, "", "", false, false, false, false, false, true)
blockdb, err := stack.OpenDatabaseWithFreezer(name+"/block", 0, 0, "", "", false, false, false, false)
if err != nil {
utils.Fatalf("Failed to open separate block database: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,7 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node, readonly, disableFree
case ctx.String(SyncModeFlag.Name) == "light":
chainDb, err = stack.OpenDatabase("lightchaindata", cache, handles, "", readonly)
default:
chainDb, err = stack.OpenDatabaseWithFreezer("chaindata", cache, handles, ctx.String(AncientFlag.Name), "", readonly, disableFreeze, false, false, false, false)
chainDb, err = stack.OpenDatabaseWithFreezer("chaindata", cache, handles, ctx.String(AncientFlag.Name), "", readonly, disableFreeze, false, false)
// set the separate state database
if stack.IsSeparatedDB() && err == nil {
stateDiskDb := MakeStateDataBase(ctx, stack, readonly, false)
Expand All @@ -2339,7 +2339,7 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node, readonly, disableFree
func MakeStateDataBase(ctx *cli.Context, stack *node.Node, readonly, disableFreeze bool) ethdb.Database {
cache := ctx.Int(CacheFlag.Name) * ctx.Int(CacheDatabaseFlag.Name) / 100
handles := MakeDatabaseHandles(ctx.Int(FDLimitFlag.Name)) / 2
statediskdb, err := stack.OpenDatabaseWithFreezer("chaindata/state", cache, handles, "", "", readonly, disableFreeze, false, false, false, false)
statediskdb, err := stack.OpenDatabaseWithFreezer("chaindata/state", cache, handles, "", "", readonly, disableFreeze, false, false)
if err != nil {
Fatalf("Failed to open separate trie database: %v", err)
}
Expand All @@ -2350,7 +2350,7 @@ func MakeStateDataBase(ctx *cli.Context, stack *node.Node, readonly, disableFree
func MakeBlockDatabase(ctx *cli.Context, stack *node.Node, readonly, disableFreeze bool) ethdb.Database {
cache := ctx.Int(CacheFlag.Name) * ctx.Int(CacheDatabaseFlag.Name) / 100
handles := MakeDatabaseHandles(ctx.Int(FDLimitFlag.Name)) / 10
blockdb, err := stack.OpenDatabaseWithFreezer("chaindata", cache, handles, "", "", readonly, disableFreeze, false, false, false, true)
blockdb, err := stack.OpenDatabaseWithFreezer("chaindata", cache, handles, "", "", readonly, disableFreeze, false, false)
if err != nil {
Fatalf("Failed to open separate block database: %v", err)
}
Expand Down
29 changes: 1 addition & 28 deletions core/rawdb/accessors_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,28 +311,6 @@ func ReadStateScheme(db ethdb.Reader) string {
return HashScheme
}

// ReadStateSchemeByStateDB reads the state scheme of persistent state from state disk db, or none
// if the state is not present in database
func ReadStateSchemeByStateDB(db, statediskdb ethdb.Reader) string {
// Check if state in path-based scheme is present
blob, _ := ReadAccountTrieNode(statediskdb, nil)
if len(blob) != 0 {
return PathScheme
}
// In a hash-based scheme, the genesis state is consistently stored
// on the disk. To assess the scheme of the persistent state, it
// suffices to inspect the scheme of the genesis state.
header := ReadHeader(db, ReadCanonicalHash(db, 0), 0)
if header == nil {
return "" // empty datadir
}
blob = ReadLegacyTrieNode(statediskdb, header.Root)
if len(blob) == 0 {
return "" // no state in disk
}
return HashScheme
}

// ValidateStateScheme used to check state scheme whether is valid.
// Valid state scheme: hash and path.
func ValidateStateScheme(stateScheme string) bool {
Expand All @@ -357,12 +335,7 @@ func ParseStateScheme(provided string, disk ethdb.Database) (string, error) {
// If state scheme is not specified, use the scheme consistent
// with persistent state, or fallback to hash mode if database
// is empty.
var stored string
if disk != nil && disk.StateStore() != nil {
stored = ReadStateSchemeByStateDB(disk, disk.StateStore())
} else {
stored = ReadStateScheme(disk)
}
stored := ReadStateScheme(disk)
if provided == "" {
if stored == "" {
// use default scheme for empty database, flip it when
Expand Down
2 changes: 2 additions & 0 deletions core/rawdb/chain_freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,11 @@ func (f *chainFreezer) freezeRange(nfdb *nofreezedb, number, limit uint64) (hash
if err := op.AppendRaw(ChainFreezerDifficultyTable, number, td); err != nil {
return fmt.Errorf("can't write td to Freezer: %v", err)
}

hashes = append(hashes, hash)
}
return nil
})

return hashes, err
}
2 changes: 1 addition & 1 deletion core/state/pruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func prune(snaptree *snapshot.Tree, root common.Hash, maindb ethdb.Database, sta

func (p *BlockPruner) backUpOldDb(name string, cache, handles int, namespace string, readonly, interrupt bool) error {
// Open old db wrapper.
chainDb, err := p.node.OpenDatabaseWithFreezer(name, cache, handles, p.oldAncientPath, namespace, readonly, true, interrupt, false, false, false)
chainDb, err := p.node.OpenDatabaseWithFreezer(name, cache, handles, p.oldAncientPath, namespace, readonly, true, interrupt, false)
if err != nil {
log.Error("Failed to open ancient database", "err=", err)
return err
Expand Down
4 changes: 0 additions & 4 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ type Config struct {
// the oldest unpruned block number.
PruneAncientData bool

// SeparateDB is an optional config and disabled by default. This is an experimental feature to separate chain
// data with data schema and isolated storage.
SeparateDB bool

TrieCleanCache int
TrieDirtyCache int
TrieTimeout time.Duration
Expand Down
6 changes: 1 addition & 5 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,12 +795,12 @@ func (n *Node) OpenAndMergeDatabase(name string, namespace string, readonly bool
// Open the separated state database if the state directory exists
if n.IsSeparatedDB() {
// Allocate half of the handles and cache to this separate state data database
statediskdb, err = n.OpenDatabaseWithFreezer(name+"/state", cache/2, chainDataHandles/2, "", "eth/db/statedata/", readonly, false, false, config.PruneAncientData, true, false)
statediskdb, err = n.OpenDatabaseWithFreezer(name+"/state", cache/2, chainDataHandles/2, "", "eth/db/statedata/", readonly, false, false, config.PruneAncientData)
if err != nil {
return nil, err
}

blockdb, err = n.OpenDatabaseWithFreezer(name+"/block", config.DatabaseCache/10, chainDataHandles/20, "", "eth/db/blockdata/", readonly, false, false, config.PruneAncientData, false, true)
blockdb, err = n.OpenDatabaseWithFreezer(name+"/block", config.DatabaseCache/10, chainDataHandles/20, "", "eth/db/blockdata/", readonly, false, false, config.PruneAncientData)
if err != nil {
return nil, err
}
Expand All @@ -810,7 +810,7 @@ func (n *Node) OpenAndMergeDatabase(name string, namespace string, readonly bool
chainDataHandles = int(float64(chainDataHandles) * 0.6)
}

chainDB, err := n.OpenDatabaseWithFreezer(name, cache, chainDataHandles, config.DatabaseFreezer, namespace, readonly, false, false, config.PruneAncientData, false, false)
chainDB, err := n.OpenDatabaseWithFreezer(name, cache, chainDataHandles, config.DatabaseFreezer, namespace, readonly, false, false, config.PruneAncientData)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -839,7 +839,7 @@ func (n *Node) OpenAndMergeDatabase(name string, namespace string, readonly bool
// also attaching a chain freezer to it that moves ancient chain data from the
// database to immutable append-only files. If the node is an ephemeral one, a
// memory database is returned.
func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, ancient, namespace string, readonly, disableFreeze, isLastOffset, pruneAncientData, isSeparateStateDB, isSeparateBlockDB bool) (ethdb.Database, error) {
func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, ancient, namespace string, readonly, disableFreeze, isLastOffset, pruneAncientData bool) (ethdb.Database, error) {
n.lock.Lock()
defer n.lock.Unlock()
if n.state == closedState {
Expand Down Expand Up @@ -872,12 +872,17 @@ func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, ancient,

// IsSeparatedDB check the state subdirectory of db, if subdirectory exists, return true
func (n *Node) IsSeparatedDB() bool {
separateDir := filepath.Join(n.ResolvePath("chaindata"), "state")
fileInfo, err := os.Stat(separateDir)
if os.IsNotExist(err) {
separateStateDir := filepath.Join(n.ResolvePath("chaindata"), "state")
fileInfo, err := os.Stat(separateStateDir)
if os.IsNotExist(err) || !fileInfo.IsDir() {
return false
}
return fileInfo.IsDir()
separateBlockDir := filepath.Join(n.ResolvePath("chaindata"), "block")
blockFileInfo, err := os.Stat(separateBlockDir)
if os.IsNotExist(err) || !blockFileInfo.IsDir() {
return false
}
return true
}

func (n *Node) OpenDiffDatabase(name string, handles int, diff, namespace string, readonly bool) (*leveldb.Database, error) {
Expand Down

0 comments on commit 8668912

Please sign in to comment.