Skip to content

Commit

Permalink
reuse timer
Browse files Browse the repository at this point in the history
  • Loading branch information
dshulyak committed Sep 5, 2023
1 parent de4cce4 commit 7234b99
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions hare3/hare.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,27 +363,35 @@ func (h *Hare) run(layer types.LayerID, beacon types.Beacon, proto *protocol) er
activeLatency.Observe(time.Since(start).Seconds())
h.tracer.OnActive(vrf)

walltime := h.nodeclock.LayerToTime(layer).Add(h.config.PreroundDelay)
var (
walltime = h.nodeclock.LayerToTime(layer).Add(h.config.PreroundDelay)
timer *clock.Timer
)
if vrf != nil {
h.log.Debug("active in preround", zap.Uint32("lid", layer.Uint32()))
// initial set is not needed if node is not active in preround
timer = h.wallclock.Timer(h.wallclock.Until(walltime))
select {
case <-h.wallclock.After(h.wallclock.Until(walltime)):
case <-timer.C:
case <-h.ctx.Done():
return h.ctx.Err()
}
start := time.Now()
proto.OnInitial(h.proposals(layer, beacon))
proposalsLatency.Observe(time.Since(start).Seconds())
} else {
timer = h.wallclock.Timer(0)
}
defer timer.Stop()
if err := h.onOutput(layer, current, proto.Next(vrf != nil), vrf); err != nil {
return err
}
walltime = walltime.Add(h.config.RoundDuration)
result := false
for {
walltime = walltime.Add(h.config.RoundDuration)
timer.Reset(h.wallclock.Until(walltime))
select {
case <-h.wallclock.After(h.wallclock.Until(walltime)):
case <-timer.C:
h.log.Debug("execute round",
zap.Uint32("lid", layer.Uint32()),
zap.Uint8("iter", proto.Iter), zap.Stringer("round", proto.Round),
Expand Down Expand Up @@ -414,7 +422,6 @@ func (h *Hare) run(layer types.LayerID, beacon types.Beacon, proto *protocol) er
return fmt.Errorf("hare failed to reach consensus in %d iterations",
h.config.IterationsLimit)
}
walltime = walltime.Add(h.config.RoundDuration)
case <-h.ctx.Done():
return nil
}
Expand Down

0 comments on commit 7234b99

Please sign in to comment.