core/state: fix resurrection state clearing and access
This commit is contained in:
		@@ -204,6 +204,15 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
 | 
				
			|||||||
		if metrics.EnabledExpensive {
 | 
							if metrics.EnabledExpensive {
 | 
				
			||||||
			defer func(start time.Time) { s.db.SnapshotStorageReads += time.Since(start) }(time.Now())
 | 
								defer func(start time.Time) { s.db.SnapshotStorageReads += time.Since(start) }(time.Now())
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							// If the object was destructed in *this* block (and potentially resurrected),
 | 
				
			||||||
 | 
							// the storage has been cleared out, and we should *not* consult the previous
 | 
				
			||||||
 | 
							// snapshot about any storage values. The only possible alternatives are:
 | 
				
			||||||
 | 
							//   1) resurrect happened, and new slot values were set -- those should
 | 
				
			||||||
 | 
							//      have been handles via pendingStorage above.
 | 
				
			||||||
 | 
							//   2) we don't have new values, and can deliver empty response back
 | 
				
			||||||
 | 
							if _, destructed := s.db.snapDestructs[s.addrHash]; destructed {
 | 
				
			||||||
 | 
								return common.Hash{}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		enc, err = s.db.snap.Storage(s.addrHash, crypto.Keccak256Hash(key[:]))
 | 
							enc, err = s.db.snap.Storage(s.addrHash, crypto.Keccak256Hash(key[:]))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// If snapshot unavailable or reading from it failed, load from the database
 | 
						// If snapshot unavailable or reading from it failed, load from the database
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -595,6 +595,9 @@ func (s *StateDB) CreateAccount(addr common.Address) {
 | 
				
			|||||||
	if prev != nil {
 | 
						if prev != nil {
 | 
				
			||||||
		newObj.setBalance(prev.data.Balance)
 | 
							newObj.setBalance(prev.data.Balance)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if s.snap != nil && prev != nil {
 | 
				
			||||||
 | 
							s.snapDestructs[prev.addrHash] = struct{}{}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (db *StateDB) ForEachStorage(addr common.Address, cb func(key, value common.Hash) bool) error {
 | 
					func (db *StateDB) ForEachStorage(addr common.Address, cb func(key, value common.Hash) bool) error {
 | 
				
			||||||
@@ -855,7 +858,7 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) {
 | 
				
			|||||||
				log.Warn("Failed to cap snapshot tree", "root", root, "layers", 127, "err", err)
 | 
									log.Warn("Failed to cap snapshot tree", "root", root, "layers", 127, "err", err)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		s.snap, s.snapAccounts, s.snapStorage = nil, nil, nil
 | 
							s.snap, s.snapDestructs, s.snapAccounts, s.snapStorage = nil, nil, nil, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return root, err
 | 
						return root, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user