diff --git a/core/blockchain.go b/core/blockchain.go index b4adee6ea3..5bcdbd78d5 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -372,8 +372,10 @@ 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) + log.Info("node run with separated trie database", "directory", separatedTrieConfig.TrieDataDir, + "db engine", separatedTrieConfig.SeparateDBEngine) 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{ Type: separatedTrieConfig.SeparateDBEngine, Directory: separateDir, @@ -410,10 +412,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis bc.flushInterval.Store(int64(cacheConfig.TrieTimeLimit)) bc.forker = NewForkChoice(bc, shouldPreserve) bc.stateCache = state.NewDatabaseWithNodeDB(bc.db, bc.triedb) - // validator may already been inited in the EnableBlockValidator function in the option - if bc.validator == nil { - bc.validator = NewBlockValidator(chainConfig, bc, engine) - } + bc.validator = NewBlockValidator(chainConfig, bc, engine) bc.prefetcher = NewStatePrefetcher(chainConfig, bc, engine) bc.processor = NewStateProcessor(chainConfig, bc, engine) @@ -551,7 +550,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis } bc.snaps, _ = snapshot.New(snapconfig, bc.db, bc.triedb, head.Root, int(bc.cacheConfig.TriesInMemory), bc.stateCache.NoTries()) } - // do options before start any routine for _, option := range options { bc, err = option(bc) @@ -559,7 +557,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis return nil, err } } - // Start future block processor. bc.wg.Add(1) go bc.updateFutureBlocks() diff --git a/core/rawdb/database.go b/core/rawdb/database.go index c219f8f042..2dba0e8ddc 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -471,8 +471,6 @@ type OpenOptions struct { DisableFreeze bool IsLastOffset bool PruneAncientData bool - IsSeparateDB bool // indicates if it is a separated db which stored snapshot, meta and block data. - IsSingleTrieDB bool // indicates if it is a separated which stored trie data. } // openKeyValueDatabase opens a disk-based key-value database, e.g. leveldb or pebble. diff --git a/core/state/state_object.go b/core/state/state_object.go index 1dea0a0f4f..935620584b 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -179,7 +179,6 @@ func (s *stateObject) getOriginStorage(key common.Hash) (common.Hash, bool) { if value, cached := s.originStorage[key]; cached { return value, true } - // if L1 cache miss, try to get it from shared pool if s.sharedOriginStorage != nil { val, ok := s.sharedOriginStorage.Load(key) diff --git a/eth/filters/bench_test.go b/eth/filters/bench_test.go index 2cc656a622..dfd47e2867 100644 --- a/eth/filters/bench_test.go +++ b/eth/filters/bench_test.go @@ -66,7 +66,7 @@ func benchmarkBloomBits(b *testing.B, sectionSize uint64) { benchDataDir := node.DefaultDataDir() + "/geth/chaindata" b.Log("Running bloombits benchmark section size:", sectionSize) - db, err := rawdb.NewLevelDBDatabase(benchDataDir, 128, 1024, "", false, false, false) + db, err := rawdb.NewLevelDBDatabase(benchDataDir, 128, 1024, "", false) if err != nil { b.Fatalf("error opening database at %v: %v", benchDataDir, err) } @@ -130,7 +130,7 @@ func benchmarkBloomBits(b *testing.B, sectionSize uint64) { for i := 0; i < benchFilterCnt; i++ { if i%20 == 0 { db.Close() - db, _ = rawdb.NewLevelDBDatabase(benchDataDir, 128, 1024, "", false, false, false) + db, _ = rawdb.NewLevelDBDatabase(benchDataDir, 128, 1024, "", false) backend = &testBackend{db: db, sections: cnt} sys = NewFilterSystem(backend, Config{}) } @@ -164,7 +164,7 @@ func BenchmarkNoBloomBits(b *testing.B) { b.Skip("test disabled: this tests presume (and modify) an existing datadir.") benchDataDir := node.DefaultDataDir() + "/geth/chaindata" b.Log("Running benchmark without bloombits") - db, err := rawdb.NewLevelDBDatabase(benchDataDir, 128, 1024, "", false, false, false) + db, err := rawdb.NewLevelDBDatabase(benchDataDir, 128, 1024, "", false) if err != nil { b.Fatalf("error opening database at %v: %v", benchDataDir, err) } diff --git a/ethdb/leveldb/leveldb.go b/ethdb/leveldb/leveldb.go index aff922afa4..c0e0eb250a 100644 --- a/ethdb/leveldb/leveldb.go +++ b/ethdb/leveldb/leveldb.go @@ -132,7 +132,6 @@ func NewCustom(file string, namespace string, customize func(options *opt.Option log: logger, quitChan: make(chan chan error), } - ldb.compTimeMeter = metrics.NewRegisteredMeter(namespace+"compact/time", nil) ldb.compReadMeter = metrics.NewRegisteredMeter(namespace+"compact/input", nil) ldb.compWriteMeter = metrics.NewRegisteredMeter(namespace+"compact/output", nil) diff --git a/ethdb/pebble/pebble.go b/ethdb/pebble/pebble.go index 9019031083..429e92004e 100644 --- a/ethdb/pebble/pebble.go +++ b/ethdb/pebble/pebble.go @@ -138,7 +138,6 @@ func New(file string, cache int, handles int, namespace string, readonly bool) ( if handles < minHandles { handles = minHandles } - logger := log.New("database", file) // The max memtable size is limited by the uint32 offsets stored in diff --git a/node/node.go b/node/node.go index 21e69dbc63..42a89be00b 100644 --- a/node/node.go +++ b/node/node.go @@ -780,7 +780,6 @@ func (n *Node) OpenAndMergeDatabase(name string, cache, handles int, freezer, di chainDataHandles := handles if persistDiff { chainDataHandles = handles * chainDataHandlesPercentage / 100 - log.Info("persist diff is true", "handler", chainDataHandles) } chainDB, err := n.OpenDatabaseWithFreezer(name, cache, chainDataHandles, freezer, namespace, readonly, false, false, pruneAncientData) if err != nil { @@ -833,6 +832,9 @@ func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, ancient, return db, err } +// OpenTrieDataBase opens an existing database to store the trie data with the given name (or +// creates one if no previous can be found) from within the node's data directory. +// This function is only used in scenarios where the separate db is used. func (n *Node) OpenTrieDataBase(name string, cache, handles int, ancient, namespace string, readonly, disableFreeze, isLastOffset, pruneAncientData bool) (ethdb.Database, error) { n.lock.Lock() defer n.lock.Unlock() @@ -841,23 +843,19 @@ func (n *Node) OpenTrieDataBase(name string, cache, handles int, ancient, namesp } var db ethdb.Database var err error - if n.config.DataDir == "" { - db = rawdb.NewMemoryDatabase() - } else { - separateDir := filepath.Join(n.config.GetTrieDir(), name) - db, err = rawdb.Open(rawdb.OpenOptions{ - Type: n.config.DBEngine, - Directory: separateDir, - AncientsDirectory: filepath.Join(separateDir, ancient), - Namespace: namespace, - Cache: cache, - Handles: handles, - ReadOnly: readonly, - DisableFreeze: disableFreeze, - IsLastOffset: isLastOffset, - PruneAncientData: pruneAncientData, - }) - } + separateDir := filepath.Join(n.config.GetTrieDir(), name) + db, err = rawdb.Open(rawdb.OpenOptions{ + Type: n.config.DBEngine, + Directory: separateDir, + AncientsDirectory: filepath.Join(separateDir, ancient), + Namespace: namespace, + Cache: cache, + Handles: handles, + ReadOnly: readonly, + DisableFreeze: disableFreeze, + IsLastOffset: isLastOffset, + PruneAncientData: pruneAncientData, + }) if err == nil { db = n.wrapDatabase(db)