From 2df9cc323a322cdad95ae20542e64a9cac8ede5e Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Tue, 10 Mar 2026 17:51:21 +0800 Subject: [PATCH] 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'. --- core/txpool/legacypool/legacypool.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 36970c820e..f6ec6739cc 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -1595,7 +1595,7 @@ func (pool *LegacyPool) demoteUnexecutables() { type accountSet struct { accounts map[common.Address]struct{} signer types.Signer - cache []common.Address + cache *[]common.Address } // 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! func (as *accountSet) flatten() []common.Address { 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'.