From 6167a5fd4ba65efce2b8809314121af7bf315b8e Mon Sep 17 00:00:00 2001 From: Yael Doweck Date: Thu, 14 Nov 2024 11:16:18 +0200 Subject: [PATCH] refactor(batcher): extract the deadline function in order to share with the validate flow --- crates/starknet_batcher/src/batcher.rs | 13 +++++++++---- crates/starknet_batcher_types/src/batcher_types.rs | 8 -------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/crates/starknet_batcher/src/batcher.rs b/crates/starknet_batcher/src/batcher.rs index 611acad8bf..fa9678800a 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( @@ -350,3 +348,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,