@@ -189,6 +189,40 @@ private void AppendBlock(Block block)
189189 _ = Task . Run ( ( ) => _blockChain . Append ( block , GetBlockCommit ( ) ) ) ;
190190 }
191191
192+ private async Task EnterPreCommitWait ( int round , BlockHash hash )
193+ {
194+ if ( ! _preCommitWaitFlags . Add ( round ) )
195+ {
196+ return ;
197+ }
198+
199+ if ( _contextOption . EnterPreCommitDelay > 0 )
200+ {
201+ await Task . Delay (
202+ _contextOption . EnterPreCommitDelay ,
203+ _cancellationTokenSource . Token ) ;
204+ }
205+
206+ ProduceMutation ( ( ) => EnterPreCommit ( round , hash ) ) ;
207+ }
208+
209+ private async Task EnterEndCommitWait ( int round )
210+ {
211+ if ( ! _endCommitWaitFlags . Add ( round ) )
212+ {
213+ return ;
214+ }
215+
216+ if ( _contextOption . EnterEndCommitDelay > 0 )
217+ {
218+ await Task . Delay (
219+ _contextOption . EnterEndCommitDelay ,
220+ _cancellationTokenSource . Token ) ;
221+ }
222+
223+ ProduceMutation ( ( ) => EnterEndCommit ( round ) ) ;
224+ }
225+
192226 /// <summary>
193227 /// Schedules <see cref="ProcessTimeoutPropose"/> to be queued after
194228 /// <see cref="TimeoutPropose"/> amount of time.
@@ -212,7 +246,18 @@ private async Task OnTimeoutPropose(int round)
212246 /// <param name="round">A round that the timeout task is scheduled for.</param>
213247 private async Task OnTimeoutPreVote ( int round )
214248 {
249+ if ( _preCommitTimeoutFlags . Contains ( round ) || ! _preVoteTimeoutFlags . Add ( round ) )
250+ {
251+ return ;
252+ }
253+
215254 TimeSpan timeout = TimeoutPreVote ( round ) ;
255+ _logger . Debug (
256+ "PreVote step in round {Round} is scheduled to be timed out after {Timeout} " +
257+ "because 2/3+ PreVotes are collected for the round. (context: {Context})" ,
258+ round ,
259+ timeout ,
260+ ToString ( ) ) ;
216261 await Task . Delay ( timeout , _cancellationTokenSource . Token ) ;
217262 _logger . Information (
218263 "TimeoutPreVote has occurred in {Timeout}. {Info}" ,
@@ -228,7 +273,18 @@ private async Task OnTimeoutPreVote(int round)
228273 /// <param name="round">The round that the timeout task is scheduled for.</param>
229274 private async Task OnTimeoutPreCommit ( int round )
230275 {
276+ if ( ! _preCommitTimeoutFlags . Add ( round ) )
277+ {
278+ return ;
279+ }
280+
231281 TimeSpan timeout = TimeoutPreCommit ( round ) ;
282+ _logger . Debug (
283+ "PreCommit step in round {Round} is scheduled to be timed out in {Timeout} " +
284+ "because 2/3+ PreCommits are collected for the round. (context: {Context})" ,
285+ round ,
286+ timeout ,
287+ ToString ( ) ) ;
232288 await Task . Delay ( timeout , _cancellationTokenSource . Token ) ;
233289 _logger . Information (
234290 "TimeoutPreCommit has occurred in {Timeout}. {Info}" ,
0 commit comments