Skip to content

Commit

Permalink
chore(batcher): add next_block_info method to block builder factory
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Nov 24, 2024
1 parent 54dff5c commit 58aa988
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions crates/starknet_batcher/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,23 +296,27 @@ pub struct BlockBuilderFactory {
}

impl BlockBuilderFactory {
fn preprocess_and_create_transaction_executor(
&self,
height: BlockNumber,
retrospective_block_hash: Option<BlockHashAndNumber>,
) -> BlockBuilderResult<TransactionExecutor<PapyrusReader>> {
let block_builder_config = self.block_builder_config.clone();
let next_block_info = BlockInfo {
fn next_block_info(&self, height: BlockNumber) -> BlockInfo {
BlockInfo {
block_number: height,
block_timestamp: BlockTimestamp(chrono::Utc::now().timestamp().try_into()?),
sequencer_address: block_builder_config.sequencer_address,
block_timestamp: BlockTimestamp(chrono::Utc::now().timestamp().try_into().unwrap()),
sequencer_address: self.block_builder_config.sequencer_address,
// TODO (yael 7/10/2024): add logic to compute gas prices
gas_prices: {
let tmp_val = NonzeroGasPrice::MIN;
GasPrices::new(tmp_val, tmp_val, tmp_val, tmp_val, tmp_val, tmp_val)
},
use_kzg_da: block_builder_config.use_kzg_da,
};
use_kzg_da: self.block_builder_config.use_kzg_da,
}
}

fn preprocess_and_create_transaction_executor(
&self,
next_block_info: BlockInfo,
retrospective_block_hash: Option<BlockHashAndNumber>,
) -> BlockBuilderResult<TransactionExecutor<PapyrusReader>> {
let block_builder_config = self.block_builder_config.clone();
let height = next_block_info.block_number;
let versioned_constants = VersionedConstants::get_versioned_constants(
block_builder_config.versioned_constants_overrides,
);
Expand Down Expand Up @@ -356,8 +360,12 @@ impl BlockBuilderFactoryTrait for BlockBuilderFactory {
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(height, retrospective_block_hash)?;
// TODO(Arni): Get block info as a parameter for this function.
let next_block_info = self.next_block_info(height);
let executor = self.preprocess_and_create_transaction_executor(
next_block_info,
retrospective_block_hash,
)?;
Ok(Box::new(BlockBuilder::new(
Box::new(executor),
tx_provider,
Expand Down

0 comments on commit 58aa988

Please sign in to comment.