Skip to content

Commit

Permalink
refactor(batcher): extract the deadline function in order to share wi…
Browse files Browse the repository at this point in the history
…th the validate flow
  • Loading branch information
Yael-Starkware committed Nov 17, 2024
1 parent 78a5182 commit 6167a5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
13 changes: 9 additions & 4 deletions crates/starknet_batcher/src/batcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::sync::Arc;

use blockifier::state::global_cache::GlobalContractCache;
use chrono::Utc;
#[cfg(test)]
use mockall::automock;
use papyrus_storage::state::{StateStorageReader, StateStorageWriter};
Expand Down Expand Up @@ -86,10 +87,7 @@ impl Batcher {
build_proposal_input: BuildProposalInput,
) -> BatcherResult<()> {
let proposal_id = build_proposal_input.proposal_id;
let deadline =
tokio::time::Instant::from_std(build_proposal_input.deadline_as_instant().map_err(
|_| BatcherError::TimeToDeadlineError { deadline: build_proposal_input.deadline },
)?);
let deadline = deadline_as_instant(build_proposal_input.deadline)?;

let (tx_sender, tx_receiver) = tokio::sync::mpsc::unbounded_channel();
let tx_provider = ProposeTransactionProvider::new(
Expand Down Expand Up @@ -350,3 +348,10 @@ impl From<GetProposalResultError> for BatcherError {
}

impl ComponentStarter for Batcher {}

pub fn deadline_as_instant(deadline: chrono::DateTime<Utc>) -> BatcherResult<tokio::time::Instant> {
let time_to_deadline = deadline - chrono::Utc::now();
let as_duration =
time_to_deadline.to_std().map_err(|_| BatcherError::TimeToDeadlineError { deadline })?;
Ok((std::time::Instant::now() + as_duration).into())
}
8 changes: 0 additions & 8 deletions crates/starknet_batcher_types/src/batcher_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ pub struct ValidateProposalInput {
pub retrospective_block_hash: Option<BlockHashAndNumber>,
}

impl BuildProposalInput {
pub fn deadline_as_instant(&self) -> Result<std::time::Instant, chrono::OutOfRangeError> {
let time_to_deadline = self.deadline - chrono::Utc::now();
let as_duration = time_to_deadline.to_std()?;
Ok(std::time::Instant::now() + as_duration)
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SendProposalContentInput {
pub proposal_id: ProposalId,
Expand Down

0 comments on commit 6167a5f

Please sign in to comment.