Skip to content

Commit c46aae2

Browse files
authored
add check for empty lists in txpool (ethereum#704)
* add check * linters
1 parent a4f1ac1 commit c46aae2

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

core/tx_list.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,8 @@ func (m *txSortedMap) lastElement() *types.Transaction {
351351

352352
m.cacheMu.Unlock()
353353

354-
cache = make(types.Transactions, 0, len(m.items))
355-
356354
m.m.RLock()
355+
cache = make(types.Transactions, 0, len(m.items))
357356

358357
for _, tx := range m.items {
359358
cache = append(cache, tx)
@@ -373,6 +372,11 @@ func (m *txSortedMap) lastElement() *types.Transaction {
373372
hitCacheCounter.Inc(1)
374373
}
375374

375+
ln := len(cache)
376+
if ln == 0 {
377+
return nil
378+
}
379+
376380
return cache[len(cache)-1]
377381
}
378382

core/tx_pool.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,7 @@ func (pool *TxPool) runReorg(ctx context.Context, done chan struct{}, reset *txp
15391539
// remove any transaction that has been included in the block or was invalidated
15401540
// because of another transaction (e.g. higher gas price).
15411541

1542+
//nolint:nestif
15421543
if reset != nil {
15431544
tracing.ElapsedTime(ctx, span, "new block", func(_ context.Context, innerSpan trace.Span) {
15441545

@@ -1573,7 +1574,9 @@ func (pool *TxPool) runReorg(ctx context.Context, done chan struct{}, reset *txp
15731574
tracing.ElapsedTime(ctx, innerSpan, "09 fill nonces", func(_ context.Context, innerSpan trace.Span) {
15741575
for addr, list := range pool.pending {
15751576
highestPending = list.LastElement()
1576-
nonces[addr] = highestPending.Nonce() + 1
1577+
if highestPending != nil {
1578+
nonces[addr] = highestPending.Nonce() + 1
1579+
}
15771580
}
15781581
})
15791582

0 commit comments

Comments
 (0)