From 0b748efc5c1d415ceea297611c802ff219957719 Mon Sep 17 00:00:00 2001 From: Hao Duan Date: Tue, 2 Jun 2020 19:06:50 +0800 Subject: [PATCH 1/2] 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/tx_pool.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/tx_pool.go b/core/tx_pool.go index 3dbccdfe9489..d45f5c772420 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -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() @@ -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) } From ad8bb1092baf15ebcf4dc52c00d0a446d1f81d35 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 4 Aug 2020 11:27:37 +0200 Subject: [PATCH 2/2] core: fix flatten condition + comment --- core/tx_pool.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/tx_pool.go b/core/tx_pool.go index d45f5c772420..63e405d10e1e 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -1023,8 +1023,10 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt defer close(done) var promoteAddrs []common.Address - if dirtyAccounts != nil && reset != nil { - // flatten dirty accounts to promote if any. + if dirtyAccounts != nil && reset == nil { + // Only dirty accounts need to be promoted, unless we're resetting. + // For resets, all addresses in the tx queue will be promoted and + // the flatten operation can be avoided. promoteAddrs = dirtyAccounts.flatten() } pool.mu.Lock()