Skip to content

Commit

Permalink
fix(starknet_batcher): change block full condition in block builder
Browse files Browse the repository at this point in the history
  • Loading branch information
alonh5 committed Jan 20, 2025
1 parent 6f9eaaf commit fa9534d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
25 changes: 17 additions & 8 deletions crates/starknet_batcher/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@ async fn collect_execution_results_and_stream_txs(
output_content_sender: &Option<tokio::sync::mpsc::UnboundedSender<Transaction>>,
fail_on_err: bool,
) -> BlockBuilderResult<bool> {
assert!(
results.len() <= tx_chunk.len(),
"The number of results should be less than or equal to the number of transactions."
);
let mut block_is_full = false;
// If the block is full, we won't get an error from the executor. We will just get only the
// results of the transactions that were executed before the block was full.
// see [TransactionExecutor::execute_txs].
if results.len() < tx_chunk.len() {
info!("Block is full.");
if fail_on_err {
return Err(BlockBuilderError::FailOnError(FailOnErrorCause::BlockFull));
} else {
block_is_full = true;
}
}
for (input_tx, result) in tx_chunk.into_iter().zip(results.into_iter()) {
match result {
Ok(tx_execution_info) => {
Expand All @@ -245,13 +261,6 @@ async fn collect_execution_results_and_stream_txs(
}
// TODO(yael 18/9/2024): add timeout error handling here once this
// feature is added.
Err(BlockifierTransactionExecutorError::BlockFull) => {
info!("Block is full");
if fail_on_err {
return Err(BlockBuilderError::FailOnError(FailOnErrorCause::BlockFull));
}
return Ok(true);
}
Err(err) => {
debug!("Transaction {:?} failed with error: {}.", input_tx, err);
if fail_on_err {
Expand All @@ -263,7 +272,7 @@ async fn collect_execution_results_and_stream_txs(
}
}
}
Ok(false)
Ok(block_is_full)
}

pub struct BlockMetadata {
Expand Down
5 changes: 4 additions & 1 deletion crates/starknet_batcher/src/block_builder_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,14 @@ fn empty_block_test_expectations() -> TestExpectations {
fn mock_transaction_executor_block_full(input_txs: &[Transaction]) -> MockTransactionExecutorTrait {
let input_txs_cloned = input_txs.to_vec();
let mut mock_transaction_executor = MockTransactionExecutorTrait::new();
let execution_results = vec![Ok(execution_info())];
// When the block is full, the executor will return less results than the number of input txs.
assert!(input_txs.len() > execution_results.len());
mock_transaction_executor
.expect_add_txs_to_block()
.times(1)
.withf(move |blockifier_input| compare_tx_hashes(&input_txs_cloned, blockifier_input))
.return_once(move |_| vec![Ok(execution_info()), Err(TransactionExecutorError::BlockFull)]);
.return_once(move |_| execution_results);
mock_transaction_executor
}

Expand Down

0 comments on commit fa9534d

Please sign in to comment.