Skip to content

Commit

Permalink
Merge pull request #69 from bladehan1/fix-check-empty
Browse files Browse the repository at this point in the history
add(txpool): add check for empty lists in txpool
  • Loading branch information
bladehan1 authored Mar 6, 2024
2 parents a87b672 + 2e00f25 commit b87e27e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/tx_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ func (m *txSortedMap) Flatten() types.Transactions {
// transaction with the highest nonce
func (m *txSortedMap) LastElement() *types.Transaction {
cache := m.flatten()
ln := len(cache)
if ln == 0 {
return nil
}
return cache[len(cache)-1]
}

Expand Down
3 changes: 3 additions & 0 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,9 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt
// Update all accounts to the latest known pending nonce
for addr, list := range pool.pending {
highestPending := list.LastElement()
if highestPending == nil {
continue
}
pool.pendingNonces.set(addr, highestPending.Nonce()+1)
}
dropBetweenReorgHistogram.Update(int64(pool.changesSinceReorg))
Expand Down

0 comments on commit b87e27e

Please sign in to comment.