Skip to content

Commit 062fc76

Browse files
committed
Stop generating block if consensus cannot make a seal
If Tendermint consensus received an outdated block request, it returns empty seal. Miner should stop the block generation if the seal is empty.
1 parent db5368c commit 062fc76

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

core/src/miner/miner.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl Miner {
451451
&self,
452452
parent_block_id: BlockId,
453453
chain: &C,
454-
) -> Result<(ClosedBlock, Option<H256>), Error> {
454+
) -> Result<Option<(ClosedBlock, Option<H256>)>, Error> {
455455
let (transactions, mut open_block, original_work_hash, block_number) = {
456456
let sealing_work = self.sealing_work.lock();
457457

@@ -491,7 +491,7 @@ impl Miner {
491491
if let Some(seal_bytes) = seal.seal_fields() {
492492
open_block.seal(self.engine.borrow(), seal_bytes).expect("Sealing always success");
493493
} else {
494-
panic!("Seal should not be none")
494+
return Ok(None)
495495
}
496496
}
497497

@@ -576,7 +576,7 @@ impl Miner {
576576
chain.chain_info().best_block_timestamp,
577577
);
578578
}
579-
Ok((block, original_work_hash))
579+
Ok(Some((block, original_work_hash)))
580580
}
581581

582582
/// Attempts to perform internal sealing (one that does not require work) and handles the result depending on the type of Seal.
@@ -798,9 +798,12 @@ impl MinerService for Miner {
798798
// | Make sure to release the locks before calling that method. |
799799
// --------------------------------------------------------------------------
800800
match self.prepare_block(BlockId::Latest, client) {
801-
Ok((block, original_work_hash)) => {
801+
Ok(Some((block, original_work_hash))) => {
802802
self.prepare_work(block, original_work_hash);
803803
}
804+
Ok(None) => {
805+
ctrace!(MINER, "prepare_work_sealing: cannot prepare block");
806+
}
804807
Err(err) => {
805808
ctrace!(MINER, "prepare_work_sealing: cannot prepare block: {:?}", err);
806809
}
@@ -837,13 +840,17 @@ impl MinerService for Miner {
837840
let parent_block_number = chain.block_header(&parent_block).expect("Parent is always exist").number();
838841
if self.requires_reseal(parent_block_number) {
839842
let (block, original_work_hash) = match self.prepare_block(parent_block, chain) {
840-
Ok((block, original_work_hash)) => {
843+
Ok(Some((block, original_work_hash))) => {
841844
if !allow_empty_block && block.block().transactions().is_empty() {
842845
ctrace!(MINER, "update_sealing: block is empty, and allow_empty_block is false");
843846
return
844847
}
845848
(block, original_work_hash)
846849
}
850+
Ok(None) => {
851+
ctrace!(MINER, "update_sealing: cannot prepare block");
852+
return
853+
}
847854
Err(err) => {
848855
ctrace!(MINER, "update_sealing: cannot prepare block: {:?}", err);
849856
return

0 commit comments

Comments
 (0)