nextTick returns the current clock reading and the duration till the next turn. If duration is less or equal to 0, use the clock reading to run the next cycle - this avoids some problem caused by concurrently time synchronization.
()
| 226 | // is less or equal to 0, use the clock reading to run the next cycle - this avoids some problem |
| 227 | // caused by concurrently time synchronization. |
| 228 | func (r *runtime) nextTick() (t time.Time, d time.Duration) { |
| 229 | r.stateMutex.Lock() |
| 230 | defer r.stateMutex.Unlock() |
| 231 | t = r.now() |
| 232 | d = r.chainInitTime.Add(time.Duration(r.nextTurn) * r.period).Sub(t) |
| 233 | |
| 234 | if d > r.tick { |
| 235 | d = r.tick |
| 236 | } |
| 237 | |
| 238 | return |
| 239 | } |
| 240 | |
| 241 | func (r *runtime) updatePeers(peers *proto.Peers) (err error) { |
| 242 | r.peersMutex.Lock() |