Skip to content

Commit 4c8aaab

Browse files
dbadoyblakehhuynh
authored andcommitted
all: use AbsTime.Add instead of conversion (ethereum#25417)
1 parent c597177 commit 4c8aaab

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

common/mclock/simclock.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (s *Simulated) Run(d time.Duration) {
5858
s.mu.Lock()
5959
s.init()
6060

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

137-
at := s.now + AbsTime(d)
137+
at := s.now.Add(d)
138138
ev := &simTimer{do: fn, at: at, s: s}
139139
heap.Push(&s.scheduled, ev)
140140
s.cond.Broadcast()

common/prque/lazyqueue.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ func (q *LazyQueue) Refresh() {
8787

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

9999
// Push adds an item to the queue

les/distributor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func (d *requestDistributor) queue(r *distReq) chan distPeer {
256256
if r.reqOrder == 0 {
257257
d.lastReqOrder++
258258
r.reqOrder = d.lastReqOrder
259-
r.waitForPeers = d.clock.Now() + mclock.AbsTime(waitForPeers)
259+
r.waitForPeers = d.clock.Now().Add(waitForPeers)
260260
}
261261
// Assign the timestamp when the request is queued no matter it's
262262
// a new one or re-queued one.

les/flowcontrol/control.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (node *ClientNode) UpdateParams(params ServerParams) {
182182
return
183183
}
184184
}
185-
node.updateSchedule = append(node.updateSchedule, scheduledUpdate{time: now + mclock.AbsTime(DecParamDelay), params: params})
185+
node.updateSchedule = append(node.updateSchedule, scheduledUpdate{time: now.Add(DecParamDelay), params: params})
186186
}
187187
}
188188

les/utils/timeutils_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestUpdateTimer(t *testing.T) {
3737
if updated := timer.Update(func(diff time.Duration) bool { return true }); !updated {
3838
t.Fatalf("Doesn't update the clock when reaching the threshold")
3939
}
40-
if updated := timer.UpdateAt(sim.Now()+mclock.AbsTime(time.Second), func(diff time.Duration) bool { return true }); !updated {
40+
if updated := timer.UpdateAt(sim.Now().Add(time.Second), func(diff time.Duration) bool { return true }); !updated {
4141
t.Fatalf("Doesn't update the clock when reaching the threshold")
4242
}
4343
timer = NewUpdateTimer(sim, 0)

les/vflux/server/balance.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func (n *nodeBalance) estimatePriority(capacity uint64, addBalance int64, future
356356
b = n.reducedBalance(b, now, future, capacity, avgReqCost)
357357
}
358358
if bias > 0 {
359-
b = n.reducedBalance(b, now+mclock.AbsTime(future), bias, capacity, 0)
359+
b = n.reducedBalance(b, now.Add(future), bias, capacity, 0)
360360
}
361361
pri := n.balanceToPriority(now, b, capacity)
362362
// Ensure that biased estimates are always lower than actual priorities, even if
@@ -512,15 +512,15 @@ func (n *nodeBalance) scheduleCheck(now mclock.AbsTime) {
512512
n.updateAfter(0)
513513
return
514514
}
515-
if n.nextUpdate == 0 || n.nextUpdate > now+mclock.AbsTime(d) {
515+
if n.nextUpdate == 0 || n.nextUpdate > now.Add(d) {
516516
if d > time.Second {
517517
// Note: if the scheduled update is not in the very near future then we
518518
// schedule the update a bit earlier. This way we do need to update a few
519519
// extra times but don't need to reschedule every time a processed request
520520
// brings the expected firing time a little bit closer.
521521
d = ((d - time.Second) * 7 / 8) + time.Second
522522
}
523-
n.nextUpdate = now + mclock.AbsTime(d)
523+
n.nextUpdate = now.Add(d)
524524
n.updateAfter(d)
525525
}
526526
} else {
@@ -629,7 +629,7 @@ func (n *nodeBalance) reducedBalance(b balance, start mclock.AbsTime, dt time.Du
629629
// since the costs are applied continuously during the dt time period we calculate
630630
// the expiration offset at the middle of the period
631631
var (
632-
at = start + mclock.AbsTime(dt/2)
632+
at = start.Add(dt / 2)
633633
dtf = float64(dt)
634634
)
635635
if !b.pos.IsZero() {

0 commit comments

Comments
 (0)