Skip to content

Commit

Permalink
chore(batcher): set block timestamp in build block input
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Nov 28, 2024
1 parent 6541e23 commit a21cac0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use starknet_api::block::{
BlockHashAndNumber,
BlockInfo,
BlockNumber,
BlockTimestamp,
GasPriceVector,
GasPrices,
NonzeroGasPrice,
Expand Down Expand Up @@ -128,10 +129,11 @@ impl ConsensusContext for SequencerConsensusContext {
self.proposal_id += 1;
let timeout =
chrono::Duration::from_std(timeout).expect("Can't convert timeout to chrono::Duration");
let now = chrono::Utc::now();
let build_proposal_input = ProposeBlockInput {
proposal_id,
// TODO: Discuss with batcher team passing std Duration instead.
deadline: chrono::Utc::now() + timeout,
deadline: now + timeout,
// TODO: This is not part of Milestone 1.
retrospective_block_hash: Some(BlockHashAndNumber {
number: BlockNumber::default(),
Expand All @@ -141,6 +143,9 @@ impl ConsensusContext for SequencerConsensusContext {
block_info: BlockInfo {
block_number: proposal_init.height,
gas_prices: TEMPORARY_GAS_PRICES,
block_timestamp: BlockTimestamp(
now.timestamp().try_into().expect("Failed to convert timestamp"),
),
..Default::default()
},
};
Expand Down Expand Up @@ -192,9 +197,10 @@ impl ConsensusContext for SequencerConsensusContext {

let chrono_timeout =
chrono::Duration::from_std(timeout).expect("Can't convert timeout to chrono::Duration");
let now = chrono::Utc::now();
let input = ValidateBlockInput {
proposal_id,
deadline: chrono::Utc::now() + chrono_timeout,
deadline: now + chrono_timeout,
// TODO(Matan 3/11/2024): Add the real value of the retrospective block hash.
retrospective_block_hash: Some(BlockHashAndNumber {
number: BlockNumber::default(),
Expand All @@ -204,6 +210,9 @@ impl ConsensusContext for SequencerConsensusContext {
block_info: BlockInfo {
block_number: height,
gas_prices: TEMPORARY_GAS_PRICES,
block_timestamp: BlockTimestamp(
now.timestamp().try_into().expect("Failed to convert timestamp"),
),
..Default::default()
},
};
Expand Down
9 changes: 7 additions & 2 deletions crates/starknet_batcher/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use crate::transaction_provider::{NextTxs, TransactionProvider, TransactionProvi
#[derive(Debug, Error)]
pub enum BlockBuilderError {
#[error(transparent)]
BadTimestamp(#[from] std::num::TryFromIntError),
BadTimestamp(std::num::TryFromIntError),
#[error(transparent)]
BlockifierStateError(#[from] StateError),
#[error(transparent)]
Expand Down Expand Up @@ -313,7 +313,12 @@ impl BlockBuilderFactory {
let block_builder_config = self.block_builder_config.clone();
let next_block_info = BlockInfo {
block_number: block_metadata.height,
block_timestamp: BlockTimestamp(chrono::Utc::now().timestamp().try_into()?),
block_timestamp: BlockTimestamp(
chrono::Utc::now()
.timestamp()
.try_into()
.map_err(BlockBuilderError::BadTimestamp)?,
),
sequencer_address: block_builder_config.sequencer_address,
// TODO (yael 7/10/2024): add logic to compute gas prices
gas_prices: {
Expand Down

0 comments on commit a21cac0

Please sign in to comment.