Skip to content

Commit

Permalink
chore(sidecar): fix mutable borrow conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
namn-grg committed Jul 19, 2024
1 parent 1470eb8 commit c408c2b
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions bolt-sidecar/src/state/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,23 @@ impl<C: StateFetcher> ExecutionState<C> {
return Err(ValidationError::ChainIdMismatch);
}

// Check if there is room for more commitments
let max_commitments_per_slot = self.max_commitments_per_slot.get();
let max_committed_gas_per_slot = self.max_committed_gas_per_slot.get();

// Check if there is room for more commitments and gas in the block template
if let Some(template) = self.get_block_template(target_slot) {
if template.transactions_len() >= self.max_commitments_per_slot.get() {
if template.transactions_len() >= max_commitments_per_slot {
return Err(ValidationError::MaxCommitmentsReachedForSlot(
self.slot,
self.max_commitments_per_slot.get(),
max_commitments_per_slot,
));
}

// Check if the committed gas exceeds the maximum
if template.committed_gas().to::<u64>() >= self.max_committed_gas_per_slot.get() {
if template.committed_gas().to::<u64>() >= max_committed_gas_per_slot {
return Err(ValidationError::MaxCommittedGasReachedForSlot(
self.slot,
self.max_committed_gas_per_slot.get(),
max_committed_gas_per_slot,
));
}
}
Expand Down Expand Up @@ -476,7 +479,8 @@ mod tests {
let client = StateClient::new(anvil.endpoint_url());

let max_comms = NonZero::new(10).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms).await?;
let max_gas = NonZero::new(10_000_000).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms, max_gas).await?;

let sender = anvil.addresses().first().unwrap();
let sender_pk = anvil.keys().first().unwrap();
Expand All @@ -502,7 +506,8 @@ mod tests {
let client = StateClient::new(anvil.endpoint_url());

let max_comms = NonZero::new(10).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms).await?;
let max_gas = NonZero::new(10_000_000).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms, max_gas).await?;

let sender = anvil.addresses().first().unwrap();
let sender_pk = anvil.keys().first().unwrap();
Expand Down Expand Up @@ -543,7 +548,8 @@ mod tests {
let client = StateClient::new(anvil.endpoint_url());

let max_comms = NonZero::new(10).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms).await?;
let max_gas = NonZero::new(10_000_000).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms, max_gas).await?;

let sender = anvil.addresses().first().unwrap();
let sender_pk = anvil.keys().first().unwrap();
Expand Down Expand Up @@ -596,7 +602,8 @@ mod tests {
let client = StateClient::new(anvil.endpoint_url());

let max_comms = NonZero::new(10).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms).await?;
let max_gas = NonZero::new(10_000_000).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms, max_gas).await?;

let sender = anvil.addresses().first().unwrap();
let sender_pk = anvil.keys().first().unwrap();
Expand Down Expand Up @@ -627,7 +634,8 @@ mod tests {
let client = StateClient::new(anvil.endpoint_url());

let max_comms = NonZero::new(10).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms).await?;
let max_gas = NonZero::new(10_000_000).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms, max_gas).await?;

let sender = anvil.addresses().first().unwrap();
let sender_pk = anvil.keys().first().unwrap();
Expand Down Expand Up @@ -690,7 +698,8 @@ mod tests {
let client = StateClient::new(anvil.endpoint_url());

let max_comms = NonZero::new(10).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms).await?;
let max_gas = NonZero::new(10_000_000).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms, max_gas).await?;

let basefee = state.basefee();

Expand Down Expand Up @@ -725,7 +734,8 @@ mod tests {
let provider = ProviderBuilder::new().on_http(anvil.endpoint_url());

let max_comms = NonZero::new(10).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms).await?;
let max_gas = NonZero::new(10_000_000).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms, max_gas).await?;

let sender = anvil.addresses().first().unwrap();
let sender_pk = anvil.keys().first().unwrap();
Expand Down Expand Up @@ -792,7 +802,8 @@ mod tests {
let client = StateClient::new(anvil.endpoint_url());

let max_comms = NonZero::new(10).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms).await?;
let max_gas = NonZero::new(10_000_000).unwrap();
let mut state = ExecutionState::new(client.clone(), max_comms, max_gas).await?;

let sender = anvil.addresses().first().unwrap();
let sender_pk = anvil.keys().first().unwrap();
Expand Down

0 comments on commit c408c2b

Please sign in to comment.