Skip to content

Commit

Permalink
Add override to avoid creating threads in StateDB.IntermediateRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsutton committed Aug 23, 2024
1 parent 0f5b9dc commit fb63f14
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ type StateDB struct {
StorageUpdated atomic.Int64
AccountDeleted int
StorageDeleted atomic.Int64

singlethreaded bool
}

// New creates a new state from a given trie.
Expand Down Expand Up @@ -196,6 +198,10 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
return sdb, nil
}

func (s *StateDB) MakeSingleThreaded() {
s.singlethreaded = true
}

// SetLogger sets the logger for account update hooks.
func (s *StateDB) SetLogger(l *tracing.Hooks) {
s.logger = l
Expand Down Expand Up @@ -867,7 +873,7 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
continue
}
obj := s.stateObjects[addr] // closure for the task runner below
workers.Go(func() error {
doUpdate := func() error {
if s.db.TrieDB().IsVerkle() {
obj.updateTrie()
} else {
Expand All @@ -880,7 +886,13 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
}
}
return nil
})
}
if s.singlethreaded {
// Ignores errors in the same way that the later workers.Wait() ignores errors
doUpdate()
} else {
workers.Go(doUpdate)
}
}
// If witness building is enabled, gather all the read-only accesses
if s.witness != nil {
Expand Down Expand Up @@ -913,7 +925,9 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
}
}
}
workers.Wait()
if !s.singlethreaded {
workers.Wait()
}
s.StorageUpdates += time.Since(start)

// Now we're about to start to write changes to the trie. The trie is so far
Expand Down

0 comments on commit fb63f14

Please sign in to comment.