Skip to content

Commit f62e91d

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 changed when it is needed.
1 parent 0f57148 commit f62e91d

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
@@ -1208,25 +1208,27 @@ impl Worker {
12081208
fn on_timeout(&mut self, token: usize) {
12091209
// Timeout from empty block generation
12101210
if token == ENGINE_TIMEOUT_EMPTY_PROPOSAL {
1211-
let prev_step = mem::replace(&mut self.step, TendermintState::Propose);
1212-
match prev_step {
1213-
TendermintState::ProposeWaitEmptyBlockTimer {
1214-
block,
1215-
} => {
1216-
if self.height == block.header().number() {
1217-
cdebug!(
1218-
ENGINE,
1219-
"Empty proposal timer is finished, go to the prevote step and broadcast the block"
1220-
);
1221-
self.submit_proposal_block(block.as_ref());
1222-
} else {
1223-
cwarn!(ENGINE, "Empty proposal timer was for previous height.");
1224-
}
1225-
}
1226-
_ => {
1227-
cwarn!(ENGINE, "Empty proposal timer was not cleared.");
1211+
let block = if self.step.is_propose_wait_empty_block_timer() {
1212+
let previous = mem::replace(&mut self.step, TendermintState::Propose);
1213+
match previous {
1214+
TendermintState::ProposeWaitEmptyBlockTimer {
1215+
block,
1216+
} => block,
1217+
_ => unreachable!(),
12281218
}
1219+
} else {
1220+
cwarn!(ENGINE, "Empty proposal timer was not cleared.");
1221+
return
1222+
};
1223+
1224+
if self.height == block.header().number() {
1225+
cdebug!(ENGINE, "Empty proposal timer is finished, go to the prevote step and broadcast the block");
1226+
self.submit_proposal_block(block.as_ref());
1227+
} else {
1228+
self.move_to_step(TendermintState::Prevote, false);
1229+
cwarn!(ENGINE, "Empty proposal timer was for previous height.");
12291230
}
1231+
12301232
return
12311233
}
12321234

0 commit comments

Comments
 (0)