-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6510350
commit b309840
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/com/limechain/grandpa/round/PreVoteStage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,56 @@ | ||
package com.limechain.grandpa.round; | ||
|
||
import lombok.extern.java.Log; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@Log | ||
public class PreVoteStage implements StageState { | ||
|
||
@Override | ||
public void start(GrandpaRound round) { | ||
if (round.isCompletable()) { | ||
log.fine(String.format("Round %d is completable.", round.getRoundNumber())); | ||
end(round); | ||
return; | ||
} | ||
|
||
long duration = 0; //TODO: choose appropriate value | ||
long delay = (duration * 2) - (System.currentTimeMillis() - round.getStartTime().toEpochMilli()); | ||
|
||
round.getOnStageTimerHandler().schedule(() -> { | ||
log.info(String.format("Round #%d: Time of prevote stage is out", round.getRoundNumber())); | ||
end(round); | ||
}, delay, TimeUnit.MILLISECONDS); | ||
|
||
} | ||
|
||
@Override | ||
public void end(GrandpaRound round) { | ||
log.info(String.format("Round %d ended pre-vote stage", round.getRoundNumber())); | ||
round.setState(new PreCommitStage()); | ||
} | ||
|
||
// stage_timer_handle_ = scheduler_->scheduleWithHandle( | ||
// [wself{weak_from_this()}] { | ||
// if (auto self = wself.lock()) { | ||
// if (self->stage_ == Stage::PREVOTE_RUNS) { | ||
// SL_DEBUG(self->logger_, | ||
// "Round #{}: Time of prevote stage is out", | ||
// self->round_number_); | ||
// self->endPrevoteStage(); | ||
// } | ||
// } | ||
// }, | ||
// toMilliseconds(duration_ * 2 - (scheduler_->now() - start_time_))); | ||
// | ||
// on_complete_handler_ = [this] { | ||
// if (stage_ == Stage::PREVOTE_RUNS) { | ||
// SL_DEBUG(logger_, "Round #{}: Became completable", round_number_); | ||
// endPrevoteStage(); | ||
// } | ||
// }; | ||
// | ||
// stage_ = Stage::PREVOTE_RUNS; | ||
} | ||
|