mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Revert "core, trie: cleanup trie database (#28062)"
This reverts commit ef485b7254.
This commit is contained in:
parent
37c7dff490
commit
00c76bbe2b
4 changed files with 26 additions and 20 deletions
|
|
@ -135,9 +135,6 @@ type StateDB struct {
|
||||||
StorageUpdated int
|
StorageUpdated int
|
||||||
AccountDeleted int
|
AccountDeleted int
|
||||||
StorageDeleted int
|
StorageDeleted int
|
||||||
|
|
||||||
// Testing hooks
|
|
||||||
onCommit func(states *triestate.Set) // Hook invoked when commit is performed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new state from a given trie.
|
// New creates a new state from a given trie.
|
||||||
|
|
@ -1279,17 +1276,13 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
|
||||||
}
|
}
|
||||||
if root != origin {
|
if root != origin {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
set := triestate.New(s.accountsOrigin, s.storagesOrigin, incomplete)
|
if err := s.db.TrieDB().Update(root, origin, block, nodes, triestate.New(s.accountsOrigin, s.storagesOrigin, incomplete)); err != nil {
|
||||||
if err := s.db.TrieDB().Update(root, origin, block, nodes, set); err != nil {
|
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
s.originalRoot = root
|
s.originalRoot = root
|
||||||
if metrics.EnabledExpensive {
|
if metrics.EnabledExpensive {
|
||||||
s.TrieDBCommits += time.Since(start)
|
s.TrieDBCommits += time.Since(start)
|
||||||
}
|
}
|
||||||
if s.onCommit != nil {
|
|
||||||
s.onCommit(set)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Clear all internal flags at the end of commit operation.
|
// Clear all internal flags at the end of commit operation.
|
||||||
s.accounts = make(map[common.Hash][]byte)
|
s.accounts = make(map[common.Hash][]byte)
|
||||||
|
|
|
||||||
|
|
@ -181,7 +181,7 @@ func (test *stateTest) run() bool {
|
||||||
storageList = append(storageList, copy2DSet(states.Storages))
|
storageList = append(storageList, copy2DSet(states.Storages))
|
||||||
}
|
}
|
||||||
disk = rawdb.NewMemoryDatabase()
|
disk = rawdb.NewMemoryDatabase()
|
||||||
tdb = trie.NewDatabase(disk, &trie.Config{PathDB: pathdb.Defaults})
|
tdb = trie.NewDatabase(disk, &trie.Config{OnCommit: onCommit, PathDB: pathdb.Defaults})
|
||||||
sdb = NewDatabaseWithNodeDB(disk, tdb)
|
sdb = NewDatabaseWithNodeDB(disk, tdb)
|
||||||
byzantium = rand.Intn(2) == 0
|
byzantium = rand.Intn(2) == 0
|
||||||
)
|
)
|
||||||
|
|
@ -206,8 +206,6 @@ func (test *stateTest) run() bool {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
state.onCommit = onCommit
|
|
||||||
|
|
||||||
for i, action := range actions {
|
for i, action := range actions {
|
||||||
if i%test.chunk == 0 && i != 0 {
|
if i%test.chunk == 0 && i != 0 {
|
||||||
if byzantium {
|
if byzantium {
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,9 @@ type Config struct {
|
||||||
Preimages bool // Flag whether the preimage of node key is recorded
|
Preimages bool // Flag whether the preimage of node key is recorded
|
||||||
HashDB *hashdb.Config // Configs for hash-based scheme
|
HashDB *hashdb.Config // Configs for hash-based scheme
|
||||||
PathDB *pathdb.Config // Configs for experimental path-based scheme
|
PathDB *pathdb.Config // Configs for experimental path-based scheme
|
||||||
|
|
||||||
|
// Testing hooks
|
||||||
|
OnCommit func(states *triestate.Set) // Hook invoked when commit is performed
|
||||||
}
|
}
|
||||||
|
|
||||||
// HashDefaults represents a config for using hash-based scheme with
|
// HashDefaults represents a config for using hash-based scheme with
|
||||||
|
|
@ -85,6 +88,20 @@ type Database struct {
|
||||||
backend backend // The backend for managing trie nodes
|
backend backend // The backend for managing trie nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prepare initializes the database with provided configs, but the
|
||||||
|
// database backend is still left as nil.
|
||||||
|
func prepare(diskdb ethdb.Database, config *Config) *Database {
|
||||||
|
var preimages *preimageStore
|
||||||
|
if config != nil && config.Preimages {
|
||||||
|
preimages = newPreimageStore(diskdb)
|
||||||
|
}
|
||||||
|
return &Database{
|
||||||
|
config: config,
|
||||||
|
diskdb: diskdb,
|
||||||
|
preimages: preimages,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewDatabase initializes the trie database with default settings, note
|
// NewDatabase initializes the trie database with default settings, note
|
||||||
// the legacy hash-based scheme is used by default.
|
// the legacy hash-based scheme is used by default.
|
||||||
func NewDatabase(diskdb ethdb.Database, config *Config) *Database {
|
func NewDatabase(diskdb ethdb.Database, config *Config) *Database {
|
||||||
|
|
@ -132,6 +149,9 @@ func (db *Database) Reader(blockRoot common.Hash) (Reader, error) {
|
||||||
// The passed in maps(nodes, states) will be retained to avoid copying everything.
|
// The passed in maps(nodes, states) will be retained to avoid copying everything.
|
||||||
// Therefore, these maps must not be changed afterwards.
|
// Therefore, these maps must not be changed afterwards.
|
||||||
func (db *Database) Update(root common.Hash, parent common.Hash, block uint64, nodes *trienode.MergedNodeSet, states *triestate.Set) error {
|
func (db *Database) Update(root common.Hash, parent common.Hash, block uint64, nodes *trienode.MergedNodeSet, states *triestate.Set) error {
|
||||||
|
if db.config != nil && db.config.OnCommit != nil {
|
||||||
|
db.config.OnCommit(states)
|
||||||
|
}
|
||||||
if db.preimages != nil {
|
if db.preimages != nil {
|
||||||
db.preimages.commit(false)
|
db.preimages.commit(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,16 +25,11 @@ import (
|
||||||
|
|
||||||
// newTestDatabase initializes the trie database with specified scheme.
|
// newTestDatabase initializes the trie database with specified scheme.
|
||||||
func newTestDatabase(diskdb ethdb.Database, scheme string) *Database {
|
func newTestDatabase(diskdb ethdb.Database, scheme string) *Database {
|
||||||
config := &Config{Preimages: false}
|
db := prepare(diskdb, nil)
|
||||||
if scheme == rawdb.HashScheme {
|
if scheme == rawdb.HashScheme {
|
||||||
config.HashDB = &hashdb.Config{
|
db.backend = hashdb.New(diskdb, &hashdb.Config{}, mptResolver{})
|
||||||
CleanCacheSize: 0,
|
|
||||||
} // disable clean cache
|
|
||||||
} else {
|
} else {
|
||||||
config.PathDB = &pathdb.Config{
|
db.backend = pathdb.New(diskdb, &pathdb.Config{}) // disable clean/dirty cache
|
||||||
CleanCacheSize: 0,
|
|
||||||
DirtyCacheSize: 0,
|
|
||||||
} // disable clean/dirty cache
|
|
||||||
}
|
}
|
||||||
return NewDatabase(diskdb, config)
|
return db
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue