From 5e331836f3311af40f400951733666f577955678 Mon Sep 17 00:00:00 2001 From: Evgeny Danienko <6655321@bk.ru> Date: Fri, 27 Jan 2023 11:43:50 +0400 Subject: [PATCH 1/2] add check --- core/tx_list.go | 8 ++++++-- core/tx_pool.go | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/tx_list.go b/core/tx_list.go index e763777e33..fea4434b9b 100644 --- a/core/tx_list.go +++ b/core/tx_list.go @@ -351,9 +351,8 @@ func (m *txSortedMap) lastElement() *types.Transaction { m.cacheMu.Unlock() - cache = make(types.Transactions, 0, len(m.items)) - m.m.RLock() + cache = make(types.Transactions, 0, len(m.items)) for _, tx := range m.items { cache = append(cache, tx) @@ -373,6 +372,11 @@ func (m *txSortedMap) lastElement() *types.Transaction { hitCacheCounter.Inc(1) } + ln := len(cache) + if ln == 0 { + return nil + } + return cache[len(cache)-1] } diff --git a/core/tx_pool.go b/core/tx_pool.go index e98fd2e0ae..8b03dc2a23 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -1573,7 +1573,9 @@ func (pool *TxPool) runReorg(ctx context.Context, done chan struct{}, reset *txp tracing.ElapsedTime(ctx, innerSpan, "09 fill nonces", func(_ context.Context, innerSpan trace.Span) { for addr, list := range pool.pending { highestPending = list.LastElement() - nonces[addr] = highestPending.Nonce() + 1 + if highestPending != nil { + nonces[addr] = highestPending.Nonce() + 1 + } } }) From d3796630815f4361b22287903542660263e0c2a4 Mon Sep 17 00:00:00 2001 From: Evgeny Danienko <6655321@bk.ru> Date: Mon, 6 Feb 2023 08:12:34 +0400 Subject: [PATCH 2/2] linters --- core/tx_pool.go | 1 + 1 file changed, 1 insertion(+) diff --git a/core/tx_pool.go b/core/tx_pool.go index 8b03dc2a23..a3a10e7023 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -1539,6 +1539,7 @@ func (pool *TxPool) runReorg(ctx context.Context, done chan struct{}, reset *txp // remove any transaction that has been included in the block or was invalidated // because of another transaction (e.g. higher gas price). + //nolint:nestif if reset != nil { tracing.ElapsedTime(ctx, span, "new block", func(_ context.Context, innerSpan trace.Span) {