Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check for empty lists in txpool #704

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions core/tx_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
}

Expand Down
5 changes: 4 additions & 1 deletion core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -1573,7 +1574,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
}
}
})

Expand Down