Skip to content

Commit

Permalink
feat: add clearOnStageTimerHandler method to GrandpaRound
Browse files Browse the repository at this point in the history
  • Loading branch information
Grigorov-Georgi committed Feb 7, 2025
1 parent 9f17578 commit 234cf35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/limechain/grandpa/round/GrandpaRound.java
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,11 @@ public void broadcastCommitMessage() {

peerMessageCoordinator.sendCommitMessageToPeers(commitMessage);
}

public void clearOnStageTimerHandler() {
if (onStageTimerHandler != null && onStageTimerHandler.isShutdown()) {
onStageTimerHandler.shutdown();
onStageTimerHandler = null;
}
}
}
8 changes: 2 additions & 6 deletions src/main/java/com/limechain/grandpa/round/PreCommitStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,16 @@ public void start(GrandpaRound round) {

@Override
public void end(GrandpaRound round) {
log.fine(String.format("Round %d ended pre-commit stage.", round.getRoundNumber()));

if (round.getOnStageTimerHandler() != null && !round.getOnStageTimerHandler().isShutdown()) {
round.getOnStageTimerHandler().shutdown();
round.setOnStageTimerHandler(null);
}
round.clearOnStageTimerHandler();

try {

Vote grandpaGhost = Vote.fromBlockHeader(round.getGrandpaGhost());
round.broadcastVoteMessage(grandpaGhost, SubRound.PRE_COMMIT);
round.setState(new FinalizeStage());
round.getState().start(round);
log.fine(String.format("Round %d ended start stage.", round.getRoundNumber()));
log.fine(String.format("Round %d ended pre-commit stage.", round.getRoundNumber()));

} catch (GrandpaGenericException e) {
log.fine(String.format("Round %d cannot end now: %s", round.getRoundNumber(), e.getMessage()));
Expand Down

0 comments on commit 234cf35

Please sign in to comment.