bsc/triedb/versiondb/versadb.go
joeycli 0af2fb4324 feat: support rewind for versa db
fix: rewind ancient store
2024-09-02 17:32:56 +08:00

78 lines
1.8 KiB
Go

package versiondb
import (
versa "github.com/bnb-chain/versioned-state-database"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/trie/trienode"
"github.com/ethereum/go-ethereum/trie/triestate"
)
type Config struct {
Path string
FlushInterval int64
MaxStatesInMem int
}
type VersionDB struct {
db versa.Database
}
func New(config *Config) *VersionDB {
var (
cfg *versa.VersaDBConfig
path = "./node/version_db" // TODO:: debug code
)
if config != nil {
path = config.Path
cfg = &versa.VersaDBConfig{
FlushInterval: config.FlushInterval,
MaxStatesInMem: config.MaxStatesInMem,
}
}
db, err := versa.NewVersaDB(path, cfg)
if err != nil {
log.Crit("failed to new version db", "error", err)
}
v := &VersionDB{
db: db,
}
log.Info("success to init version mode triedb")
return v
}
func (v *VersionDB) Scheme() string {
return rawdb.VersionScheme
}
func (v *VersionDB) Initialized(genesisRoot common.Hash) bool {
version, _ := v.db.LatestStoreDiskVersionInfo()
return version >= 0
}
func (v *VersionDB) Size() (common.StorageSize, common.StorageSize, common.StorageSize) {
// TODO:: waiting versa db supported
return 0, 0, 0
}
func (v *VersionDB) Update(root common.Hash, parent common.Hash, block uint64, nodes *trienode.MergedNodeSet, states *triestate.Set) error {
// TODO:: debug code, will change to return error.
panic("version db not supported")
}
func (v *VersionDB) Commit(root common.Hash, report bool) error {
// TODO:: debug code, will change to return error.
panic("version db not supported")
}
func (v *VersionDB) Close() error {
return v.db.Close()
}
func (v *VersionDB) VersaDB() versa.Database {
return v.db
}