chore: delete write batch and change versa config

This commit is contained in:
joeylichang 2024-09-30 15:11:05 +08:00
parent 37b942eb2c
commit 7bf93179b9
2 changed files with 22 additions and 39 deletions

@ -679,7 +679,7 @@ func (s *StateDB) GetTransientState(addr common.Address, key common.Hash) common
// //
// updateStateObject writes the given object to the trie. // updateStateObject writes the given object to the trie.
func (s *StateDB) updateStateObject(obj *stateObject, accounts map[string][]byte) { func (s *StateDB) updateStateObject(obj *stateObject) {
if s.noTrie { if s.noTrie {
return return
} }
@ -689,16 +689,10 @@ func (s *StateDB) updateStateObject(obj *stateObject, accounts map[string][]byte
} }
// Encode the account and update the account trie // Encode the account and update the account trie
addr := obj.Address() addr := obj.Address()
//if err := s.trie.UpdateAccount(addr, &obj.data); err != nil { if err := s.trie.UpdateAccount(addr, &obj.data); err != nil {
// s.setError(fmt.Errorf("updateStateObject (%x) error: %v", addr[:], err)) s.setError(fmt.Errorf("updateStateObject (%x) error: %v", addr[:], err))
//}
data, err := rlp.EncodeToBytes(&obj.data)
if err != nil {
s.setError(fmt.Errorf("rlp updateStateObject (%x) error: %v", addr[:], err))
} }
accounts[string(addr.Bytes())] = data
if obj.dirtyCode { if obj.dirtyCode {
s.trie.UpdateContractCode(obj.Address(), common.BytesToHash(obj.CodeHash()), obj.code) s.trie.UpdateContractCode(obj.Address(), common.BytesToHash(obj.CodeHash()), obj.code)
} }
@ -716,7 +710,7 @@ func (s *StateDB) updateStateObject(obj *stateObject, accounts map[string][]byte
} }
// deleteStateObject removes the given object from the state trie. // deleteStateObject removes the given object from the state trie.
func (s *StateDB) deleteStateObject(obj *stateObject, accounts map[string][]byte) { func (s *StateDB) deleteStateObject(obj *stateObject) {
if s.noTrie { if s.noTrie {
return return
} }
@ -727,10 +721,9 @@ func (s *StateDB) deleteStateObject(obj *stateObject, accounts map[string][]byte
// Delete the account from the trie // Delete the account from the trie
addr := obj.Address() addr := obj.Address()
accounts[string(addr.Bytes())] = nil if err := s.trie.DeleteAccount(addr); err != nil {
//if err := s.trie.DeleteAccount(addr); err != nil { s.setError(fmt.Errorf("deleteStateObject (%x) error: %v", addr[:], err))
// s.setError(fmt.Errorf("deleteStateObject (%x) error: %v", addr[:], err)) }
//}
} }
// getStateObject retrieves a state object given by the address, returning nil if // getStateObject retrieves a state object given by the address, returning nil if
@ -1282,23 +1275,19 @@ func (s *StateDB) StateIntermediateRoot() common.Hash {
s.trie = tr s.trie = tr
} }
accounts := make(map[string][]byte)
usedAddrs := make([][]byte, 0, len(s.stateObjectsPending)) usedAddrs := make([][]byte, 0, len(s.stateObjectsPending))
if !s.noTrie { if !s.noTrie {
for addr := range s.stateObjectsPending { for addr := range s.stateObjectsPending {
if obj := s.stateObjects[addr]; obj.deleted { if obj := s.stateObjects[addr]; obj.deleted {
s.deleteStateObject(obj, accounts) s.deleteStateObject(obj)
} else { } else {
s.updateStateObject(obj, accounts) s.updateStateObject(obj)
} }
usedAddrs = append(usedAddrs, common.CopyBytes(addr[:])) // Copy needed for closure usedAddrs = append(usedAddrs, common.CopyBytes(addr[:])) // Copy needed for closure
} }
if prefetcher != nil { if prefetcher != nil {
prefetcher.used(common.Hash{}, s.originalRoot, usedAddrs) prefetcher.used(common.Hash{}, s.originalRoot, usedAddrs)
} }
if err := s.trie.WriteBatch(accounts); err != nil {
s.setError(fmt.Errorf("WriteBatchStateObject error: %v", err))
}
} }
if len(s.stateObjectsPending) > 0 { if len(s.stateObjectsPending) > 0 {

@ -22,28 +22,22 @@ type VersionDB struct {
func New(config *Config) *VersionDB { func New(config *Config) *VersionDB {
var ( var (
cfg *versa.VersaDBConfig //cfg *versa.VersaDBConfig
path = "./node/version_db" // TODO:: debug code path = "./node/version_db" // TODO:: debug code
) )
if config != nil { //if config != nil {
path = config.Path // path = config.Path
cfg = &versa.VersaDBConfig{ // cfg = &versa.VersaDBConfig{
FlushInterval: 2000, // FlushInterval: 2000,
MaxStatesInMem: 128, // MaxStatesInMem: 128,
MemLowWaterMark: 10, // MemLowWaterMark: 10,
MemHighWaterMark: 20, // MemHighWaterMark: 20,
MemEvictInternal: 200, // MemEvictInternal: 200,
} // }
_ = cfg // _ = cfg
} //}
db, err := versa.NewVersaDB(path, &versa.VersaDBConfig{ db, err := versa.NewVersaDB(path, nil)
FlushInterval: 2000,
MaxStatesInMem: 128,
MemLowWaterMark: 10,
MemHighWaterMark: 20,
MemEvictInternal: 200,
})
if err != nil { if err != nil {
log.Crit("failed to new version db", "error", err) log.Crit("failed to new version db", "error", err)
} }