Skip to content

Commit 947202a

Browse files
committed
Do not panic when height, view or step is changed while creating a block
1 parent 7ab679a commit 947202a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

core/src/consensus/tendermint/worker.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,24 @@ impl Worker {
11031103
}
11041104

11051105
fn proposal_generated(&mut self, sealed_block: &SealedBlock) {
1106+
let proposal_height = sealed_block.header().number();
1107+
let proposal_seal = sealed_block.header().seal();
1108+
let proposal_view = TendermintSealView::new(proposal_seal)
1109+
.consensus_view()
1110+
.expect("Generated proposal should have a valid seal");
1111+
assert!(proposal_height <= self.height, "A generated proposal cannot be generated on the future height");
1112+
if proposal_height < self.height || (proposal_height == self.height && proposal_view != self.view) {
1113+
ctrace!(
1114+
ENGINE,
1115+
"Proposal is generated on the height {} and view {}. Current height is {} and view is {}",
1116+
proposal_height,
1117+
proposal_view,
1118+
self.height,
1119+
self.view,
1120+
);
1121+
return
1122+
}
1123+
11061124
let header = sealed_block.header();
11071125
let hash = header.hash();
11081126
let parent_hash = header.parent_hash();
@@ -1117,7 +1135,12 @@ impl Worker {
11171135
parent_hash, expected_parent_hash
11181136
);
11191137
} else {
1120-
panic!("Block is generated at unexpected step {:?}", self.step);
1138+
ctrace!(
1139+
ENGINE,
1140+
"Proposal is generated after step is changed. Expected step is ProposeWaitBlockGeneration but current step is {:?}",
1141+
self.step,
1142+
);
1143+
return
11211144
}
11221145
let prev_proposer_idx = self.block_proposer_idx(*parent_hash).expect("Prev block must exists");
11231146

0 commit comments

Comments
 (0)