Skip to content
Open
4 changes: 4 additions & 0 deletions app/seidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const (
FlagSSPruneInterval = "state-store.ss-prune-interval"
FlagSSImportNumWorkers = "state-store.ss-import-num-workers"
FlagSSReadWriteMetrics = "state-store.ss-enable-read-write-metrics"
FlagSSCacheSize = "state-store.ss-cache-size-bytes"

// EVM SS optimization (embedded in SS config, controlled via write/read mode)
FlagEVMSSDirectory = "state-store.evm-ss-db-directory"
Expand Down Expand Up @@ -203,6 +204,9 @@ func parseSSConfigs(appOpts servertypes.AppOptions) config.StateStoreConfig {
ssConfig.ImportNumWorkers = cast.ToInt(appOpts.Get(FlagSSImportNumWorkers))
ssConfig.DBDirectory = cast.ToString(appOpts.Get(FlagSSDirectory))
ssConfig.EnableReadWriteMetrics = cast.ToBool(appOpts.Get(FlagSSReadWriteMetrics))
if v := appOpts.Get(FlagSSCacheSize); v != nil {
ssConfig.CacheSizeBytes = cast.ToInt64(v)
}

// EVM optimization fields (embedded in SS config)
ssConfig.EVMDBDirectory = cast.ToString(appOpts.Get(FlagEVMSSDirectory))
Expand Down
1 change: 1 addition & 0 deletions sei-cosmos/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ func GetConfig(v *viper.Viper) (Config, error) {
EVMSplit: v.GetBool("state-store.evm-ss-split"),
EVMDBDirectory: v.GetString("state-store.evm-ss-db-directory"),
SeparateEVMSubDBs: v.GetBool("state-store.evm-ss-separate-dbs"),
CacheSizeBytes: v.GetInt64("state-store.ss-cache-size-bytes"),
},
Genesis: GenesisConfig{
StreamImport: v.GetBool("genesis.stream-import"),
Expand Down
23 changes: 16 additions & 7 deletions sei-db/config/ss_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ package config
type DBBackend string

const (
DefaultSSKeepRecent = 100000
DefaultSSPruneInterval = 600
DefaultSSImportWorkers = 1
DefaultSSAsyncBuffer = 100
PebbleDBBackend = "pebbledb"
RocksDBBackend = "rocksdb"
DefaultSSBackend = PebbleDBBackend
DefaultSSKeepRecent = 100000
DefaultSSPruneInterval = 600
DefaultSSImportWorkers = 1
DefaultSSAsyncBuffer = 100
PebbleDBBackend = "pebbledb"
RocksDBBackend = "rocksdb"
DefaultSSBackend = PebbleDBBackend
DefaultSSCacheSizeBytes = 32 * 1024 * 1024
)

// StateStoreConfig defines configuration for the state store (SS) layer.
Expand Down Expand Up @@ -80,6 +81,13 @@ type StateStoreConfig struct {
// When true, data is routed to separate DBs by EVM key family while
// preserving the same logical store key and full key encoding inside each DB.
SeparateEVMSubDBs bool `mapstructure:"evm-separate-dbs"`

// CacheSizeBytes defines the pebbledb block cache size (in bytes) for the
// state store backend. Historical reads (e.g. eth debug_trace*, archival
// queries) are served from the SS backend rather than memIAVL, so a larger
// cache reduces disk-bound random reads. Set <= 0 to use the default.
// defaults to 32 MiB
CacheSizeBytes int64 `mapstructure:"ss-cache-size-bytes"`
}

// DefaultStateStoreConfig returns the default StateStoreConfig
Expand All @@ -95,5 +103,6 @@ func DefaultStateStoreConfig() StateStoreConfig {
UseDefaultComparer: false,
EVMSplit: false,
SeparateEVMSubDBs: false,
CacheSizeBytes: DefaultSSCacheSizeBytes,
}
}
6 changes: 6 additions & 0 deletions sei-db/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ evm-ss-split = {{ .StateStore.EVMSplit }}
# When false, all EVM data stays in one DB using the current unified layout.
# When true, data is routed to separate DBs while preserving the same evm key prefix format.
evm-ss-separate-dbs = {{ .StateStore.SeparateEVMSubDBs }}

# CacheSizeBytes defines the pebbledb block cache size (in bytes) for the state store.
# Historical reads (e.g. eth debug_trace*, archival queries) are served from the SS
# backend rather than memIAVL, so a larger cache reduces disk-bound random reads.
# Set <= 0 to use the default. Defaults to 33554432 (32 MiB).
ss-cache-size-bytes = {{ .StateStore.CacheSizeBytes }}
`

// ReceiptStoreConfigTemplate defines the configuration template for receipt-store
Expand Down
12 changes: 8 additions & 4 deletions sei-db/db_engine/pebbledb/mvcc/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

errorutils "github.com/sei-protocol/sei-chain/sei-db/common/errors"
"github.com/sei-protocol/sei-chain/sei-db/common/utils"
"github.com/sei-protocol/sei-chain/sei-db/config"
seidbconfig "github.com/sei-protocol/sei-chain/sei-db/config"
pebbledbmetrics "github.com/sei-protocol/sei-chain/sei-db/db_engine/pebbledb"
"github.com/sei-protocol/sei-chain/sei-db/db_engine/types"
"github.com/sei-protocol/sei-chain/sei-db/proto"
Expand Down Expand Up @@ -69,7 +69,7 @@ var (
type Database struct {
storage *pebble.DB
asyncWriteWG sync.WaitGroup
config config.StateStoreConfig
config seidbconfig.StateStoreConfig
// Earliest version for db after pruning
earliestVersion atomic.Int64
// Latest version for db
Expand Down Expand Up @@ -103,8 +103,12 @@ type VersionedChangesets struct {
Done chan struct{} // non-nil for barrier: closed when this entry is processed
}

func OpenDB(dataDir string, config config.StateStoreConfig) (types.StateStore, error) {
cache := pebble.NewCache(1024 * 1024 * 32)
func OpenDB(dataDir string, config seidbconfig.StateStoreConfig) (types.StateStore, error) {
cacheSizeBytes := config.CacheSizeBytes
if cacheSizeBytes <= 0 {
cacheSizeBytes = seidbconfig.DefaultSSCacheSizeBytes
}
cache := pebble.NewCache(cacheSizeBytes)
defer cache.Unref()

// Select comparer based on config. Note: UseDefaultComparer is NOT backwards compatible
Expand Down
Loading