Skip to content

Commit c03b699

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

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
@@ -1098,6 +1098,24 @@ impl Worker {
10981098
}
10991099

11001100
fn proposal_generated(&mut self, sealed_block: &SealedBlock) {
1101+
let proposal_height = sealed_block.header().number();
1102+
let proposal_seal = sealed_block.header().seal();
1103+
let proposal_view = TendermintSealView::new(proposal_seal)
1104+
.consensus_view()
1105+
.expect("Generated proposal should have a valid seal");
1106+
assert!(proposal_height <= self.height, "A proposal cannot be generated on the future height");
1107+
if proposal_height < self.height || (proposal_height == self.height && proposal_view != self.view) {
1108+
ctrace!(
1109+
ENGINE,
1110+
"Proposal is generated on the height {} and view {}. Current height is {} and view is {}",
1111+
proposal_height,
1112+
proposal_view,
1113+
self.height,
1114+
self.view,
1115+
);
1116+
return
1117+
}
1118+
11011119
let header = sealed_block.header();
11021120
let hash = header.hash();
11031121
let parent_hash = header.parent_hash();
@@ -1112,7 +1130,12 @@ impl Worker {
11121130
parent_hash, expected_parent_hash
11131131
);
11141132
} else {
1115-
panic!("Block is generated at unexpected step {:?}", self.step);
1133+
ctrace!(
1134+
ENGINE,
1135+
"Proposal is generated after step is changed. Expected step is ProposeWaitBlockGeneration but current step is {:?}",
1136+
self.step,
1137+
);
1138+
return
11161139
}
11171140
let prev_proposer_idx = self.block_proposer_idx(*parent_hash).expect("Prev block must exists");
11181141

0 commit comments

Comments
 (0)