make cache configurable

This commit is contained in:
i-norden 2021-10-19 16:19:44 -05:00
parent 64e80eeb6a
commit 01d0c21fd5

View File

@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
) )
// LvlDBReader exposes the necessary read functions on lvldb // LvlDBReader exposes the necessary read functions on lvldb
@ -34,16 +35,24 @@ type LvlDBReader struct {
chainConfig *params.ChainConfig chainConfig *params.ChainConfig
} }
// ReaderConfig struct for initializing a LvlDBReader
type ReaderConfig struct {
TrieConfig *trie.Config
ChainConfig *params.ChainConfig
Path, AncientPath string
DBCacheSize int
}
// NewLvlDBReader creates a new LvlDBReader // NewLvlDBReader creates a new LvlDBReader
func NewLvlDBReader(path, ancient string, chainConfig *params.ChainConfig) (*LvlDBReader, error) { func NewLvlDBReader(conf ReaderConfig) (*LvlDBReader, error) {
edb, err := rawdb.NewLevelDBDatabaseWithFreezer(path, 1024, 256, ancient, "eth-statediff-service", true) edb, err := rawdb.NewLevelDBDatabaseWithFreezer(conf.Path, conf.DBCacheSize, 256, conf.AncientPath, "eth-statediff-service", true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &LvlDBReader{ return &LvlDBReader{
ethDB: edb, ethDB: edb,
stateDB: state.NewDatabase(edb), stateDB: state.NewDatabaseWithConfig(edb, conf.TrieConfig),
chainConfig: chainConfig, chainConfig: conf.ChainConfig,
}, nil }, nil
} }