Skip to content

Commit

Permalink
common: do not pass current time as param in priority funcs (ethereum…
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Dec 26, 2024
1 parent f9ee15f commit d97aafd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions common/prque/lazyqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type LazyQueue struct {
}

type (
PriorityCallback func(data interface{}, now mclock.AbsTime) int64 // actual priority callback
PriorityCallback func(data interface{}) int64 // actual priority callback
MaxPriorityCallback func(data interface{}, until mclock.AbsTime) int64 // estimated maximum priority callback
)

Expand Down Expand Up @@ -140,11 +140,10 @@ func (q *LazyQueue) peekIndex() int {
// Pop multiple times. Popped items are passed to the callback. MultiPop returns
// when the callback returns false or there are no more items to pop.
func (q *LazyQueue) MultiPop(callback func(data interface{}, priority int64) bool) {
now := q.clock.Now()
nextIndex := q.peekIndex()
for nextIndex != -1 {
data := heap.Pop(q.queue[nextIndex]).(*item).value
heap.Push(q.popQueue, &item{data, q.priority(data, now)})
heap.Push(q.popQueue, &item{data, q.priority(data)})
nextIndex = q.peekIndex()
for q.popQueue.Len() != 0 && (nextIndex == -1 || q.queue[nextIndex].blocks[0][0].priority < q.popQueue.blocks[0][0].priority) {
i := heap.Pop(q.popQueue).(*item)
Expand Down
3 changes: 1 addition & 2 deletions common/prque/lazyqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type lazyItem struct {
index int
}

func testPriority(a interface{}, now mclock.AbsTime) int64 {
func testPriority(a interface{}) int64 {
return a.(*lazyItem).p
}

Expand All @@ -56,7 +56,6 @@ func testSetIndex(a interface{}, i int) {
}

func TestLazyQueue(t *testing.T) {
rand.Seed(time.Now().UnixNano())
clock := &mclock.Simulated{}
q := NewLazyQueue(testSetIndex, testPriority, testMaxPriority, clock, testQueueRefresh)

Expand Down

0 comments on commit d97aafd

Please sign in to comment.