mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 13:21:37 +00:00
common, p2p: use AbsTime.Add instead of conversion (#25417)
This commit is contained in:
parent
e3edcc8429
commit
32e033df3a
4 changed files with 12 additions and 12 deletions
|
|
@ -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)
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -88,13 +88,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
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ func pongToTicket(localTime mclock.AbsTime, topics []Topic, node *Node, p *ingre
|
|||
}
|
||||
// Convert wait periods to local absolute time.
|
||||
for i, wp := range wps {
|
||||
t.regTime[i] = localTime + mclock.AbsTime(time.Second*time.Duration(wp))
|
||||
t.regTime[i] = localTime.Add(time.Second * time.Duration(wp))
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
|
|
@ -349,7 +349,7 @@ func (s *ticketStore) nextFilteredTicket() (*ticketRef, time.Duration) {
|
|||
}
|
||||
log.Trace("Found discovery ticket to register", "node", ticket.t.node, "serial", ticket.t.serial, "wait", wait)
|
||||
|
||||
regTime := now + mclock.AbsTime(wait)
|
||||
regTime := now.Add(wait)
|
||||
topic := ticket.t.topics[ticket.idx]
|
||||
if s.tickets[topic] != nil && regTime >= s.tickets[topic].nextReg {
|
||||
return ticket, wait
|
||||
|
|
@ -614,7 +614,7 @@ func (s *ticketStore) cleanupTopicQueries(now mclock.AbsTime) {
|
|||
delete(s.queriesSent, n)
|
||||
}
|
||||
}
|
||||
s.nextTopicQueryCleanup = now + mclock.AbsTime(topicQueryTimeout)
|
||||
s.nextTopicQueryCleanup = now.Add(topicQueryTimeout)
|
||||
}
|
||||
|
||||
func (s *ticketStore) gotTopicNodes(from *Node, hash common.Hash, nodes []rpcNode) (timeout bool) {
|
||||
|
|
@ -625,7 +625,7 @@ func (s *ticketStore) gotTopicNodes(from *Node, hash common.Hash, nodes []rpcNod
|
|||
return true
|
||||
}
|
||||
q, ok := qq[hash]
|
||||
if !ok || now > q.sent+mclock.AbsTime(topicQueryTimeout) {
|
||||
if !ok || now > q.sent.Add(topicQueryTimeout) {
|
||||
return true
|
||||
}
|
||||
inside := float64(0)
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ func (t *topicTable) addEntry(node *Node, topic Topic) {
|
|||
topic: topic,
|
||||
fifoIdx: fifoIdx,
|
||||
node: node,
|
||||
expire: tm + mclock.AbsTime(fallbackRegistrationExpiry),
|
||||
expire: tm.Add(fallbackRegistrationExpiry),
|
||||
}
|
||||
if printTestImgLogs {
|
||||
fmt.Printf("*+ %d %v %016x %016x\n", tm/1000000, topic, t.self.sha[:8], node.sha[:8])
|
||||
|
|
@ -251,7 +251,7 @@ func (t *topicTable) useTicket(node *Node, serialNo uint32, topics []Topic, idx
|
|||
}
|
||||
if serialNo != n.lastUsedTicket {
|
||||
n.lastUsedTicket = serialNo
|
||||
n.noRegUntil = tm + mclock.AbsTime(noRegTimeout())
|
||||
n.noRegUntil = tm.Add(noRegTimeout())
|
||||
t.storeTicketCounters(node)
|
||||
}
|
||||
|
||||
|
|
@ -263,7 +263,7 @@ func (t *topicTable) useTicket(node *Node, serialNo uint32, topics []Topic, idx
|
|||
t.addEntry(node, topics[idx])
|
||||
} else {
|
||||
// if there is an active entry, don't move to the front of the FIFO but prolong expire time
|
||||
e.expire = tm + mclock.AbsTime(fallbackRegistrationExpiry)
|
||||
e.expire = tm.Add(fallbackRegistrationExpiry)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
@ -293,7 +293,7 @@ func (topictab *topicTable) getTicket(node *Node, topics []Topic) *ticket {
|
|||
waitPeriod = minWaitPeriod
|
||||
}
|
||||
|
||||
t.regTime[i] = now + mclock.AbsTime(waitPeriod)
|
||||
t.regTime[i] = now.Add(waitPeriod)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue