Skip to content

Recover TendermintState when empty the proposal timer is fired in a wrong time #1808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions core/src/consensus/tendermint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ impl TendermintState {
}
}

pub fn is_propose_wait_empty_block_timer(&self) -> bool {
match self {
TendermintState::ProposeWaitEmptyBlockTimer {
..
} => true,
_ => false,
}
}

pub fn is_commit(&self) -> bool {
match self {
TendermintState::Commit {
Expand Down
49 changes: 25 additions & 24 deletions core/src/consensus/tendermint/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,9 @@ impl Worker {
block,
} => {
if !block.transactions().is_empty() {
self.submit_proposal_block(&block);
cinfo!(ENGINE, "Submitting proposal block {}", block.header().hash());
self.move_to_step(TendermintState::Prevote, false);
self.broadcast_proposal_block(self.view, encoded::Block::new(block.rlp_bytes()));
} else {
ctrace!(ENGINE, "Empty proposal is generated, set timer");
self.step = TendermintState::ProposeWaitEmptyBlockTimer {
Expand Down Expand Up @@ -986,12 +988,6 @@ impl Worker {
}
}

fn submit_proposal_block(&mut self, sealed_block: &SealedBlock) {
cinfo!(ENGINE, "Submitting proposal block {}", sealed_block.header().hash());
self.move_to_step(TendermintState::Prevote, false);
self.broadcast_proposal_block(self.view, encoded::Block::new(sealed_block.rlp_bytes()));
}

fn backup(&self) {
backup(self.client().get_kvdb().as_ref(), BackupView {
height: &self.height,
Expand Down Expand Up @@ -1214,25 +1210,30 @@ impl Worker {
fn on_timeout(&mut self, token: usize) {
// Timeout from empty block generation
if token == ENGINE_TIMEOUT_EMPTY_PROPOSAL {
let prev_step = mem::replace(&mut self.step, TendermintState::Propose);
match prev_step {
TendermintState::ProposeWaitEmptyBlockTimer {
block,
} => {
if self.height == block.header().number() {
cdebug!(
ENGINE,
"Empty proposal timer is finished, go to the prevote step and broadcast the block"
);
self.submit_proposal_block(block.as_ref());
} else {
cwarn!(ENGINE, "Empty proposal timer was for previous height.");
}
}
_ => {
cwarn!(ENGINE, "Empty proposal timer was not cleared.");
let block = if self.step.is_propose_wait_empty_block_timer() {
let previous = mem::replace(&mut self.step, TendermintState::Propose);
match previous {
TendermintState::ProposeWaitEmptyBlockTimer {
block,
} => block,
_ => unreachable!(),
}
} else {
cwarn!(ENGINE, "Empty proposal timer was not cleared.");
return
};

// When self.height != block.header().number() && "propose timeout" is already called,
// the state is stuck and can't move to Prevote. We should change the step to Prevote.
self.move_to_step(TendermintState::Prevote, false);
if self.height == block.header().number() {
cdebug!(ENGINE, "Empty proposal timer is finished, go to the prevote step and broadcast the block");
cinfo!(ENGINE, "Submitting proposal block {}", block.header().hash());
self.broadcast_proposal_block(self.view, encoded::Block::new(block.rlp_bytes()));
} else {
cwarn!(ENGINE, "Empty proposal timer was for previous height.");
}

return
}

Expand Down