core: replace the read list with block access list

This commit is contained in:
Gary Rong 2026-04-23 15:36:09 +08:00 committed by Jared Wasinger
parent 5b9a06d2f6
commit 6fcebbfd00
6 changed files with 11 additions and 105 deletions

View file

@ -184,7 +184,7 @@ func (s *stateObject) getState(key common.Hash) (common.Hash, common.Hash) {
// without any mutations caused in the current execution. // without any mutations caused in the current execution.
func (s *stateObject) GetCommittedState(key common.Hash) common.Hash { func (s *stateObject) GetCommittedState(key common.Hash) common.Hash {
// Record slot access regardless of whether the storage slot exists. // Record slot access regardless of whether the storage slot exists.
s.db.stateReadList.AddState(s.address, key) s.db.stateAccessList.StorageRead(s.address, key)
// If we have a pending write or clean cached, return that // If we have a pending write or clean cached, return that
if value, pending := s.pendingStorage[key]; pending { if value, pending := s.pendingStorage[key]; pending {

View file

@ -128,7 +128,7 @@ type StateDB struct {
accessEvents *AccessEvents accessEvents *AccessEvents
// Per-transaction state access footprint for EIP-7928 // Per-transaction state access footprint for EIP-7928
stateReadList *bal.StateAccessList stateAccessList *bal.ConstructionBlockAccessList
// Transient storage // Transient storage
transientStorage transientStorage transientStorage transientStorage
@ -589,7 +589,7 @@ func (s *StateDB) deleteStateObject(addr common.Address) {
// the object is not found or was deleted in this execution context. // the object is not found or was deleted in this execution context.
func (s *StateDB) getStateObject(addr common.Address) *stateObject { func (s *StateDB) getStateObject(addr common.Address) *stateObject {
// Record state access regardless of whether the account exists. // Record state access regardless of whether the account exists.
s.stateReadList.AddAccount(addr) s.stateAccessList.AccountRead(addr)
// Prefer live objects if any is available // Prefer live objects if any is available
if obj := s.stateObjects[addr]; obj != nil { if obj := s.stateObjects[addr]; obj != nil {
@ -799,7 +799,7 @@ func (s *StateDB) LogsForBurnAccounts() []*types.Log {
// Finalise finalises the state by removing the destructed objects and clears // Finalise finalises the state by removing the destructed objects and clears
// the journal as well as the refunds. Finalise, however, will not push any updates // the journal as well as the refunds. Finalise, however, will not push any updates
// into the tries just yet. Only IntermediateRoot or Commit will do that. // into the tries just yet. Only IntermediateRoot or Commit will do that.
func (s *StateDB) Finalise(deleteEmptyObjects bool) *bal.StateAccessList { func (s *StateDB) Finalise(deleteEmptyObjects bool) *bal.ConstructionBlockAccessList {
addressesToPrefetch := make([]common.Address, 0, len(s.journal.mutations)) addressesToPrefetch := make([]common.Address, 0, len(s.journal.mutations))
for addr := range s.journal.mutations { for addr := range s.journal.mutations {
obj, exist := s.stateObjects[addr] obj, exist := s.stateObjects[addr]
@ -839,7 +839,7 @@ func (s *StateDB) Finalise(deleteEmptyObjects bool) *bal.StateAccessList {
// Invalidate journal because reverting across transactions is not allowed. // Invalidate journal because reverting across transactions is not allowed.
s.clearJournalAndRefund() s.clearJournalAndRefund()
return s.stateReadList return s.stateAccessList
} }
// IntermediateRoot computes the current root hash of the state trie. // IntermediateRoot computes the current root hash of the state trie.
@ -1435,7 +1435,7 @@ func (s *StateDB) Prepare(rules params.Rules, sender, coinbase common.Address, d
s.transientStorage = newTransientStorage() s.transientStorage = newTransientStorage()
if rules.IsAmsterdam { if rules.IsAmsterdam {
s.stateReadList = bal.NewStateAccessList() s.stateAccessList = bal.NewConstructionBlockAccessList()
} }
} }

View file

@ -234,7 +234,7 @@ func (s *hookedStateDB) LogsForBurnAccounts() []*types.Log {
return s.inner.LogsForBurnAccounts() return s.inner.LogsForBurnAccounts()
} }
func (s *hookedStateDB) Finalise(deleteEmptyObjects bool) *bal.StateAccessList { func (s *hookedStateDB) Finalise(deleteEmptyObjects bool) *bal.ConstructionBlockAccessList {
if s.hooks.OnBalanceChange == nil && s.hooks.OnNonceChangeV2 == nil && s.hooks.OnNonceChange == nil && s.hooks.OnCodeChangeV2 == nil && s.hooks.OnCodeChange == nil { if s.hooks.OnBalanceChange == nil && s.hooks.OnNonceChangeV2 == nil && s.hooks.OnNonceChange == nil && s.hooks.OnCodeChangeV2 == nil && s.hooks.OnCodeChange == nil {
// Short circuit if no relevant hooks are set. // Short circuit if no relevant hooks are set.
return s.inner.Finalise(deleteEmptyObjects) return s.inner.Finalise(deleteEmptyObjects)

View file

@ -1,94 +0,0 @@
// Copyright 2026 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>
package bal
import (
"maps"
"github.com/ethereum/go-ethereum/common"
)
// StorageAccessList represents a set of storage slots accessed within an account.
type StorageAccessList map[common.Hash]struct{}
// StateAccessList records the set of accounts and storage slots that have been
// accessed. An entry with an empty StorageAccessList denotes an account access
// without any storage slot access.
type StateAccessList struct {
list map[common.Address]StorageAccessList
}
// NewStateAccessList returns an empty StateAccessList ready for use.
func NewStateAccessList() *StateAccessList {
return &StateAccessList{
list: make(map[common.Address]StorageAccessList),
}
}
// AddAccount records an access to the given account. It is a no-op if the
// account is already present.
func (s *StateAccessList) AddAccount(addr common.Address) {
if s == nil {
return
}
if _, exists := s.list[addr]; !exists {
s.list[addr] = make(StorageAccessList)
}
}
// AddState records an access to the given storage slot. The owning account is
// implicitly recorded as well.
func (s *StateAccessList) AddState(addr common.Address, slot common.Hash) {
if s == nil {
return
}
slots, exists := s.list[addr]
if !exists {
slots = make(StorageAccessList)
s.list[addr] = slots
}
slots[slot] = struct{}{}
}
// Merge merges the entries from other into the receiver.
func (s *StateAccessList) Merge(other *StateAccessList) {
if s == nil || other == nil {
return
}
for addr, otherSlots := range other.list {
slots, exists := s.list[addr]
if !exists {
s.list[addr] = otherSlots
continue
}
maps.Copy(slots, otherSlots)
}
}
// Copy returns a deep copy of the StateAccessList.
func (s *StateAccessList) Copy() *StateAccessList {
if s == nil {
return nil
}
cpy := &StateAccessList{
list: make(map[common.Address]StorageAccessList, len(s.list)),
}
for addr, slots := range s.list {
cpy.list[addr] = maps.Clone(slots)
}
return cpy
}

View file

@ -71,8 +71,8 @@ type ConstructionBlockAccessList struct {
} }
// NewConstructionBlockAccessList instantiates an empty access list. // NewConstructionBlockAccessList instantiates an empty access list.
func NewConstructionBlockAccessList() ConstructionBlockAccessList { func NewConstructionBlockAccessList() *ConstructionBlockAccessList {
return ConstructionBlockAccessList{ return &ConstructionBlockAccessList{
Accounts: make(map[common.Address]*ConstructionAccountAccess), Accounts: make(map[common.Address]*ConstructionAccountAccess),
} }
} }
@ -169,5 +169,5 @@ func (b *ConstructionBlockAccessList) Copy() *ConstructionBlockAccessList {
aaCopy.CodeChange = codes aaCopy.CodeChange = codes
res.Accounts[addr] = &aaCopy res.Accounts[addr] = &aaCopy
} }
return &res return res
} }

View file

@ -98,5 +98,5 @@ type StateDB interface {
AccessEvents() *state.AccessEvents AccessEvents() *state.AccessEvents
// Finalise must be invoked at the end of a transaction // Finalise must be invoked at the end of a transaction
Finalise(bool) *bal.StateAccessList Finalise(bool) *bal.ConstructionBlockAccessList
} }