Skip to content

Commit

Permalink
feat(katana): configurable max gas for rpc call
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Feb 17, 2025
1 parent ce8c3f7 commit 74c7c8c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/katana/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ impl NodeArgs {
cors_origins: self.server.http_cors_origins.clone(),
max_event_page_size: Some(self.server.max_event_page_size),
max_proof_keys: Some(self.server.max_proof_keys),
max_call_gas: Some(self.server.max_call_gas),
})
}

Expand Down
8 changes: 8 additions & 0 deletions crates/katana/cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use clap::Args;
use katana_node::config::execution::{DEFAULT_INVOCATION_MAX_STEPS, DEFAULT_VALIDATION_MAX_STEPS};
#[cfg(feature = "server")]
use katana_node::config::metrics::{DEFAULT_METRICS_ADDR, DEFAULT_METRICS_PORT};
use katana_node::config::rpc::DEFAULT_RPC_MAX_CALL_GAS;
#[cfg(feature = "server")]
use katana_node::config::rpc::{RpcModulesList, DEFAULT_RPC_MAX_PROOF_KEYS};
#[cfg(feature = "server")]
Expand Down Expand Up @@ -128,6 +129,12 @@ pub struct ServerOptions {
#[arg(default_value_t = DEFAULT_RPC_MAX_PROOF_KEYS)]
#[serde(default = "default_proof_keys")]
pub max_proof_keys: u64,

/// Maximum gas for the `starknet_call` RPC method.
#[arg(long = "rpc.max-call-gas", value_name = "GAS")]
#[arg(default_value_t = DEFAULT_RPC_MAX_CALL_GAS)]
#[serde(default = "default_max_call_gas")]
pub max_call_gas: u64,
}

#[cfg(feature = "server")]
Expand All @@ -143,6 +150,7 @@ impl Default for ServerOptions {
max_connections: None,
max_request_body_size: None,
max_response_body_size: None,
max_call_gas: DEFAULT_RPC_MAX_CALL_GAS,
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/katana/executor/src/implementation/blockifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub struct StarknetVMProcessor<'a> {
simulation_flags: ExecutionFlags,
stats: ExecutionStats,
bouncer: Bouncer,
max_call_gas: u64,
}

impl<'a> StarknetVMProcessor<'a> {
Expand All @@ -118,6 +119,7 @@ impl<'a> StarknetVMProcessor<'a> {
simulation_flags,
stats: Default::default(),
bouncer,
max_call_gas: cfg_env.max_call_gas,
}
}

Expand Down Expand Up @@ -329,7 +331,7 @@ impl ExecutorExt for StarknetVMProcessor<'_> {
let block_context = &self.block_context;
let mut state = self.state.inner.lock();
let state = MutRefState::new(&mut state.cached_state);
let retdata = call::execute_call(call, state, block_context, 1_000_000_000)?;
let retdata = call::execute_call(call, state, block_context, self.max_call_gas)?;
Ok(retdata)
}
}
11 changes: 11 additions & 0 deletions crates/katana/node-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pub struct Katana {
http_addr: Option<SocketAddr>,
http_port: Option<u16>,
rpc_max_connections: Option<u64>,
rpc_max_call_gas: Option<u64>,
http_cors_domain: Option<String>,

// Dev options
Expand Down Expand Up @@ -326,6 +327,12 @@ impl Katana {
self
}

/// Sets the maximum gas for the `starknet_call` RPC method.
pub const fn rpc_max_call_gas(mut self, max_call_gas: u64) -> Self {
self.rpc_max_call_gas = Some(max_call_gas);
self
}

/// Enables the CORS layer and sets the allowed origins, separated by commas.
pub fn http_cors_domain<T: Into<String>>(mut self, allowed_origins: T) -> Self {
self.http_cors_domain = Some(allowed_origins.into());
Expand Down Expand Up @@ -525,6 +532,10 @@ impl Katana {
cmd.arg("--rpc.max-connections").arg(max_connections.to_string());
}

if let Some(max_call_gas) = self.rpc_max_call_gas {
cmd.arg("--rpc.max-call-gas").arg(max_call_gas.to_string());
}

if let Some(allowed_origins) = self.http_cors_domain {
cmd.arg("--http.corsdomain").arg(allowed_origins);
}
Expand Down
5 changes: 4 additions & 1 deletion crates/katana/node/src/config/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ pub const DEFAULT_RPC_PORT: u16 = 5050;
pub const DEFAULT_RPC_MAX_EVENT_PAGE_SIZE: u64 = 1024;
/// Default maximmum number of keys for the `starknet_getStorageProof` RPC method.
pub const DEFAULT_RPC_MAX_PROOF_KEYS: u64 = 100;

/// Default maximum gas for the `starknet_call` RPC method.
pub const DEFAULT_RPC_MAX_CALL_GAS: u64 = 1_000_000_000;
/// List of RPC modules supported by Katana.
#[derive(
Debug,
Expand Down Expand Up @@ -45,6 +46,7 @@ pub struct RpcConfig {
pub max_response_body_size: Option<u32>,
pub max_proof_keys: Option<u64>,
pub max_event_page_size: Option<u64>,
pub max_call_gas: Option<u64>,
}

impl RpcConfig {
Expand All @@ -66,6 +68,7 @@ impl Default for RpcConfig {
apis: RpcModulesList::default(),
max_event_page_size: Some(DEFAULT_RPC_MAX_EVENT_PAGE_SIZE),
max_proof_keys: Some(DEFAULT_RPC_MAX_PROOF_KEYS),
max_call_gas: Some(DEFAULT_RPC_MAX_CALL_GAS),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/katana/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub struct CfgEnv {
pub validate_max_n_steps: u32,
/// The maximum recursion depth allowed.
pub max_recursion_depth: usize,
/// The maximum gas allowed for the `starknet_call` RPC method.
pub max_call_gas: u64,
}

/// The contract addresses of the tokens used for the fees.
Expand Down

0 comments on commit 74c7c8c

Please sign in to comment.