Skip to content

Commit

Permalink
remove from CfgEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Feb 17, 2025
1 parent 74c7c8c commit 44c2570
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
5 changes: 5 additions & 0 deletions crates/katana/cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,8 @@ fn default_metrics_addr() -> IpAddr {
fn default_metrics_port() -> u16 {
DEFAULT_METRICS_PORT
}

#[cfg(feature = "server")]
fn default_max_call_gas() -> u64 {
DEFAULT_RPC_MAX_CALL_GAS
}
19 changes: 16 additions & 3 deletions crates/katana/executor/src/implementation/blockifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@ pub struct BlockifierFactory {
cfg: CfgEnv,
flags: ExecutionFlags,
limits: BlockLimits,
max_call_gas: u64,
}

impl BlockifierFactory {
/// Create a new factory with the given configuration and simulation flags.
pub fn new(cfg: CfgEnv, flags: ExecutionFlags, limits: BlockLimits) -> Self {
Self { cfg, flags, limits }
Self { cfg, flags, limits, max_call_gas: 1_000_000_000 }
}

pub fn set_max_call_gas(&mut self, max_call_gas: u64) {
self.max_call_gas = max_call_gas;
}
}

Expand All @@ -72,7 +77,14 @@ impl ExecutorFactory for BlockifierFactory {
let cfg_env = self.cfg.clone();
let flags = self.flags.clone();
let limits = self.limits.clone();
Box::new(StarknetVMProcessor::new(Box::new(state), block_env, cfg_env, flags, limits))
Box::new(StarknetVMProcessor::new(
Box::new(state),
block_env,
cfg_env,
flags,
limits,
self.max_call_gas,
))
}

fn cfg(&self) -> &CfgEnv {
Expand Down Expand Up @@ -103,6 +115,7 @@ impl<'a> StarknetVMProcessor<'a> {
cfg_env: CfgEnv,
simulation_flags: ExecutionFlags,
limits: BlockLimits,
max_call_gas: u64,
) -> Self {
let transactions = Vec::new();
let block_context = utils::block_context_from_envs(&block_env, &cfg_env);
Expand All @@ -119,7 +132,7 @@ impl<'a> StarknetVMProcessor<'a> {
simulation_flags,
stats: Default::default(),
bouncer,
max_call_gas: cfg_env.max_call_gas,
max_call_gas,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/katana/node/src/config/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub const DEFAULT_RPC_MAX_EVENT_PAGE_SIZE: u64 = 1024;
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
15 changes: 10 additions & 5 deletions crates/katana/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,16 @@ pub async fn build(mut config: Config) -> Result<Node> {
.with_account_validation(config.dev.account_validation)
.with_fee(config.dev.fee);

let executor_factory = Arc::new(BlockifierFactory::new(
cfg_env,
execution_flags,
config.sequencing.block_limits(),
));
let executor_factory = {
let mut factory =
BlockifierFactory::new(cfg_env, execution_flags, config.sequencing.block_limits());

if let Some(max_call_gas) = config.rpc.max_call_gas {
factory.set_max_call_gas(max_call_gas);
}

Arc::new(factory)
};

// --- build backend

Expand Down
2 changes: 0 additions & 2 deletions crates/katana/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ 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 44c2570

Please sign in to comment.