core/state: ensure triedb Commit after Update (#1900)

This commit is contained in:
Nathan 2023-09-27 11:07:45 +08:00 committed by GitHub
parent c955dd2189
commit f8bc2b76ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1608,6 +1608,22 @@ func (s *StateDB) Commit(block uint64, failPostCommitFunc func(), postCommitFunc
if root != types.EmptyRootHash {
s.db.CacheAccount(root, s.trie)
}
origin := s.originalRoot
if origin == (common.Hash{}) {
origin = types.EmptyRootHash
}
if root != origin {
start := time.Now()
if err := s.db.TrieDB().Update(root, origin, block, nodes, triestate.New(s.accountsOrigin, s.storagesOrigin, incomplete)); err != nil {
return err
}
s.originalRoot = root
if metrics.EnabledExpensive {
s.TrieDBCommits += time.Since(start)
}
}
}
for _, postFunc := range postCommitFuncs {
@ -1732,24 +1748,10 @@ func (s *StateDB) Commit(block uint64, failPostCommitFunc func(), postCommitFunc
} else {
s.snap = nil
}
if root == (common.Hash{}) {
root = types.EmptyRootHash
}
origin := s.originalRoot
if origin == (common.Hash{}) {
origin = types.EmptyRootHash
}
if root != origin {
start := time.Now()
if err := s.db.TrieDB().Update(root, origin, block, nodes, triestate.New(s.accountsOrigin, s.storagesOrigin, incomplete)); err != nil {
return common.Hash{}, nil, err
}
s.originalRoot = root
if metrics.EnabledExpensive {
s.TrieDBCommits += time.Since(start)
}
}
// Clear all internal flags at the end of commit operation.
s.accounts = make(map[common.Hash][]byte)
s.storages = make(map[common.Hash]map[common.Hash][]byte)