Skip to content

Commit

Permalink
core: avoid modification of accountSet cache in tx_pool
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
duanhao0814 committed Jun 19, 2020
1 parent 5435e0d commit 0b748ef
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,8 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt
defer close(done)

var promoteAddrs []common.Address
if dirtyAccounts != nil {
if dirtyAccounts != nil && reset != nil {
// flatten dirty accounts to promote if any.
promoteAddrs = dirtyAccounts.flatten()
}
pool.mu.Lock()
Expand All @@ -1039,7 +1040,7 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt
}
}
// Reset needs promote for all addresses
promoteAddrs = promoteAddrs[:0]
promoteAddrs = make([]common.Address, 0, len(pool.queue))
for addr := range pool.queue {
promoteAddrs = append(promoteAddrs, addr)
}
Expand Down

0 comments on commit 0b748ef

Please sign in to comment.