@@ -291,10 +291,13 @@ func (s *stateObject) finalise() {
291291}
292292
293293// updateTrie writes cached storage modifications into the object's storage trie.
294+ // It will return nil if the trie has not been loaded and no changes have been made
294295func (s * stateObject ) updateTrie (db Database ) Trie {
295296 // Make sure all dirty slots are finalized into the pending storage area
296297 s .finalise ()
297-
298+ if len (s .pendingStorage ) == 0 {
299+ return s .trie
300+ }
298301 // Track the amount of time wasted on updating the storage trie
299302 defer func (start time.Time ) { s .db .StorageUpdates += time .Since (start ) }(time .Now ())
300303 // Insert all the pending updates into the trie
@@ -322,8 +325,10 @@ func (s *stateObject) updateTrie(db Database) Trie {
322325
323326// UpdateRoot sets the trie root to the current root hash of
324327func (s * stateObject ) updateRoot (db Database ) {
325- s .updateTrie (db )
326-
328+ // If nothing changed, don't bother with hashing anything
329+ if s .updateTrie (db ) == nil {
330+ return
331+ }
327332 // Track the amount of time wasted on hashing the storage trie
328333 defer func (start time.Time ) { s .db .StorageHashes += time .Since (start ) }(time .Now ())
329334
@@ -333,7 +338,10 @@ func (s *stateObject) updateRoot(db Database) {
333338// CommitTrie the storage trie of the object to dwb.
334339// This updates the trie root.
335340func (s * stateObject ) CommitTrie (db Database ) error {
336- s .updateTrie (db )
341+ // If nothing changed, don't bother with hashing anything
342+ if s .updateTrie (db ) == nil {
343+ return nil
344+ }
337345 if s .dbErr != nil {
338346 return s .dbErr
339347 }
0 commit comments