Skip to content

Commit

Permalink
revert opt of reheap frequency; close async pricedlist when txpool is…
Browse files Browse the repository at this point in the history
… shutdown
  • Loading branch information
andyzhang2023 committed Dec 26, 2024
1 parent 428556d commit 77ece0b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion core/txpool/legacypool/async_priced_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (a *asyncPricedList) GetBaseFee() *big.Int {
return a.priced.floating.baseFee
}

func (a *asyncPricedList) Stop() {
func (a *asyncPricedList) Close() {
close(a.quit)
}

Expand Down
12 changes: 3 additions & 9 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ func (pool *LegacyPool) loop() {
defer evict.Stop()
defer journal.Stop()
defer reannounce.Stop()
defer pool.priced.Close()

// Notify tests that the init phase is done
close(pool.initDoneCh)
Expand Down Expand Up @@ -845,15 +846,6 @@ func (pool *LegacyPool) add(tx *types.Transaction, local bool) (replaced bool, e
}
// If the transaction pool is full, discard underpriced transactions
if uint64(pool.all.Slots()+numSlots(tx)) > pool.config.GlobalSlots+pool.config.GlobalQueue {
currHead := pool.currentHead.Load()
if currHead != nil && currHead.BaseFee != nil && pool.priced.NeedReheap(currHead) {
if pool.chainconfig.IsLondon(new(big.Int).Add(currHead.Number, big.NewInt(1))) {
baseFee := eip1559.CalcBaseFee(pool.chainconfig, currHead, currHead.Time+1)
pool.priced.SetBaseFee(baseFee)
}
pool.priced.Reheap()
}

// If the new transaction is underpriced, don't accept it
if !isLocal && pool.priced.Underpriced(tx) {
log.Trace("Discarding underpriced transaction", "hash", hash, "gasTipCap", tx.GasTipCap(), "gasFeeCap", tx.GasFeeCap())
Expand Down Expand Up @@ -1472,6 +1464,8 @@ func (pool *LegacyPool) runReorg(done chan struct{}, reset *txpoolResetRequest,
if pool.chainconfig.IsLondon(new(big.Int).Add(reset.newHead.Number, big.NewInt(1))) {
pendingBaseFee = eip1559.CalcBaseFee(pool.chainconfig, reset.newHead, reset.newHead.Time+1)
pool.priced.SetBaseFee(pendingBaseFee)
} else {
pool.priced.Reheap()
}
}
gasTip, baseFee := pool.gasTip.Load(), pendingBaseFee
Expand Down
1 change: 0 additions & 1 deletion core/txpool/legacypool/legacypool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2304,7 +2304,6 @@ func TestDualHeapEviction(t *testing.T) {
add(false)
for baseFee = 0; baseFee <= 1000; baseFee += 100 {
pool.priced.SetBaseFee(big.NewInt(int64(baseFee)))
pool.priced.Reheap()
add(true)
check(highCap, "fee cap")
add(false)
Expand Down
12 changes: 6 additions & 6 deletions core/txpool/legacypool/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,12 @@ type pricedListInterface interface {
Removed(count int)
Underpriced(tx *types.Transaction) bool
Discard(slots int, force bool) (types.Transactions, bool)
NeedReheap(currHead *types.Header) bool
Reheap()
SetBaseFee(baseFee *big.Int)
GetBaseFee() *big.Int
Staled() int
TxCount() int
Close()
}

// pricedList is a price-sorted heap to allow operating on transactions pool
Expand All @@ -564,7 +564,6 @@ type pricedListInterface interface {
// better candidates for inclusion while in other cases (at the top of the baseFee peak)
// the floating heap is better. When baseFee is decreasing they behave similarly.
type pricedList struct {
currHead *types.Header // Current block header for effective tip calculation
// Number of stale price points to (re-heap trigger).
stales atomic.Int64

Expand Down Expand Up @@ -687,10 +686,6 @@ func (l *pricedList) Discard(slots int, force bool) (types.Transactions, bool) {
return drop, true
}

func (l *pricedList) NeedReheap(currHead *types.Header) bool {
return l.currHead == nil || currHead == nil || currHead.Hash().Cmp(l.currHead.Hash()) != 0
}

// Reheap forcibly rebuilds the heap based on the current remote transaction set.
func (l *pricedList) Reheap() {
l.reheapMu.Lock()
Expand Down Expand Up @@ -722,6 +717,7 @@ func (l *pricedList) Reheap() {
// necessary to call right before SetBaseFee when processing a new block.
func (l *pricedList) SetBaseFee(baseFee *big.Int) {
l.urgent.baseFee = baseFee
l.Reheap()
}

// GetBaseFee returns the current base fee used for sorting the urgent heap.
Expand All @@ -732,3 +728,7 @@ func (l *pricedList) GetBaseFee() *big.Int {
func (l *pricedList) TxCount() int {
return len(l.urgent.list) + len(l.floating.list)
}

func (l *pricedList) Close() {
//do nothing
}

0 comments on commit 77ece0b

Please sign in to comment.