Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(batcher): extract the deadline function in order to share with the validate flow #2049

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -351,3 +349,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
Loading