From 087af3b0463c0c13b7b57614bc6cd4ffda37ee71 Mon Sep 17 00:00:00 2001 From: Arnon Hod Date: Mon, 14 Oct 2024 11:43:02 +0300 Subject: [PATCH] feat: use a proper block builder factory in batcher creation (#1384) --- crates/batcher/src/batcher.rs | 46 +++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/crates/batcher/src/batcher.rs b/crates/batcher/src/batcher.rs index 72943070ad..7f8be3e4fc 100644 --- a/crates/batcher/src/batcher.rs +++ b/crates/batcher/src/batcher.rs @@ -1,11 +1,16 @@ use std::collections::HashMap; use std::sync::Arc; -use blockifier::blockifier::block::BlockNumberHashPair; +use blockifier::blockifier::config::TransactionExecutorConfig; +use blockifier::bouncer::BouncerConfig; +use blockifier::context::ChainInfo; +use blockifier::state::global_cache::GlobalContractCache; +use blockifier::versioned_constants::VersionedConstantsOverrides; #[cfg(test)] use mockall::automock; use papyrus_storage::state::StateStorageReader; use starknet_api::block::BlockNumber; +use starknet_api::core::ContractAddress; use starknet_api::executable_transaction::Transaction; use starknet_batcher_types::batcher_types::{ BatcherResult, @@ -21,7 +26,7 @@ use starknet_mempool_infra::component_definitions::ComponentStarter; use starknet_mempool_types::communication::SharedMempoolClient; use tracing::{error, instrument}; -use crate::block_builder::{BlockBuilderFactoryTrait, BlockBuilderResult, BlockBuilderTrait}; +use crate::block_builder::{BlockBuilderFactory, ExecutionConfig}; use crate::config::BatcherConfig; use crate::proposal_manager::{ BuildProposalError, @@ -41,19 +46,6 @@ pub struct Batcher { proposals: HashMap, } -// TODO(Yael 7/10/2024): remove DummyBlockBuilderFactory and pass the real BlockBuilderFactory -struct DummyBlockBuilderFactory {} - -impl BlockBuilderFactoryTrait for DummyBlockBuilderFactory { - fn create_block_builder( - &self, - _height: BlockNumber, - _retrospective_block_hash: Option, - ) -> BlockBuilderResult> { - todo!() - } -} - impl Batcher { pub(crate) fn new( config: BatcherConfig, @@ -129,11 +121,33 @@ impl Batcher { pub fn create_batcher(config: BatcherConfig, mempool_client: SharedMempoolClient) -> Batcher { let (storage_reader, _storage_writer) = papyrus_storage::open_storage(config.storage.clone()) .expect("Failed to open batcher's storage"); + + // TODO(Arni): use real config - add as part of batcher config. + let execution_config = ExecutionConfig { + chain_info: ChainInfo::default(), + execute_config: TransactionExecutorConfig::default(), + bouncer_config: BouncerConfig::default(), + sequencer_address: ContractAddress::default(), + use_kzg_da: true, + tx_chunk_size: 100, + versioned_constants_overrides: VersionedConstantsOverrides { + validate_max_n_steps: 1000000, + max_recursion_depth: 50, + invoke_tx_max_n_steps: 4000000, + }, + }; + let cache_size = 100; + + let block_builder_factory = Arc::new(BlockBuilderFactory { + execution_config, + storage_reader: storage_reader.clone(), + global_class_hash_to_class: GlobalContractCache::new(cache_size), + }); let storage_reader = Arc::new(storage_reader); let proposal_manager = Box::new(ProposalManager::new( config.proposal_manager.clone(), mempool_client.clone(), - Arc::new(DummyBlockBuilderFactory {}), + block_builder_factory, storage_reader.clone(), )); Batcher::new(config, storage_reader, proposal_manager)