Skip to content

Commit

Permalink
fix: fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
flywukong committed Mar 6, 2024
1 parent a44dc79 commit 38e115d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ 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)
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, true)
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)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
v := ctx.Uint64(utils.OverrideFeynman.Name)
cfg.Eth.OverrideFeynman = &v
}
if ctx.IsSet(utils.SeparateDBFlag.Name) && !stack.HasSeparateTrieDir() {
if ctx.IsSet(utils.SeparateDBFlag.Name) && !stack.IsSeparatedDB() {
utils.Fatalf("Failed to locate separate database subdirectory when separatedb parameter has been set")
}
backend, eth := utils.RegisterEthService(stack, &cfg.Eth)
Expand Down
14 changes: 7 additions & 7 deletions cmd/geth/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1119,13 +1119,13 @@ func hbss2pbss(ctx *cli.Context) error {

db := utils.MakeChainDatabase(ctx, stack, false, false)
db.Sync()
statediskdb := db.StateStore()
stateDiskDb := db.StateStore()
defer db.Close()

// convert hbss trie node to pbss trie node
var lastStateID uint64
if statediskdb != nil {
lastStateID = rawdb.ReadPersistentStateID(statediskdb)
if stateDiskDb != nil {
lastStateID = rawdb.ReadPersistentStateID(stateDiskDb)
} else {
lastStateID = rawdb.ReadPersistentStateID(db)
}
Expand Down Expand Up @@ -1180,8 +1180,8 @@ func hbss2pbss(ctx *cli.Context) error {
}

// repair state ancient offset
if statediskdb != nil {
lastStateID = rawdb.ReadPersistentStateID(statediskdb)
if stateDiskDb != nil {
lastStateID = rawdb.ReadPersistentStateID(stateDiskDb)
} else {
lastStateID = rawdb.ReadPersistentStateID(db)
}
Expand All @@ -1203,8 +1203,8 @@ func hbss2pbss(ctx *cli.Context) error {
return err
}
// prune hbss trie node
if statediskdb != nil {
err = rawdb.PruneHashTrieNodeInDataBase(statediskdb)
if stateDiskDb != nil {
err = rawdb.PruneHashTrieNodeInDataBase(stateDiskDb)
} else {
err = rawdb.PruneHashTrieNodeInDataBase(db)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2320,11 +2320,11 @@ 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)
chainDb, err = stack.OpenDatabaseWithFreezer("chaindata", cache, handles, ctx.String(AncientFlag.Name), "", readonly, disableFreeze, false, false)
// set the separate state database
if stack.HasSeparateTrieDir() && err == nil {
statediskdb := MakeStateDataBase(ctx, stack, readonly, false)
chainDb.SetStateStore(statediskdb)
if stack.IsSeparatedDB() && err == nil {
stateDiskDb := MakeStateDataBase(ctx, stack, readonly, false)
chainDb.SetStateStore(stateDiskDb)
}
}
if err != nil {
Expand All @@ -2337,7 +2337,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", cache, handles, "", "", readonly, disableFreeze, false, false, true)
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 Down
9 changes: 4 additions & 5 deletions node/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ import (
)

var (
ErrDatadirUsed = errors.New("datadir already used by another process")
ErrNodeStopped = errors.New("node not started")
ErrNodeRunning = errors.New("node already running")
ErrServiceUnknown = errors.New("unknown service")
ErrSeprateDBDatadir = errors.New("datadir is not configured when using separate trie")
ErrDatadirUsed = errors.New("datadir already used by another process")
ErrNodeStopped = errors.New("node not started")
ErrNodeRunning = errors.New("node already running")
ErrServiceUnknown = errors.New("unknown service")

datadirInUseErrnos = map[uint]bool{11: true, 32: true, 35: true}
)
Expand Down
15 changes: 6 additions & 9 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,9 +787,9 @@ func (n *Node) OpenAndMergeDatabase(name string, cache, handles int, freezer, di
var statediskdb ethdb.Database
var err error
// Open the separated state database if the state directory exists
if n.HasSeparateTrieDir() {
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, pruneAncientData, true)
statediskdb, err = n.OpenDatabaseWithFreezer(name+"/state", cache/2, chainDataHandles/2, "", "eth/db/statedata/", readonly, false, false, pruneAncientData)
if err != nil {
return nil, err
}
Expand All @@ -799,7 +799,7 @@ func (n *Node) OpenAndMergeDatabase(name string, cache, handles int, freezer, di
chainDataHandles = int(float64(chainDataHandles) * 0.6)
}

chainDB, err := n.OpenDatabaseWithFreezer(name, cache, chainDataHandles, freezer, namespace, readonly, false, false, pruneAncientData, false)
chainDB, err := n.OpenDatabaseWithFreezer(name, cache, chainDataHandles, freezer, namespace, readonly, false, false, pruneAncientData)
if err != nil {
return nil, err
}
Expand All @@ -824,7 +824,7 @@ func (n *Node) OpenAndMergeDatabase(name string, cache, handles int, freezer, di
// 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 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 All @@ -833,9 +833,6 @@ func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, ancient,
var db ethdb.Database
var err error
if n.config.DataDir == "" {
if isSeparateStateDB {
return nil, ErrSeprateDBDatadir
}
db = rawdb.NewMemoryDatabase()
} else {
db, err = rawdb.Open(rawdb.OpenOptions{
Expand All @@ -858,8 +855,8 @@ func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, ancient,
return db, err
}

// HasSeparateTrieDir check the state subdirectory of db, if subdirectory exists, return true
func (n *Node) HasSeparateTrieDir() bool {
// 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) {
Expand Down

0 comments on commit 38e115d

Please sign in to comment.