bnb-chain / op-geth

GNU Lesser General Public License v3.0
58 stars 47 forks source link

optimization: txpool pricedlist only reheap when pool is full #175

Closed andyzhang2023 closed 1 month ago

andyzhang2023 commented 2 months ago

Description

The pricedlist LegacyTxpool.priced is used to evict transactions when the pool overflows. It sorts all remote pending transactions by nonce and price and decides which transaction to stay and which to remove. It only works when the pool is full, but re-heap every second when the state of the pool changes.. The cost of re-heap is hight because it re-sorts all the pending transactions.

This improvement changes it to "only re-heap when the pool overflows", so that:

  1. LegacyTxpool.runReorg() cost less time to update the whole state of the pool.
  2. LegacyTxpool.Add() can be called more because it shares the mu.Lock with LegacyTxpool.runReorg()
  3. some other calls who share the mu.Lock too will get lower latency just as the LegacyTxpool.Add() does.

All of these will support higher TPS on the pool.