From 6fcebbfd007e3fc452e5d22efe9e8079f2189fd0 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Thu, 23 Apr 2026 15:36:09 +0800 Subject: [PATCH] core: replace the read list with block access list --- core/state/state_object.go | 2 +- core/state/statedb.go | 10 ++-- core/state/statedb_hooked.go | 2 +- core/types/bal/access_list.go | 94 ----------------------------------- core/types/bal/bal.go | 6 +-- core/vm/interface.go | 2 +- 6 files changed, 11 insertions(+), 105 deletions(-) delete mode 100644 core/types/bal/access_list.go diff --git a/core/state/state_object.go b/core/state/state_object.go index 8e72486825..db03c09e41 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -184,7 +184,7 @@ func (s *stateObject) getState(key common.Hash) (common.Hash, common.Hash) { // without any mutations caused in the current execution. func (s *stateObject) GetCommittedState(key common.Hash) common.Hash { // 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 value, pending := s.pendingStorage[key]; pending { diff --git a/core/state/statedb.go b/core/state/statedb.go index 806193be99..aacd926ba4 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -128,7 +128,7 @@ type StateDB struct { accessEvents *AccessEvents // Per-transaction state access footprint for EIP-7928 - stateReadList *bal.StateAccessList + stateAccessList *bal.ConstructionBlockAccessList // Transient storage 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. func (s *StateDB) getStateObject(addr common.Address) *stateObject { // Record state access regardless of whether the account exists. - s.stateReadList.AddAccount(addr) + s.stateAccessList.AccountRead(addr) // Prefer live objects if any is available 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 // 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. -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)) for addr := range s.journal.mutations { 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. s.clearJournalAndRefund() - return s.stateReadList + return s.stateAccessList } // 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() if rules.IsAmsterdam { - s.stateReadList = bal.NewStateAccessList() + s.stateAccessList = bal.NewConstructionBlockAccessList() } } diff --git a/core/state/statedb_hooked.go b/core/state/statedb_hooked.go index 53da7a374e..f32e982b5f 100644 --- a/core/state/statedb_hooked.go +++ b/core/state/statedb_hooked.go @@ -234,7 +234,7 @@ func (s *hookedStateDB) LogsForBurnAccounts() []*types.Log { 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 { // Short circuit if no relevant hooks are set. return s.inner.Finalise(deleteEmptyObjects) diff --git a/core/types/bal/access_list.go b/core/types/bal/access_list.go deleted file mode 100644 index e563fa22e2..0000000000 --- a/core/types/bal/access_list.go +++ /dev/null @@ -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 - -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 -} diff --git a/core/types/bal/bal.go b/core/types/bal/bal.go index 99ead8d6f0..9cbc1faeb9 100644 --- a/core/types/bal/bal.go +++ b/core/types/bal/bal.go @@ -71,8 +71,8 @@ type ConstructionBlockAccessList struct { } // NewConstructionBlockAccessList instantiates an empty access list. -func NewConstructionBlockAccessList() ConstructionBlockAccessList { - return ConstructionBlockAccessList{ +func NewConstructionBlockAccessList() *ConstructionBlockAccessList { + return &ConstructionBlockAccessList{ Accounts: make(map[common.Address]*ConstructionAccountAccess), } } @@ -169,5 +169,5 @@ func (b *ConstructionBlockAccessList) Copy() *ConstructionBlockAccessList { aaCopy.CodeChange = codes res.Accounts[addr] = &aaCopy } - return &res + return res } diff --git a/core/vm/interface.go b/core/vm/interface.go index 487d8002f9..5619d98c53 100644 --- a/core/vm/interface.go +++ b/core/vm/interface.go @@ -98,5 +98,5 @@ type StateDB interface { AccessEvents() *state.AccessEvents // Finalise must be invoked at the end of a transaction - Finalise(bool) *bal.StateAccessList + Finalise(bool) *bal.ConstructionBlockAccessList }