Skip to content

Commit

Permalink
feat: add starting point
Browse files Browse the repository at this point in the history
  • Loading branch information
Grigorov-Georgi committed Feb 6, 2025
1 parent 6510350 commit b309840
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private boolean isFinalizable() {
*
* @return if the current round is completable
*/
private boolean isCompletable() {
public boolean isCompletable() {

Map<Vote, Long> votes = getDirectVotes(SubRound.PRE_COMMIT);
long votesCount = votes.values().stream()
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/com/limechain/grandpa/round/PreVoteStage.java
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;
}

0 comments on commit b309840

Please sign in to comment.