From c408c2b5c04d7333948b0ce56d21deff23934ec7 Mon Sep 17 00:00:00 2001 From: Naman Garg <0708ng@gmail.com> Date: Fri, 19 Jul 2024 12:38:38 +0530 Subject: [PATCH] chore(sidecar): fix mutable borrow conflict --- bolt-sidecar/src/state/execution.rs | 37 +++++++++++++++++++---------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/bolt-sidecar/src/state/execution.rs b/bolt-sidecar/src/state/execution.rs index 4ab08d938..0be10e9f4 100644 --- a/bolt-sidecar/src/state/execution.rs +++ b/bolt-sidecar/src/state/execution.rs @@ -207,20 +207,23 @@ impl ExecutionState { 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::() >= self.max_committed_gas_per_slot.get() { + if template.committed_gas().to::() >= max_committed_gas_per_slot { return Err(ValidationError::MaxCommittedGasReachedForSlot( self.slot, - self.max_committed_gas_per_slot.get(), + max_committed_gas_per_slot, )); } } @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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();