Skip to content

Commit

Permalink
chore(batcher): remove block metadata member from block builder factory
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Nov 24, 2024
1 parent bd62ab3 commit 54dff5c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
23 changes: 11 additions & 12 deletions crates/starknet_batcher/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockHashAndNumber>,
}

/// 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<BlockHashAndNumber>,
execution_params: BlockBuilderExecutionParams,
tx_provider: Box<dyn TransactionProvider>,
output_content_sender: Option<tokio::sync::mpsc::UnboundedSender<Transaction>>,
Expand Down Expand Up @@ -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<BlockHashAndNumber>,
) -> BlockBuilderResult<TransactionExecutor<PapyrusReader>> {
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
Expand All @@ -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(),
Expand All @@ -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,
)?;

Expand All @@ -352,13 +349,15 @@ impl BlockBuilderFactory {
impl BlockBuilderFactoryTrait for BlockBuilderFactory {
fn create_block_builder(
&self,
block_metadata: BlockMetadata,
height: BlockNumber,
retrospective_block_hash: Option<BlockHashAndNumber>,
execution_params: BlockBuilderExecutionParams,
tx_provider: Box<dyn TransactionProvider>,
output_content_sender: Option<tokio::sync::mpsc::UnboundedSender<Transaction>>,
abort_signal_receiver: tokio::sync::oneshot::Receiver<()>,
) -> BlockBuilderResult<Box<dyn BlockBuilderTrait>> {
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,
Expand Down
7 changes: 4 additions & 3 deletions crates/starknet_batcher/src/proposal_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::block_builder::{
BlockBuilderFactoryTrait,
BlockBuilderTrait,
BlockExecutionArtifacts,
BlockMetadata,
};
use crate::transaction_provider::{ProposeTransactionProvider, ValidateTransactionProvider};

Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/starknet_batcher/src/proposal_manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}

Expand Down

0 comments on commit 54dff5c

Please sign in to comment.