Skip to content

Commit

Permalink
feat: use a proper block builder factory in batcher creation (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware authored Oct 14, 2024
1 parent 16caad8 commit 087af3b
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions crates/batcher/src/batcher.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -41,19 +46,6 @@ pub struct Batcher {
proposals: HashMap<ProposalId, Proposal>,
}

// 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<BlockNumberHashPair>,
) -> BlockBuilderResult<Box<dyn BlockBuilderTrait>> {
todo!()
}
}

impl Batcher {
pub(crate) fn new(
config: BatcherConfig,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 087af3b

Please sign in to comment.