@@ -579,7 +579,7 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
579579
580580// updateStateObject writes the given object to the trie. The actual value is
581581// only resolved from the provided function when it is needed during trie hashing.
582- func (s * StateDB ) updateStateObjectAsync (addr common.Address , resolver func () * types.StateAccount ) {
582+ func (s * StateDB ) updateStateObjectAsync (addr common.Address , resolver func () ( * types.StateAccount , int ) ) {
583583 if err := s .trie .UpdateAccountAsync (addr , resolver ); err != nil {
584584 s .setError (fmt .Errorf ("updateStateObject (%x) error: %v" , addr , err ))
585585 }
@@ -838,13 +838,17 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
838838 workers .SetLimit (1 )
839839 }
840840
841- stateObjectsResolve := make (map [common.Address ]func () * types.StateAccount )
841+ type stateAccountWithCodeLen struct {
842+ * types.StateAccount
843+ codeLen int
844+ }
845+ stateObjectsResolve := make (map [common.Address ]func () (* types.StateAccount , int ))
842846 for addr , op := range s .mutations {
843847 if op .applied || op .isDelete () {
844848 continue
845849 }
846850 obj := s .stateObjects [addr ] // closure for the task runner below
847- complete := make (chan * types. StateAccount )
851+ complete := make (chan stateAccountWithCodeLen )
848852 workers .Go (func () error {
849853 if s .db .TrieDB ().IsVerkle () {
850854 obj .updateTrie ()
@@ -857,12 +861,13 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
857861 s .witness .AddState (obj .trie .Witness ())
858862 }
859863 }
860- complete <- & obj .data
864+ complete <- stateAccountWithCodeLen { & obj .data , 0 }
861865 return nil
862866 })
863867
864- stateObjectsResolve [addr ] = func () * types.StateAccount {
865- return <- complete
868+ stateObjectsResolve [addr ] = func () (* types.StateAccount , int ) {
869+ res := <- complete
870+ return res .StateAccount , res .codeLen
866871 }
867872 }
868873 // If witness building is enabled, gather all the read-only accesses.
@@ -914,6 +919,7 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
914919 }
915920 }
916921 }
922+
917923 s .StorageUpdates += time .Since (start )
918924
919925 // Now we're about to start to write changes to the trie. The trie is so far
@@ -954,11 +960,7 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
954960 if op .isDelete () {
955961 deletedAddrs = append (deletedAddrs , addr )
956962 } else {
957- if s .db .TrieDB ().IsVerkle () {
958- s .updateStateObject (s .stateObjects [addr ])
959- } else {
960- s .updateStateObjectAsync (addr , stateObjectsResolve [addr ])
961- }
963+ s .updateStateObjectAsync (addr , stateObjectsResolve [addr ])
962964 s .AccountUpdated += 1
963965 }
964966 usedAddrs = append (usedAddrs , addr ) // Copy needed for closure
0 commit comments