diff --git a/crates/starknet_batcher/src/batcher.rs b/crates/starknet_batcher/src/batcher.rs index 3b8c4c6b48..289df7339a 100644 --- a/crates/starknet_batcher/src/batcher.rs +++ b/crates/starknet_batcher/src/batcher.rs @@ -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}; @@ -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( @@ -351,3 +349,10 @@ impl From for BatcherError { } impl ComponentStarter for Batcher {} + +pub fn deadline_as_instant(deadline: chrono::DateTime) -> BatcherResult { + 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()) +} diff --git a/crates/starknet_batcher_types/src/batcher_types.rs b/crates/starknet_batcher_types/src/batcher_types.rs index 4ce45a2b98..4be67e9a71 100644 --- a/crates/starknet_batcher_types/src/batcher_types.rs +++ b/crates/starknet_batcher_types/src/batcher_types.rs @@ -65,14 +65,6 @@ pub struct ValidateProposalInput { pub retrospective_block_hash: Option, } -impl BuildProposalInput { - pub fn deadline_as_instant(&self) -> Result { - 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,