Skip to content

Commit

Permalink
gracefully shutdown when the async priced list is closed (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: andyzhang2023 <andyzhang2023@gmail.com>
  • Loading branch information
andyzhang2023 and andyzhang2023 authored Jan 17, 2025
1 parent cf82d72 commit 83e173e
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions core/txpool/legacypool/async_priced_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func (a *asyncPricedList) run() {
toRemove += remove

case baseFee = <-a.setBaseFee:
// always reheap after setting base fee
reheap = true

case <-currentDone:
currentDone = nil
Expand Down Expand Up @@ -124,11 +126,17 @@ func (a *asyncPricedList) Staled() int {
}

func (a *asyncPricedList) Put(tx *types.Transaction, local bool) {
a.add <- &addEvent{tx, local}
select {
case a.add <- &addEvent{tx, local}:
case <-a.quit:
}
}

func (a *asyncPricedList) Removed(count int) {
a.remove <- count
select {
case a.remove <- count:
case <-a.quit:
}
}

func (a *asyncPricedList) Underpriced(tx *types.Transaction) bool {
Expand Down Expand Up @@ -161,12 +169,17 @@ func (a *asyncPricedList) NeedReheap(currHead *types.Header) bool {
}

func (a *asyncPricedList) Reheap() {
a.reheap <- struct{}{}
select {
case a.reheap <- struct{}{}:
case <-a.quit:
}
}

func (a *asyncPricedList) SetBaseFee(baseFee *big.Int) {
a.setBaseFee <- baseFee
a.reheap <- struct{}{}
select {
case a.setBaseFee <- baseFee:
case <-a.quit:
}
}

func (a *asyncPricedList) SetHead(currHead *types.Header) {
Expand Down

0 comments on commit 83e173e

Please sign in to comment.