Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
chore: move max_capacity selection to BouncerConfig (#1941)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoni-Starkware authored Jun 3, 2024
1 parent b54fb18 commit e042a43
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions crates/blockifier/src/bouncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ impl BouncerConfig {
block_max_capacity: BouncerWeights::max(false),
}
}

pub fn has_room(&self, weights: BouncerWeights) -> bool {
let max_capacity = if weights.builtin_count.keccak > 0 {
self.block_max_capacity_with_keccak
} else {
self.block_max_capacity
};

max_capacity.has_room(weights)
}
}

#[derive(
Expand Down Expand Up @@ -216,19 +226,13 @@ impl Bouncer {
&state_changes_keys,
)?;

let mut max_capacity = self.bouncer_config.block_max_capacity;
if self.accumulated_weights.builtin_count.keccak > 0 || tx_weights.builtin_count.keccak > 0
{
max_capacity = self.bouncer_config.block_max_capacity_with_keccak;
}

// Check if the transaction is too large to fit any block.
if !max_capacity.has_room(tx_weights) {
if !self.bouncer_config.has_room(tx_weights) {
Err(TransactionExecutionError::TransactionTooLarge)?
}

// Check if the transaction can fit the current block available capacity.
if !max_capacity.has_room(self.accumulated_weights + tx_weights) {
if !self.bouncer_config.has_room(self.accumulated_weights + tx_weights) {
log::debug!(
"Transaction cannot be added to the current block, block capacity reached; \
transaction weights: {tx_weights:?}, block weights: {:?}.",
Expand Down

0 comments on commit e042a43

Please sign in to comment.