java-topology/defects/go-ethereum/patch/go-ethereum-0001-txpool-auths-map.patch

77 lines
2.3 KiB
Diff

# UNDF: UNDF-2026-000000082
# UNDF: (pending assignment)
--- a/core/txpool/legacypool/legacypool.go
+++ b/core/txpool/legacypool/legacypool.go
@@ -1649,7 +1649,7 @@ type lookup struct {
slots int
lock sync.RWMutex
txs map[common.Hash]*types.Transaction
- auths map[common.Address][]common.Hash // All accounts with a pooled authorization
+ auths map[common.Address]map[common.Hash]struct{} // All accounts with a pooled authorization
}
// newLookup returns a new lookup structure.
@@ -1658,7 +1658,7 @@ func newLookup() *lookup {
return &lookup{
txs: make(map[common.Hash]*types.Transaction),
- auths: make(map[common.Address][]common.Hash),
+ auths: make(map[common.Address]map[common.Hash]struct{}),
}
}
@@ -1737,7 +1737,7 @@ func (t *lookup) Clear() {
t.slots = 0
t.txs = make(map[common.Hash]*types.Transaction)
- t.auths = make(map[common.Address][]common.Hash)
+ t.auths = make(map[common.Address]map[common.Hash]struct{})
}
// addAuthorities tracks the supplied tx in relation to each authority it
@@ -1756,13 +1756,12 @@ func (t *lookup) addAuthorities(tx *types.Transaction) {
for _, addr := range tx.SetCodeAuthorities() {
- list, ok := t.auths[addr]
- if !ok {
- list = []common.Hash{}
- }
- if slices.Contains(list, tx.Hash()) {
- // Don't add duplicates.
+ set, ok := t.auths[addr]
+ if !ok {
+ set = make(map[common.Hash]struct{})
+ t.auths[addr] = set
+ }
+ if _, dup := set[tx.Hash()]; dup {
+ // Don't add duplicates.
continue
}
- list = append(list, tx.Hash())
- t.auths[addr] = list
+ set[tx.Hash()] = struct{}{}
}
}
@@ -1773,16 +1772,14 @@ func (t *lookup) removeAuthorities(tx *types.Transaction) {
hash := tx.Hash()
for _, addr := range tx.SetCodeAuthorities() {
- list := t.auths[addr]
- // Remove tx from tracker.
- if i := slices.Index(list, hash); i >= 0 {
- list = append(list[:i], list[i+1:]...)
- } else {
+ set := t.auths[addr]
+ // Remove tx from tracker.
+ if _, ok := set[hash]; ok {
+ delete(set, hash)
+ } else {
log.Error("Authority with untracked tx", "addr", addr, "hash", hash)
}
- if len(list) == 0 {
- // If list is newly empty, delete it entirely.
+ if len(set) == 0 {
+ // If set is newly empty, delete it entirely.
delete(t.auths, addr)
continue
}
- t.auths[addr] = list
}
}