Skip to content

Commit b35e4fc

Browse files
duanhao0814fjl
andauthored
core: avoid modification of accountSet cache in tx_pool (#21159)
* core: avoid modification of accountSet cache in tx_pool when runReorg, we may copy the dirtyAccounts' accountSet cache to promoteAddrs in which accounts will be promoted, however, if we have reset request at the same time, we may reuse promoteAddrs and modify the cache content which is against the original intention of accountSet cache. So, we need to make a new slice here to avoid modify accountSet cache. * core: fix flatten condition + comment Co-authored-by: Felix Lange <[email protected]>
1 parent e24e05d commit b35e4fc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

core/tx_pool.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,10 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt
10321032
defer close(done)
10331033

10341034
var promoteAddrs []common.Address
1035-
if dirtyAccounts != nil {
1035+
if dirtyAccounts != nil && reset == nil {
1036+
// Only dirty accounts need to be promoted, unless we're resetting.
1037+
// For resets, all addresses in the tx queue will be promoted and
1038+
// the flatten operation can be avoided.
10361039
promoteAddrs = dirtyAccounts.flatten()
10371040
}
10381041
pool.mu.Lock()
@@ -1048,7 +1051,7 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt
10481051
}
10491052
}
10501053
// Reset needs promote for all addresses
1051-
promoteAddrs = promoteAddrs[:0]
1054+
promoteAddrs = make([]common.Address, 0, len(pool.queue))
10521055
for addr := range pool.queue {
10531056
promoteAddrs = append(promoteAddrs, addr)
10541057
}

0 commit comments

Comments
 (0)