Skip to content

Commit

Permalink
chore: add notrie check in statedb commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joeylichang committed Jun 6, 2024
1 parent 9a37a62 commit be44bde
Showing 1 changed file with 42 additions and 38 deletions.
80 changes: 42 additions & 38 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
// which will affect performance, so it is discarded
//storageTrieNodesUpdated int
//storageTrieNodesDeleted int

nodes = trienode.NewMergedNodeSet()
incomplete map[common.Address]struct{}
)
Expand Down Expand Up @@ -1368,13 +1368,16 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
if obj := s.stateObjects[addr]; !obj.deleted {
tasks <- func() {
// Write any storage changes in the state object to its storage trie
if set, err := obj.commit(); err != nil {
taskResults <- taskResult{err, nil}
return
if !s.noTrie {
if set, err := obj.commit(); err != nil {
taskResults <- taskResult{err, nil}
return
} else {
taskResults <- taskResult{nil, set}
}
} else {
taskResults <- taskResult{nil, set}
taskResults <- taskResult{nil, nil}
}

}
tasksNum++
}
Expand All @@ -1397,45 +1400,46 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
}
close(finishCh)

var start time.Time
if metrics.EnabledExpensive {
start = time.Now()
}
root, set, err := s.trie.Commit(true)
if err != nil {
return err
}
// Merge the dirty nodes of account trie into global set
if set != nil {
if err := nodes.Merge(set); err != nil {
return err
if !s.noTrie {
var start time.Time
if metrics.EnabledExpensive {
start = time.Now()
}
accountTrieNodesUpdated, accountTrieNodesDeleted = set.Size()
}
if metrics.EnabledExpensive {
s.AccountCommits += time.Since(start)
}

origin := s.originalRoot
if origin == (common.Hash{}) {
origin = types.EmptyRootHash
}

if root != origin {
start := time.Now()
set := triestate.New(s.accountsOrigin, s.storagesOrigin, incomplete)
if err := s.db.TrieDB().Update(root, origin, block, nodes, set); err != nil {
root, set, err := s.trie.Commit(true)
if err != nil {
return err
}
s.originalRoot = root
// Merge the dirty nodes of account trie into global set
if set != nil {
if err := nodes.Merge(set); err != nil {
return err
}
accountTrieNodesUpdated, accountTrieNodesDeleted = set.Size()
}
if metrics.EnabledExpensive {
s.TrieDBCommits += time.Since(start)
s.AccountCommits += time.Since(start)
}

origin := s.originalRoot
if origin == (common.Hash{}) {
origin = types.EmptyRootHash
}
if s.onCommit != nil {
s.onCommit(set)

if root != origin {
start := time.Now()
set := triestate.New(s.accountsOrigin, s.storagesOrigin, incomplete)
if err := s.db.TrieDB().Update(root, origin, block, nodes, set); err != nil {
return err
}
s.originalRoot = root
if metrics.EnabledExpensive {
s.TrieDBCommits += time.Since(start)
}
if s.onCommit != nil {
s.onCommit(set)
}
}
}

wg.Wait()
return nil
},
Expand Down

0 comments on commit be44bde

Please sign in to comment.