From 54dff5c76faba4f8e8a3f7d24619fa480beaa18f Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Thu, 21 Nov 2024 17:55:25 +0200 Subject: [PATCH] chore(batcher): remove block metadata member from block builder factory --- crates/starknet_batcher/src/block_builder.rs | 23 +++++++++---------- .../starknet_batcher/src/proposal_manager.rs | 7 +++--- .../src/proposal_manager_test.rs | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/crates/starknet_batcher/src/block_builder.rs b/crates/starknet_batcher/src/block_builder.rs index 2c862bb4ba..27aa41d30d 100644 --- a/crates/starknet_batcher/src/block_builder.rs +++ b/crates/starknet_batcher/src/block_builder.rs @@ -217,17 +217,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>, @@ -302,11 +298,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 @@ -332,7 +329,7 @@ impl BlockBuilderFactory { // cache. 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(), @@ -341,7 +338,7 @@ impl BlockBuilderFactory { 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 +349,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()); } }