Skip to content

Commit 362ae11

Browse files
committed
feat: expose duration
1 parent 21f6797 commit 362ae11

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

timer/timer.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type LinearTimer struct {
7272
}
7373

7474
// NewLinearTimer constructs a new Linear Timer from the input options and channels
75-
func NewLinearTimer(opts Options, handleTimeoutPropose, handleTimeoutPrevote, handleTimeoutPrecommit func(Timeout)) process.Timer {
75+
func NewLinearTimer(opts Options, handleTimeoutPropose, handleTimeoutPrevote, handleTimeoutPrecommit func(Timeout)) *LinearTimer {
7676
return &LinearTimer{
7777
opts: opts,
7878
handleTimeoutPropose: handleTimeoutPropose,
@@ -86,7 +86,7 @@ func NewLinearTimer(opts Options, handleTimeoutPropose, handleTimeoutPrevote, ha
8686
func (t *LinearTimer) TimeoutPropose(height process.Height, round process.Round) {
8787
if t.handleTimeoutPropose != nil {
8888
go func() {
89-
time.Sleep(t.timeoutDuration(height, round))
89+
time.Sleep(t.DurationAtHeightAndRound(height, round))
9090
t.handleTimeoutPropose(Timeout{MessageType: process.MessageTypePropose, Height: height, Round: round})
9191
}()
9292
}
@@ -97,7 +97,7 @@ func (t *LinearTimer) TimeoutPropose(height process.Height, round process.Round)
9797
func (t *LinearTimer) TimeoutPrevote(height process.Height, round process.Round) {
9898
if t.handleTimeoutPrevote != nil {
9999
go func() {
100-
time.Sleep(t.timeoutDuration(height, round))
100+
time.Sleep(t.DurationAtHeightAndRound(height, round))
101101
t.handleTimeoutPrevote(Timeout{MessageType: process.MessageTypePrevote, Height: height, Round: round})
102102
}()
103103
}
@@ -108,12 +108,15 @@ func (t *LinearTimer) TimeoutPrevote(height process.Height, round process.Round)
108108
func (t *LinearTimer) TimeoutPrecommit(height process.Height, round process.Round) {
109109
if t.handleTimeoutPrecommit != nil {
110110
go func() {
111-
time.Sleep(t.timeoutDuration(height, round))
111+
time.Sleep(t.DurationAtHeightAndRound(height, round))
112112
t.handleTimeoutPrecommit(Timeout{MessageType: process.MessageTypePrecommit, Height: height, Round: round})
113113
}()
114114
}
115115
}
116116

117-
func (t *LinearTimer) timeoutDuration(height process.Height, round process.Round) time.Duration {
117+
// DurationAtHeightAndRound returns the duration of the timeout at the given
118+
// height and round. This is the duration that the other methods will wait
119+
// before scheduling their respective timeout events.
120+
func (t *LinearTimer) DurationAtHeightAndRound(height process.Height, round process.Round) time.Duration {
118121
return t.opts.Timeout + t.opts.Timeout*time.Duration(float64(round)*t.opts.TimeoutScaling)
119122
}

0 commit comments

Comments
 (0)