Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(bolt-sidecar): get block gas limit from config #594

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions bolt-sidecar/src/config/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub const DEFAULT_COMMITMENT_DEADLINE_IN_MILLIS: u64 = 8_000;
/// Default slot time duration in seconds.
pub const DEFAULT_SLOT_TIME_IN_SECONDS: u64 = 12;

/// Default gas limit for the sidecar.
pub const DEFAULT_GAS_LIMIT: u64 = 30_000_000;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/// The domain mask for signing application-builder messages.
pub const APPLICATION_BUILDER_DOMAIN_MASK: [u8; 4] = [0, 0, 0, 1];

Expand All @@ -31,6 +34,7 @@ pub const DEFAULT_CHAIN_CONFIG: ChainConfig = ChainConfig {
chain: Chain::Mainnet,
commitment_deadline: DEFAULT_COMMITMENT_DEADLINE_IN_MILLIS,
slot_time: DEFAULT_SLOT_TIME_IN_SECONDS,
gas_limit: DEFAULT_GAS_LIMIT,
enable_unsafe_lookahead: false,
};

Expand Down Expand Up @@ -61,6 +65,15 @@ pub struct ChainConfig {
default_value_t = DEFAULT_CHAIN_CONFIG.slot_time,
)]
pub(crate) slot_time: u64,
/// The gas limit for the sidecar.
/// This is the maximum amount of gas that can be used for a single transaction.
/// If provided, it overrides the default for the selected [Chain].
#[clap(
long,
env = "BOLT_SIDECAR_GAS_LIMIT",
default_value_t = DEFAULT_CHAIN_CONFIG.gas_limit
)]
pub(crate) gas_limit: u64,
/// Toggle to enable unsafe lookahead for the sidecar. If `true`, commitments requests will be
/// validated against a two-epoch lookahead window.
#[clap(
Expand Down Expand Up @@ -148,6 +161,11 @@ impl ChainConfig {
self.slot_time
}

/// Get the gas limit for the given chain.
pub fn gas_limit(&self) -> u64 {
self.gas_limit
}

/// Get the domain for signing application-builder messages on the given chain.
pub fn application_builder_domain(&self) -> [u8; 32] {
self.compute_domain_from_mask(APPLICATION_BUILDER_DOMAIN_MASK)
Expand Down
2 changes: 1 addition & 1 deletion bolt-sidecar/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl<C: StateFetcher, ECDSA: SignerECDSA> SidecarDriver<C, ECDSA> {
}

let beacon_client = BeaconClient::new(opts.beacon_api_url.clone());
let execution = ExecutionState::new(fetcher, opts.limits).await?;
let execution = ExecutionState::new(fetcher, opts.limits, opts.chain.gas_limit).await?;

let genesis_time = beacon_client.get_genesis_details().await?.genesis_time;
let slot_stream =
Expand Down
62 changes: 39 additions & 23 deletions bolt-sidecar/src/state/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ pub struct ValidationParams {
pub max_init_code_byte_size: usize,
}

impl Default for ValidationParams {
fn default() -> Self {
impl ValidationParams {
pub fn new(gas_limit: u64) -> Self {
Self {
block_gas_limit: 30_000_000,
block_gas_limit: gas_limit,
max_tx_input_bytes: 4 * 32 * 1024,
max_init_code_byte_size: 2 * 24576,
}
Expand All @@ -189,7 +189,11 @@ impl Default for ValidationParams {
impl<C: StateFetcher> ExecutionState<C> {
/// Creates a new state with the given client, initializing the
/// basefee and head block number.
pub async fn new(client: C, limits: LimitsOpts) -> Result<Self, TransportError> {
pub async fn new(
client: C,
limits: LimitsOpts,
gas_limit: u64,
) -> Result<Self, TransportError> {
let (basefee, blob_basefee, block_number, chain_id) = tokio::try_join!(
client.get_basefee(None),
client.get_blob_basefee(None),
Expand Down Expand Up @@ -217,7 +221,7 @@ impl<C: StateFetcher> ExecutionState<C> {
// Load the default KZG settings
kzg_settings: EnvKzgSettings::default(),
// TODO: add a way to configure these values from CLI
validation_params: ValidationParams::default(),
validation_params: ValidationParams::new(gas_limit),
})
}

Expand Down Expand Up @@ -600,7 +604,8 @@ fn compute_diffs(
mod tests {
use super::*;
use crate::{
builder::template::StateDiff, config::limits::DEFAULT_MAX_COMMITTED_GAS,
builder::template::StateDiff,
config::{chain::DEFAULT_GAS_LIMIT, limits::DEFAULT_MAX_COMMITTED_GAS},
signer::local::LocalSigner,
};
use std::{num::NonZero, str::FromStr, time::Duration};
Expand Down Expand Up @@ -666,7 +671,8 @@ mod tests {
let anvil = launch_anvil();
let client = StateClient::new(anvil.endpoint_url());

let mut state = ExecutionState::new(client.clone(), LimitsOpts::default()).await?;
let mut state =
ExecutionState::new(client.clone(), LimitsOpts::default(), DEFAULT_GAS_LIMIT).await?;

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

let mut state = ExecutionState::new(client.clone(), LimitsOpts::default()).await?;
let mut state =
ExecutionState::new(client.clone(), LimitsOpts::default(), DEFAULT_GAS_LIMIT).await?;

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

let mut state = ExecutionState::new(client.clone(), LimitsOpts::default()).await?;
let mut state =
ExecutionState::new(client.clone(), LimitsOpts::default(), DEFAULT_GAS_LIMIT).await?;

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

let mut state = ExecutionState::new(client.clone(), LimitsOpts::default()).await?;
let mut state =
ExecutionState::new(client.clone(), LimitsOpts::default(), DEFAULT_GAS_LIMIT).await?;

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

let mut state = ExecutionState::new(client.clone(), LimitsOpts::default()).await?;
let mut state =
ExecutionState::new(client.clone(), LimitsOpts::default(), DEFAULT_GAS_LIMIT).await?;

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

let limits = LimitsOpts::default();
let mut state = ExecutionState::new(client.clone(), limits).await?;
let mut state = ExecutionState::new(client.clone(), limits, DEFAULT_GAS_LIMIT).await?;

let basefee = state.basefee();

Expand Down Expand Up @@ -904,7 +914,7 @@ mod tests {
max_committed_gas_per_slot: NonZero::new(5_000_000).unwrap(),
..Default::default()
};
let mut state = ExecutionState::new(client.clone(), limits).await?;
let mut state = ExecutionState::new(client.clone(), limits, DEFAULT_GAS_LIMIT).await?;

let sender = anvil.addresses().first().unwrap();
let sender_pk = anvil.keys().first().unwrap();
Expand Down Expand Up @@ -932,7 +942,7 @@ mod tests {

let limits = LimitsOpts { min_priority_fee: 2 * GWEI_TO_WEI as u128, ..Default::default() };

let mut state = ExecutionState::new(client.clone(), limits).await?;
let mut state = ExecutionState::new(client.clone(), limits, DEFAULT_GAS_LIMIT).await?;

let sender = anvil.addresses().first().unwrap();
let sender_pk = anvil.keys().first().unwrap();
Expand Down Expand Up @@ -970,7 +980,7 @@ mod tests {

let limits = LimitsOpts { min_priority_fee: 2 * GWEI_TO_WEI as u128, ..Default::default() };

let mut state = ExecutionState::new(client.clone(), limits).await?;
let mut state = ExecutionState::new(client.clone(), limits, DEFAULT_GAS_LIMIT).await?;

let sender = anvil.addresses().first().unwrap();
let sender_pk = anvil.keys().first().unwrap();
Expand Down Expand Up @@ -1013,7 +1023,7 @@ mod tests {

let limits = LimitsOpts { min_priority_fee: 2 * GWEI_TO_WEI as u128, ..Default::default() };

let mut state = ExecutionState::new(client.clone(), limits).await?;
let mut state = ExecutionState::new(client.clone(), limits, DEFAULT_GAS_LIMIT).await?;

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

let mut state = ExecutionState::new(client.clone(), LimitsOpts::default()).await?;
let mut state =
ExecutionState::new(client.clone(), LimitsOpts::default(), DEFAULT_GAS_LIMIT).await?;

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

let mut state = ExecutionState::new(client.clone(), LimitsOpts::default()).await?;
let mut state =
ExecutionState::new(client.clone(), LimitsOpts::default(), DEFAULT_GAS_LIMIT).await?;

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

let limits = LimitsOpts { min_priority_fee: 1000000000, ..Default::default() };
let mut state = ExecutionState::new(client.clone(), limits).await?;
let mut state = ExecutionState::new(client.clone(), limits, DEFAULT_GAS_LIMIT).await?;

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

let mut state = ExecutionState::new(client.clone(), LimitsOpts::default()).await?;
let mut state =
ExecutionState::new(client.clone(), LimitsOpts::default(), DEFAULT_GAS_LIMIT).await?;

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

let mut state = ExecutionState::new(client.clone(), LimitsOpts::default()).await?;
let mut state =
ExecutionState::new(client.clone(), LimitsOpts::default(), DEFAULT_GAS_LIMIT).await?;

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

let mut state = ExecutionState::new(client.clone(), LimitsOpts::default()).await?;
let mut state =
ExecutionState::new(client.clone(), LimitsOpts::default(), DEFAULT_GAS_LIMIT).await?;

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

let mut state = ExecutionState::new(client.clone(), LimitsOpts::default()).await?;
let mut state =
ExecutionState::new(client.clone(), LimitsOpts::default(), DEFAULT_GAS_LIMIT).await?;

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