Skip to content

Commit

Permalink
fix: fix ancient dir of seprate trie db
Browse files Browse the repository at this point in the history
  • Loading branch information
flywukong committed Jan 18, 2024
1 parent 18689f2 commit 5672be8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 1 addition & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
var triedb *trie.Database
if cacheConfig.SeparateTrieConfig != nil {
separatedTrieConfig := cacheConfig.SeparateTrieConfig
log.Info("node run with separated trie database", "directory", separatedTrieConfig.TrieDataDir,
"db engine", separatedTrieConfig.SeparateDBEngine)
log.Info("node run with separated trie database", "directory", separatedTrieConfig.TrieDataDir)
separateDir := filepath.Join(separatedTrieConfig.TrieDataDir, separatedTrieConfig.TrieName)
// open the separated db to init the trie database which only store the trie data
separateDB, dbErr := rawdb.Open(rawdb.OpenOptions{
Expand Down
15 changes: 12 additions & 3 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ import (
"github.com/ethereum/go-ethereum/trie/triedb/pathdb"
)

const (
SeparateDBNamespace = "eth/separatedb/chaindata/"
SeparateTrieNamespace = "eth/triedb/chaindata/"
)

// Config contains the configuration options of the ETH protocol.
// Deprecated: use ethconfig.Config instead.
type Config = ethconfig.Config
Expand Down Expand Up @@ -157,7 +162,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
// It is the separated db which contain snapshot, meta and block data with no trie data storing in it.
// Allocate partial handles and cache to this separate database because it is not a complete database.
chainDb, err = stack.OpenAndMergeDatabase("chaindata", int(float64(config.DatabaseCache)*0.6), int(float64(config.DatabaseHandles)*0.6),
config.DatabaseFreezer, config.DatabaseDiff, "eth/separatedb/chaindata/", false, config.PersistDiff, config.PruneAncientData)
config.DatabaseFreezer, config.DatabaseDiff, SeparateDBNamespace, false, config.PersistDiff, config.PruneAncientData)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -275,15 +280,19 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {

// if the separated trie db has set, need to new blockchain with the separated trie database
if stack.Config().TrieDir != "" {
ancientDir := config.DatabaseFreezer
if ancientDir == "" {
ancientDir = "ancient"
}
// Allocate partial handles and cache to this separated database.
separatedDBConfig := &core.SeparateTrieConfig{
SeparateDBHandles: int(float64(config.DatabaseHandles) * 0.5),
SeparateDBCache: int(float64(config.DatabaseCache) * 0.5),
SeparateDBEngine: stack.Config().DBEngine,
TrieDataDir: stack.Config().GetTrieDir(),
TrieNameSpace: "eth/triedb/chaindata/",
TrieNameSpace: SeparateTrieNamespace,
TrieName: "chaindata",
SeparateDBAncient: config.DatabaseFreezer,
SeparateDBAncient: ancientDir,
}
cacheConfig.SeparateTrieConfig = separatedDBConfig
}
Expand Down

0 comments on commit 5672be8

Please sign in to comment.