Skip to content

Commit

Permalink
refactor(starknet_batcher): create a function to get_height from stor…
Browse files Browse the repository at this point in the history
…age for code dedup (#2665)
  • Loading branch information
ArniStarkware authored Dec 16, 2024
1 parent 901111f commit 8fbf802
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions crates/starknet_batcher/src/batcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ impl Batcher {
return Err(BatcherError::HeightInProgress);
}

let storage_height =
self.storage_reader.height().map_err(|_| BatcherError::InternalError)?;
let storage_height = self.get_height_from_storage()?;
if storage_height < input.height {
return Err(BatcherError::StorageNotSynced {
storage_height,
Expand Down Expand Up @@ -300,12 +299,16 @@ impl Batcher {
Ok(())
}

#[instrument(skip(self), err)]
pub async fn get_height(&mut self) -> BatcherResult<GetHeightResponse> {
let height = self.storage_reader.height().map_err(|err| {
fn get_height_from_storage(&mut self) -> BatcherResult<BlockNumber> {
self.storage_reader.height().map_err(|err| {
error!("Failed to get height from storage: {}", err);
BatcherError::InternalError
})?;
})
}

#[instrument(skip(self), err)]
pub async fn get_height(&mut self) -> BatcherResult<GetHeightResponse> {
let height = self.get_height_from_storage()?;
Ok(GetHeightResponse { height })
}

Expand Down Expand Up @@ -361,10 +364,7 @@ impl Batcher {
let ProposalOutput { state_diff, nonces: address_to_nonce, tx_hashes, .. } =
proposal_output;
// TODO: Keep the height from start_height or get it from the input.
let height = self.storage_reader.height().map_err(|err| {
error!("Failed to get height from storage: {}", err);
BatcherError::InternalError
})?;
let height = self.get_height_from_storage()?;
info!(
"Committing proposal {} at height {} and notifying mempool of the block.",
proposal_id, height
Expand Down

0 comments on commit 8fbf802

Please sign in to comment.