Skip to content

Commit

Permalink
all: use AbsTime.Add instead of conversion (ethereum#25417)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbadoy authored and blakehhuynh committed Oct 3, 2022
1 parent fba0d59 commit 120e58d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions common/mclock/simclock.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *Simulated) Run(d time.Duration) {
s.mu.Lock()
s.init()

end := s.now + AbsTime(d)
end := s.now.Add(d)
var do []func()
for len(s.scheduled) > 0 && s.scheduled[0].at <= end {
ev := heap.Pop(&s.scheduled).(*simTimer)
Expand Down Expand Up @@ -134,7 +134,7 @@ func (s *Simulated) AfterFunc(d time.Duration, fn func()) Timer {
func (s *Simulated) schedule(d time.Duration, fn func()) *simTimer {
s.init()

at := s.now + AbsTime(d)
at := s.now.Add(d)
ev := &simTimer{do: fn, at: at, s: s}
heap.Push(&s.scheduled, ev)
s.cond.Broadcast()
Expand Down
4 changes: 2 additions & 2 deletions common/prque/lazyqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func (q *LazyQueue) Refresh() {

// refresh re-evaluates items in the older queue and swaps the two queues
func (q *LazyQueue) refresh(now mclock.AbsTime) {
q.maxUntil = now + mclock.AbsTime(q.period)
q.maxUntil = now.Add(q.period)
for q.queue[0].Len() != 0 {
q.Push(heap.Pop(q.queue[0]).(*item).value)
}
q.queue[0], q.queue[1] = q.queue[1], q.queue[0]
q.indexOffset = 1 - q.indexOffset
q.maxUntil += mclock.AbsTime(q.period)
q.maxUntil = q.maxUntil.Add(q.period)
}

// Push adds an item to the queue
Expand Down
2 changes: 1 addition & 1 deletion les/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (d *requestDistributor) queue(r *distReq) chan distPeer {
if r.reqOrder == 0 {
d.lastReqOrder++
r.reqOrder = d.lastReqOrder
r.waitForPeers = d.clock.Now() + mclock.AbsTime(waitForPeers)
r.waitForPeers = d.clock.Now().Add(waitForPeers)
}
// Assign the timestamp when the request is queued no matter it's
// a new one or re-queued one.
Expand Down
2 changes: 1 addition & 1 deletion les/flowcontrol/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (node *ClientNode) UpdateParams(params ServerParams) {
return
}
}
node.updateSchedule = append(node.updateSchedule, scheduledUpdate{time: now + mclock.AbsTime(DecParamDelay), params: params})
node.updateSchedule = append(node.updateSchedule, scheduledUpdate{time: now.Add(DecParamDelay), params: params})
}
}

Expand Down
2 changes: 1 addition & 1 deletion les/utils/timeutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestUpdateTimer(t *testing.T) {
if updated := timer.Update(func(diff time.Duration) bool { return true }); !updated {
t.Fatalf("Doesn't update the clock when reaching the threshold")
}
if updated := timer.UpdateAt(sim.Now()+mclock.AbsTime(time.Second), func(diff time.Duration) bool { return true }); !updated {
if updated := timer.UpdateAt(sim.Now().Add(time.Second), func(diff time.Duration) bool { return true }); !updated {
t.Fatalf("Doesn't update the clock when reaching the threshold")
}
timer = NewUpdateTimer(sim, 0)
Expand Down
8 changes: 4 additions & 4 deletions les/vflux/server/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (n *nodeBalance) estimatePriority(capacity uint64, addBalance int64, future
b = n.reducedBalance(b, now, future, capacity, avgReqCost)
}
if bias > 0 {
b = n.reducedBalance(b, now+mclock.AbsTime(future), bias, capacity, 0)
b = n.reducedBalance(b, now.Add(future), bias, capacity, 0)
}
pri := n.balanceToPriority(now, b, capacity)
// Ensure that biased estimates are always lower than actual priorities, even if
Expand Down Expand Up @@ -512,15 +512,15 @@ func (n *nodeBalance) scheduleCheck(now mclock.AbsTime) {
n.updateAfter(0)
return
}
if n.nextUpdate == 0 || n.nextUpdate > now+mclock.AbsTime(d) {
if n.nextUpdate == 0 || n.nextUpdate > now.Add(d) {
if d > time.Second {
// Note: if the scheduled update is not in the very near future then we
// schedule the update a bit earlier. This way we do need to update a few
// extra times but don't need to reschedule every time a processed request
// brings the expected firing time a little bit closer.
d = ((d - time.Second) * 7 / 8) + time.Second
}
n.nextUpdate = now + mclock.AbsTime(d)
n.nextUpdate = now.Add(d)
n.updateAfter(d)
}
} else {
Expand Down Expand Up @@ -629,7 +629,7 @@ func (n *nodeBalance) reducedBalance(b balance, start mclock.AbsTime, dt time.Du
// since the costs are applied continuously during the dt time period we calculate
// the expiration offset at the middle of the period
var (
at = start + mclock.AbsTime(dt/2)
at = start.Add(dt / 2)
dtf = float64(dt)
)
if !b.pos.IsZero() {
Expand Down

0 comments on commit 120e58d

Please sign in to comment.