Skip to content

Commit

Permalink
chore(sidecar): solve nits
Browse files Browse the repository at this point in the history
  • Loading branch information
namn-grg committed Jul 19, 2024
1 parent fbe8559 commit 6e3aae9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bolt-sidecar/bin/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async fn main() -> eyre::Result<()> {
let signer = Signer::new(config.private_key.clone().unwrap());

let state_client = StateClient::new(config.execution_api_url.clone());
let mut execution_state = ExecutionState::new(state_client, config.limits.clone()).await?;
let mut execution_state = ExecutionState::new(state_client, config.limits).await?;

let mevboost_client = MevBoostClient::new(config.mevboost_url.clone());
let beacon_client = BeaconClient::new(config.beacon_api_url.clone());
Expand Down
2 changes: 1 addition & 1 deletion bolt-sidecar/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl Default for Config {
}

/// Limits for the sidecar.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy)]
pub struct Limits {
/// Maximum number of commitments to accept per block
pub max_commitments_per_slot: NonZero<usize>,
Expand Down
21 changes: 10 additions & 11 deletions bolt-sidecar/src/state/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy_transport::TransportError;
use reth_primitives::{
revm_primitives::EnvKzgSettings, BlobTransactionValidationError, PooledTransactionsElement,
};
use std::{collections::HashMap, num::NonZero};
use std::collections::HashMap;
use thiserror::Error;

use crate::{
Expand Down Expand Up @@ -115,10 +115,8 @@ pub struct ExecutionState<C> {
block_templates: HashMap<Slot, BlockTemplate>,
/// The chain ID of the chain (constant).
chain_id: u64,
/// The maximum number of commitments per slot.
max_commitments_per_slot: NonZero<usize>,
/// The maximum committed gas per slot.
max_committed_gas_per_slot: NonZero<u64>,
/// The limits set for the sidecar.
limits: Limits,
/// The KZG settings for validating blobs.
kzg_settings: EnvKzgSettings,
/// The state fetcher client.
Expand Down Expand Up @@ -161,8 +159,7 @@ impl<C: StateFetcher> ExecutionState<C> {
blob_basefee,
block_number,
chain_id,
max_commitments_per_slot: limits.max_commitments_per_slot,
max_committed_gas_per_slot: limits.max_committed_gas_per_slot,
limits,
client,
slot: 0,
account_states: HashMap::new(),
Expand Down Expand Up @@ -206,10 +203,10 @@ impl<C: StateFetcher> ExecutionState<C> {

// Check if there is room for more commitments
if let Some(template) = self.get_block_template(target_slot) {
if template.transactions_len() >= self.max_commitments_per_slot.get() {
if template.transactions_len() >= self.limits.max_commitments_per_slot.get() {
return Err(ValidationError::MaxCommitmentsReachedForSlot(
self.slot,
self.max_commitments_per_slot.get(),
self.limits.max_commitments_per_slot.get(),
));
}
}
Expand All @@ -219,10 +216,12 @@ impl<C: StateFetcher> ExecutionState<C> {
.get_block_template(target_slot)
.map(|t| t.committed_gas())
.unwrap_or(0);
if template_committed_gas + req.tx.gas_limit() >= self.max_committed_gas_per_slot.get() {
if template_committed_gas + req.tx.gas_limit()
>= self.limits.max_committed_gas_per_slot.get()
{
return Err(ValidationError::MaxCommittedGasReachedForSlot(
self.slot,
self.max_committed_gas_per_slot.get(),
self.limits.max_committed_gas_per_slot.get(),
));
}

Expand Down

0 comments on commit 6e3aae9

Please sign in to comment.