Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(batcher): remove block metadata member from block builder factory #2230

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions crates/starknet_batcher/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 @@ -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<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 @@ -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,
)?;

Expand All @@ -352,13 +351,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
Loading