@@ -27,6 +27,7 @@ import (
2727 "github.com/ethereum/go-ethereum/core/tracing"
2828 "github.com/ethereum/go-ethereum/core/types"
2929 "github.com/ethereum/go-ethereum/crypto"
30+ "github.com/ethereum/go-ethereum/log"
3031 "github.com/ethereum/go-ethereum/rlp"
3132 "github.com/ethereum/go-ethereum/trie/trienode"
3233 "github.com/holiman/uint256"
@@ -255,9 +256,16 @@ func (s *stateObject) setState(key common.Hash, value *common.Hash) {
255256func (s * stateObject ) finalise (prefetch bool ) {
256257 slotsToPrefetch := make ([][]byte , 0 , len (s .dirtyStorage ))
257258 for key , value := range s .dirtyStorage {
258- s .pendingStorage [key ] = value
259+ // If the slot is different from its original value, move it into the
260+ // pending area to be committed at the end of the block (and prefetch
261+ // the pathways).
259262 if value != s .originStorage [key ] {
263+ s .pendingStorage [key ] = value
260264 slotsToPrefetch = append (slotsToPrefetch , common .CopyBytes (key [:])) // Copy needed for closure
265+ } else {
266+ // Otherwise, the slot was reverted to its original value, remove it
267+ // from the pending area to avoid thrashing the data strutures.
268+ delete (s .pendingStorage , key )
261269 }
262270 }
263271 if s .db .prefetcher != nil && prefetch && len (slotsToPrefetch ) > 0 && s .data .Root != types .EmptyRootHash {
@@ -371,6 +379,11 @@ func (s *stateObject) updateTrie() (Trie, error) {
371379 }
372380 s .db .StorageDeleted += 1
373381 }
382+ // If no slots were touched, issue a warning as we shouldn't have done all
383+ // the above work in the first place
384+ if len (usedStorage ) == 0 {
385+ log .Error ("State object update was noop" , "addr" , s .address , "slots" , len (s .pendingStorage ))
386+ }
374387 if s .db .prefetcher != nil {
375388 s .db .prefetcher .used (s .addrHash , s .data .Root , usedStorage )
376389 }
0 commit comments