diff --git a/crates/starknet_batcher/src/block_builder.rs b/crates/starknet_batcher/src/block_builder.rs index 3cf293648e..40bbd67ec1 100644 --- a/crates/starknet_batcher/src/block_builder.rs +++ b/crates/starknet_batcher/src/block_builder.rs @@ -223,17 +223,13 @@ async fn collect_execution_results_and_stream_txs( Ok(false) } -pub struct BlockMetadata { - pub height: BlockNumber, - pub retrospective_block_hash: Option, -} - /// The BlockBuilderFactoryTrait is responsible for creating a new block builder. #[cfg_attr(test, automock)] pub trait BlockBuilderFactoryTrait { fn create_block_builder( &self, - block_metadata: BlockMetadata, + height: BlockNumber, + retrospective_block_hash: Option, execution_params: BlockBuilderExecutionParams, tx_provider: Box, output_content_sender: Option>, @@ -308,11 +304,12 @@ pub struct BlockBuilderFactory { impl BlockBuilderFactory { fn preprocess_and_create_transaction_executor( &self, - block_metadata: &BlockMetadata, + height: BlockNumber, + retrospective_block_hash: Option, ) -> BlockBuilderResult> { let block_builder_config = self.block_builder_config.clone(); let next_block_info = BlockInfo { - block_number: block_metadata.height, + block_number: height, block_timestamp: BlockTimestamp(chrono::Utc::now().timestamp().try_into()?), sequencer_address: block_builder_config.sequencer_address, // TODO (yael 7/10/2024): add logic to compute gas prices @@ -334,14 +331,16 @@ impl BlockBuilderFactory { let state_reader = PapyrusReader::new( self.storage_reader.clone(), - block_metadata.height, + height, + // TODO(Yael 18/9/2024): dont forget to flush the cached_state cache into the global + // cache on decision_reached. self.global_class_hash_to_class.clone(), ); let executor = TransactionExecutor::pre_process_and_create( state_reader, block_context, - block_metadata.retrospective_block_hash, + retrospective_block_hash, block_builder_config.execute_config, )?; @@ -352,13 +351,15 @@ impl BlockBuilderFactory { impl BlockBuilderFactoryTrait for BlockBuilderFactory { fn create_block_builder( &self, - block_metadata: BlockMetadata, + height: BlockNumber, + retrospective_block_hash: Option, execution_params: BlockBuilderExecutionParams, tx_provider: Box, output_content_sender: Option>, abort_signal_receiver: tokio::sync::oneshot::Receiver<()>, ) -> BlockBuilderResult> { - let executor = self.preprocess_and_create_transaction_executor(&block_metadata)?; + let executor = + self.preprocess_and_create_transaction_executor(height, retrospective_block_hash)?; Ok(Box::new(BlockBuilder::new( Box::new(executor), tx_provider, diff --git a/crates/starknet_batcher/src/proposal_manager.rs b/crates/starknet_batcher/src/proposal_manager.rs index 5f1fc2407c..de7c14aa83 100644 --- a/crates/starknet_batcher/src/proposal_manager.rs +++ b/crates/starknet_batcher/src/proposal_manager.rs @@ -20,7 +20,6 @@ use crate::block_builder::{ BlockBuilderFactoryTrait, BlockBuilderTrait, BlockExecutionArtifacts, - BlockMetadata, }; use crate::transaction_provider::{ProposeTransactionProvider, ValidateTransactionProvider}; @@ -156,7 +155,8 @@ impl ProposalManagerTrait for ProposalManager { let (abort_signal_sender, abort_signal_receiver) = tokio::sync::oneshot::channel(); let block_builder = self.block_builder_factory.create_block_builder( - BlockMetadata { height, retrospective_block_hash }, + height, + retrospective_block_hash, BlockBuilderExecutionParams { deadline, fail_on_err: false }, Box::new(tx_provider), Some(tx_sender.clone()), @@ -188,7 +188,8 @@ impl ProposalManagerTrait for ProposalManager { let (abort_signal_sender, abort_signal_receiver) = tokio::sync::oneshot::channel(); let block_builder = self.block_builder_factory.create_block_builder( - BlockMetadata { height, retrospective_block_hash }, + height, + retrospective_block_hash, BlockBuilderExecutionParams { deadline, fail_on_err: true }, Box::new(tx_provider), None, diff --git a/crates/starknet_batcher/src/proposal_manager_test.rs b/crates/starknet_batcher/src/proposal_manager_test.rs index b3e52da2e3..60046f5b8a 100644 --- a/crates/starknet_batcher/src/proposal_manager_test.rs +++ b/crates/starknet_batcher/src/proposal_manager_test.rs @@ -58,7 +58,7 @@ impl MockDependencies { self.block_builder_factory .expect_create_block_builder() .times(times) - .returning(move |_, _, _, _, _| simulate_build_block()); + .returning(move |_, _, _, _, _, _| simulate_build_block()); } // This function simulates a long build block operation. This is required for a test that @@ -76,7 +76,7 @@ impl MockDependencies { self.block_builder_factory .expect_create_block_builder() .times(times) - .returning(move |_, _, _, _, _| simulate_long_build_block()); + .returning(move |_, _, _, _, _, _| simulate_long_build_block()); } }