core/state: short-circuit GetCommittedState for nil origin accounts

When the account has never been persisted (origin is nil) and was not
destructed in the current block, all storage slots are implicitly empty.
Return early and cache the negative result to avoid unnecessary trie
lookups for newly created contracts.
This commit is contained in:
CPerezz 2026-03-16 23:56:25 +01:00
parent 98b13f342f
commit baf1994f8b
No known key found for this signature in database
GPG key ID: 62045F34B97177DD

View file

@ -188,6 +188,15 @@ func (s *stateObject) GetCommittedState(key common.Hash) common.Hash {
if value, cached := s.originStorage[key]; cached {
return value
}
// If the account has no on-disk origin and was not destructed in this
// block (which requires the reader call for the access list), all
// storage slots are empty.
if s.origin == nil {
if _, destructed := s.db.stateObjectsDestruct[s.address]; !destructed {
s.originStorage[key] = common.Hash{}
return common.Hash{}
}
}
// If the object was destructed in *this* block (and potentially resurrected),
// the storage has been cleared out, and we should *not* consult the previous
// database about any storage values. The only possible alternatives are: