Skip to content

Commit 53f5521

Browse files
committed
Recover TendermintState when empty proposal timer is fired in a wrong time
The Tendermint module was changing its step to 'Propose' when the "engine timeout empty proposal" timer is fired. If the timer is called in the wrong time the step should not be changed. This commit makes the step change when it is needed.
1 parent 08f5b31 commit 53f5521

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

core/src/consensus/tendermint/types.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ impl TendermintState {
7676
}
7777
}
7878

79+
pub fn is_propose_wait_empty_block_timer(&self) -> bool {
80+
match self {
81+
TendermintState::ProposeWaitEmptyBlockTimer {
82+
..
83+
} => true,
84+
_ => false,
85+
}
86+
}
87+
7988
pub fn is_commit(&self) -> bool {
8089
match self {
8190
TendermintState::Commit {

core/src/consensus/tendermint/worker.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,25 +1214,27 @@ impl Worker {
12141214
fn on_timeout(&mut self, token: usize) {
12151215
// Timeout from empty block generation
12161216
if token == ENGINE_TIMEOUT_EMPTY_PROPOSAL {
1217-
let prev_step = mem::replace(&mut self.step, TendermintState::Propose);
1218-
match prev_step {
1219-
TendermintState::ProposeWaitEmptyBlockTimer {
1220-
block,
1221-
} => {
1222-
if self.height == block.header().number() {
1223-
cdebug!(
1224-
ENGINE,
1225-
"Empty proposal timer is finished, go to the prevote step and broadcast the block"
1226-
);
1227-
self.submit_proposal_block(block.as_ref());
1228-
} else {
1229-
cwarn!(ENGINE, "Empty proposal timer was for previous height.");
1230-
}
1231-
}
1232-
_ => {
1233-
cwarn!(ENGINE, "Empty proposal timer was not cleared.");
1217+
let block = if self.step.is_propose_wait_empty_block_timer() {
1218+
let previous = mem::replace(&mut self.step, TendermintState::Propose);
1219+
match previous {
1220+
TendermintState::ProposeWaitEmptyBlockTimer {
1221+
block,
1222+
} => block,
1223+
_ => unreachable!(),
12341224
}
1225+
} else {
1226+
cwarn!(ENGINE, "Empty proposal timer was not cleared.");
1227+
return
1228+
};
1229+
1230+
if self.height == block.header().number() {
1231+
cdebug!(ENGINE, "Empty proposal timer is finished, go to the prevote step and broadcast the block");
1232+
self.submit_proposal_block(block.as_ref());
1233+
} else {
1234+
self.move_to_step(TendermintState::Prevote, false);
1235+
cwarn!(ENGINE, "Empty proposal timer was for previous height.");
12351236
}
1237+
12361238
return
12371239
}
12381240

0 commit comments

Comments
 (0)