@@ -567,13 +567,9 @@ func (s *StateDB) GetTransientState(addr common.Address, key common.Hash) common
567567//
568568
569569// updateStateObject writes the given object to the trie.
570- func (s * StateDB ) updateStateObject (obj * stateObject ) {
571- // Encode the account and update the account trie
572- if err := s .trie .UpdateAccount (obj .Address (), & obj .data , len (obj .code )); err != nil {
573- s .setError (fmt .Errorf ("updateStateObject (%x) error: %v" , obj .Address (), err ))
574- }
575- if obj .dirtyCode {
576- s .trie .UpdateContractCode (obj .Address (), common .BytesToHash (obj .CodeHash ()), obj .code )
570+ func (s * StateDB ) updateStateObject (addr common.Address , resolver func () * types.StateAccount ) {
571+ if err := s .trie .UpdateAccountAsync (addr , resolver ); err != nil {
572+ s .setError (fmt .Errorf ("updateStateObject (%x) error: %v" , addr , err ))
577573 }
578574}
579575
@@ -829,11 +825,14 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
829825 // later time.
830826 workers .SetLimit (1 )
831827 }
828+
829+ stateObjectsResolve := make (map [common.Address ]func () * types.StateAccount )
832830 for addr , op := range s .mutations {
833831 if op .applied || op .isDelete () {
834832 continue
835833 }
836834 obj := s .stateObjects [addr ] // closure for the task runner below
835+ complete := make (chan * types.StateAccount )
837836 workers .Go (func () error {
838837 if s .db .TrieDB ().IsVerkle () {
839838 obj .updateTrie ()
@@ -846,8 +845,13 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
846845 s .witness .AddState (obj .trie .Witness ())
847846 }
848847 }
848+ complete <- & obj .data
849849 return nil
850850 })
851+
852+ stateObjectsResolve [addr ] = func () * types.StateAccount {
853+ return <- complete
854+ }
851855 }
852856 // If witness building is enabled, gather all the read-only accesses.
853857 // Skip witness collection in Verkle mode, they will be gathered
@@ -939,7 +943,7 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
939943 if op .isDelete () {
940944 deletedAddrs = append (deletedAddrs , addr )
941945 } else {
942- s .updateStateObject (s . stateObjects [addr ])
946+ s .updateStateObject (addr , stateObjectsResolve [addr ])
943947 s .AccountUpdated += 1
944948 }
945949 usedAddrs = append (usedAddrs , addr ) // Copy needed for closure
0 commit comments