eth/tracers/logger: fix exclude address list

addSlot will add address to list.
So needs right way to exclude.
This commit is contained in:
Weixie Cui 2026-05-06 19:58:55 +08:00
parent aaa2b66285
commit bf68e31af3
2 changed files with 42 additions and 2 deletions

View file

@ -112,9 +112,10 @@ type AccessListTracer struct {
func NewAccessListTracer(acl types.AccessList, addressesToExclude map[common.Address]struct{}) *AccessListTracer { func NewAccessListTracer(acl types.AccessList, addressesToExclude map[common.Address]struct{}) *AccessListTracer {
list := newAccessList() list := newAccessList()
for _, al := range acl { for _, al := range acl {
if _, ok := addressesToExclude[al.Address]; !ok { if _, ok := addressesToExclude[al.Address]; ok {
list.addAddress(al.Address) continue
} }
list.addAddress(al.Address)
for _, slot := range al.StorageKeys { for _, slot := range al.StorageKeys {
list.addSlot(al.Address, slot) list.addSlot(al.Address, slot)
} }

View file

@ -0,0 +1,39 @@
// 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 logger
import (
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
func TestNewAccessListTracer_ExcludedAddress(t *testing.T) {
excluded := common.HexToAddress("0x2222222222222222222222222222222222222222")
slot := common.HexToHash("0x01")
prelude := types.AccessList{{
Address: excluded,
StorageKeys: []common.Hash{slot},
}}
excl := map[common.Address]struct{}{excluded: {}}
tracer := NewAccessListTracer(prelude, excl)
got := tracer.AccessList()
if len(got) != 0 {
t.Fatalf("excluded prelude address must not contribute tuples, got %+v", got)
}
}