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 concurrent time synchronization.
()
| 951 | // is less or equal to 0, use the clock reading to run the next cycle - this avoids some problem |
| 952 | // caused by concurrent time synchronization. |
| 953 | func (c *Chain) nextTick() (t time.Time, d time.Duration) { |
| 954 | var h uint32 |
| 955 | h, t = func() (nt uint32, t time.Time) { |
| 956 | c.RLock() |
| 957 | defer c.RUnlock() |
| 958 | nt = c.nextHeight |
| 959 | t = time.Now().Add(c.offset).UTC() |
| 960 | return |
| 961 | }() |
| 962 | d = c.genesisTime.Add(time.Duration(h) * c.period).Sub(t) |
| 963 | if d > c.tick { |
| 964 | d = c.tick |
| 965 | } |
| 966 | return |
| 967 | } |
| 968 | |
| 969 | func (c *Chain) isMyTurn() bool { |
| 970 | c.RLock() |