@@ -567,7 +567,18 @@ 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 (addr common.Address , resolver func () * types.StateAccount ) {
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 )
577+ }
578+ }
579+
580+ // updateStateObject writes the given object to the trie.
581+ func (s * StateDB ) updateStateObjectAsync (addr common.Address , resolver func () * types.StateAccount ) {
571582 if err := s .trie .UpdateAccountAsync (addr , resolver ); err != nil {
572583 s .setError (fmt .Errorf ("updateStateObject (%x) error: %v" , addr , err ))
573584 }
@@ -942,7 +953,11 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
942953 if op .isDelete () {
943954 deletedAddrs = append (deletedAddrs , addr )
944955 } else {
945- s .updateStateObject (addr , stateObjectsResolve [addr ])
956+ if s .db .TrieDB ().IsVerkle () {
957+ s .updateStateObject (s .stateObjects [addr ])
958+ } else {
959+ s .updateStateObjectAsync (addr , stateObjectsResolve [addr ])
960+ }
946961 s .AccountUpdated += 1
947962 }
948963 usedAddrs = append (usedAddrs , addr ) // Copy needed for closure
0 commit comments