mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-08 05:54:29 +00:00
core/txpool/legacypool: fix empty cache sentinel
Restore pointer-based cache sentinel in accountSet to preserve cached-empty state. With slices.Collect(maps.Keys(emptyMap)), the returned slice can be nil. Using []common.Address directly makes as.cache == nil true after flatten() on an empty set, causing repeated recomputation. Switching cache back to *[]common.Address keeps 'cache initialized' distinct from 'cached value is nil/empty'.
This commit is contained in:
parent
91cec92bf3
commit
2df9cc323a
1 changed files with 4 additions and 3 deletions
|
|
@ -1595,7 +1595,7 @@ func (pool *LegacyPool) demoteUnexecutables() {
|
||||||
type accountSet struct {
|
type accountSet struct {
|
||||||
accounts map[common.Address]struct{}
|
accounts map[common.Address]struct{}
|
||||||
signer types.Signer
|
signer types.Signer
|
||||||
cache []common.Address
|
cache *[]common.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
// newAccountSet creates a new address set with an associated signer for sender
|
// newAccountSet creates a new address set with an associated signer for sender
|
||||||
|
|
@ -1628,9 +1628,10 @@ func (as *accountSet) addTx(tx *types.Transaction) {
|
||||||
// reuse. The returned slice should not be changed!
|
// reuse. The returned slice should not be changed!
|
||||||
func (as *accountSet) flatten() []common.Address {
|
func (as *accountSet) flatten() []common.Address {
|
||||||
if as.cache == nil {
|
if as.cache == nil {
|
||||||
as.cache = slices.Collect(maps.Keys(as.accounts))
|
accounts := slices.Collect(maps.Keys(as.accounts))
|
||||||
|
as.cache = &accounts
|
||||||
}
|
}
|
||||||
return as.cache
|
return *as.cache
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge adds all addresses from the 'other' set into 'as'.
|
// merge adds all addresses from the 'other' set into 'as'.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue