Skip to content

Commit 697e692

Browse files
MitchTurnerxgreenx
andauthored
Add new Error type for block production (#3193)
## Linked Issues/PRs <!-- List of related issues/PRs --> Addressed missed feedback from #3174 ## Description <!-- List of detailed changes --> Add new error type, fix error text --------- Co-authored-by: Green Baneling <XgreenX9999@gmail.com>
1 parent 22b407f commit 697e692

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

.changes/fixed/3193.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add new error type, fix error text

crates/services/producer/src/block_producer.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub enum Error {
8484
best: DaBlockHeight,
8585
previous_block: DaBlockHeight,
8686
},
87-
#[display(fmt = "Attempting to produce genesis block")]
87+
#[display(fmt = "Couldn't produce genesis block")]
8888
CannotProduceGenesisBlock,
8989

9090
#[display(
@@ -94,6 +94,8 @@ pub enum Error {
9494
requested_height: BlockHeight,
9595
expected_height: BlockHeight,
9696
},
97+
#[display(fmt = "Reached maximum block height")]
98+
MaximumBlockHeightReached,
9799
}
98100

99101
impl From<Error> for anyhow::Error {
@@ -231,7 +233,7 @@ where
231233
let latest_height = view.latest_height().ok_or(Error::NoGenesisBlock)?;
232234
let next_height = latest_height
233235
.succ()
234-
.expect("Should always be able to increment the latest height");
236+
.ok_or(Error::MaximumBlockHeightReached)?;
235237

236238
if height == BlockHeight::new(0) {
237239
return Err(Error::CannotProduceGenesisBlock.into());
@@ -375,7 +377,7 @@ where
375377

376378
let next_height = latest_height
377379
.succ()
378-
.expect("Should always be able to increment the latest height");
380+
.ok_or(Error::MaximumBlockHeightReached)?;
379381

380382
let header = match height {
381383
Some(height) if height == next_height => {
@@ -548,7 +550,7 @@ where
548550
let height = previous_block_info
549551
.height
550552
.succ()
551-
.ok_or(Error::NoGenesisBlock)?;
553+
.ok_or(Error::MaximumBlockHeightReached)?;
552554
let consensus_parameters_version = view.latest_consensus_parameters_version()?;
553555
let state_transition_bytecode_version =
554556
view.latest_state_transition_bytecode_version()?;

0 commit comments

Comments
 (0)