-
Notifications
You must be signed in to change notification settings - Fork 347
chore: wait in the precommit step without re-scheduling #2619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
d7f4911
615f634
067cb0e
b1c73a7
78ffcdb
6ab7433
11d5caf
945a6f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -293,7 +293,7 @@ | |
| // GetRoundState returns a shallow copy of the internal consensus state. | ||
| func (cs *State) GetRoundState() *cstypes.RoundState { | ||
| cs.rsMtx.RLock() | ||
| rs := cs.rs // copy | ||
| cs.rsMtx.RUnlock() | ||
| return &rs | ||
| } | ||
|
|
@@ -302,7 +302,7 @@ | |
| func (cs *State) GetRoundStateJSON() ([]byte, error) { | ||
| cs.rsMtx.RLock() | ||
| defer cs.rsMtx.RUnlock() | ||
| return cmtjson.Marshal(cs.rs) | ||
| } | ||
|
|
||
| // GetRoundStateSimpleJSON returns a json of RoundStateSimple | ||
|
|
@@ -939,7 +939,7 @@ | |
| } | ||
| } | ||
|
|
||
| rs := cs.rs | ||
| var mi msgInfo | ||
|
|
||
| select { | ||
|
|
@@ -983,7 +983,7 @@ | |
|
|
||
| // if the timeout is relevant to the rs | ||
| // go to the next step | ||
| cs.handleTimeout(ti, rs) | ||
|
|
||
| case <-cs.Quit(): | ||
| onExit(cs) | ||
|
|
@@ -1084,7 +1084,7 @@ | |
| } | ||
| } | ||
|
|
||
| func (cs *State) handleTimeout(ti timeoutInfo, rs cstypes.RoundState) { | ||
| cs.Logger.Trace("received tock", "timeout", ti.Duration, "height", ti.Height, "round", ti.Round, "step", ti.Step) | ||
|
|
||
| // timeouts must be for current height, round, step | ||
|
|
@@ -1622,9 +1622,23 @@ | |
| return | ||
| } | ||
|
|
||
| if ready, waitTime := cs.isReadyToPrecommit(); !ready { | ||
| logger.Debug("rescheduling precommit", "delay(ms)", waitTime.Milliseconds()) | ||
| cs.scheduleTimeout(waitTime, height, round, cstypes.RoundStepPrevoteWait) | ||
| if !cs.rs.StartedPrecommitSleep.Load() { | ||
| cs.rs.StartedPrecommitSleep.Store(true) | ||
| waitTime := cs.precommitDelay() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we avoid the timer and unlocking relocking, if the waitTime is 0 We could even add the check prior like:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adding the check above would complicate the |
||
| logger.Debug("delaying precommit", "delay", waitTime) | ||
| cs.unlockAll() | ||
| t := time.NewTimer(waitTime) | ||
| select { | ||
| case <-cs.Quit(): | ||
| cs.lockAll() | ||
| return | ||
| case <-t.C: | ||
| } | ||
| cs.lockAll() | ||
evan-forbes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cs.rs.StartedPrecommitSleep.Store(false) | ||
| } else { | ||
| logger.Debug("already entered precommit sleep") | ||
| // if any other routine tries to enter precommit, we just return | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -2105,20 +2119,20 @@ | |
| // KMSSigningDelay is a constant representing a delay used primarily to adjust for KMS signing latencies. | ||
| const KMSSigningDelay = 200 * time.Millisecond | ||
|
|
||
| // isReadyToPrecommit calculates if the process has waited at least a certain number of seconds | ||
| // precommitDelay calculates if the process has waited at least a certain number of seconds | ||
| // from their start time before they can vote | ||
| // If the application's DelayedPrecommitTimeout is set to 0, no precommit wait is done. | ||
| func (cs *State) isReadyToPrecommit() (bool, time.Duration) { | ||
| func (cs *State) precommitDelay() time.Duration { | ||
| if cs.state.Timeouts.DelayedPrecommitTimeout == 0 { | ||
| // setting 0 as a special case not to reschedule the pre-commit | ||
| return true, 0 | ||
| return 0 | ||
| } | ||
| precommitVoteTime := cs.rs.StartTime.Add(cs.state.Timeouts.DelayedPrecommitTimeout) | ||
| waitTime := time.Until(precommitVoteTime) | ||
| if _, ok := cs.privValidator.(*privval.SignerClient); ok { | ||
| waitTime = waitTime - KMSSigningDelay | ||
| } | ||
| return waitTime <= 0, waitTime | ||
| return waitTime | ||
| } | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
CompareAndSwap.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6ab7433