From d6a003788120adfd70621b8973cda44eb3253640 Mon Sep 17 00:00:00 2001 From: Ammar Arif Date: Fri, 18 Oct 2024 20:19:54 -0400 Subject: [PATCH] refactor: replace starknet cfg with execution cfg --- bin/katana/src/cli/node.rs | 36 +++++++++++----------- crates/dojo-test-utils/src/sequencer.rs | 3 +- crates/katana/core/src/backend/config.rs | 29 ----------------- crates/katana/core/src/backend/mod.rs | 5 --- crates/katana/core/src/constants.rs | 5 --- crates/katana/node/src/config/dev.rs | 8 ++++- crates/katana/node/src/config/execution.rs | 21 +++++++++++++ crates/katana/node/src/config/mod.rs | 7 +++-- crates/katana/node/src/lib.rs | 8 ++--- 9 files changed, 54 insertions(+), 68 deletions(-) delete mode 100644 crates/katana/core/src/backend/config.rs create mode 100644 crates/katana/node/src/config/execution.rs diff --git a/bin/katana/src/cli/node.rs b/bin/katana/src/cli/node.rs index 6c56d56d22..c397ab9a49 100644 --- a/bin/katana/src/cli/node.rs +++ b/bin/katana/src/cli/node.rs @@ -19,14 +19,15 @@ use anyhow::{Context, Result}; use clap::{Args, Parser}; use console::Style; use dojo_utils::parse::parse_socket_address; -use katana_core::backend::config::{Environment, StarknetConfig}; use katana_core::constants::{ - DEFAULT_ETH_L1_GAS_PRICE, DEFAULT_INVOKE_MAX_STEPS, DEFAULT_SEQUENCER_ADDRESS, - DEFAULT_STRK_L1_GAS_PRICE, DEFAULT_VALIDATE_MAX_STEPS, + DEFAULT_ETH_L1_GAS_PRICE, DEFAULT_SEQUENCER_ADDRESS, DEFAULT_STRK_L1_GAS_PRICE, }; use katana_core::service::messaging::MessagingConfig; use katana_node::config::db::DbConfig; use katana_node::config::dev::DevConfig; +use katana_node::config::execution::{ + ExecutionConfig, DEFAULT_INVOCATION_MAX_STEPS, DEFAULT_VALIDATION_MAX_STEPS, +}; use katana_node::config::fork::ForkingConfig; use katana_node::config::metrics::MetricsConfig; use katana_node::config::rpc::{ @@ -188,12 +189,12 @@ pub struct EnvironmentOptions { #[arg(long)] #[arg(help = "The maximum number of steps available for the account validation logic.")] - #[arg(default_value_t = DEFAULT_VALIDATE_MAX_STEPS)] + #[arg(default_value_t = DEFAULT_VALIDATION_MAX_STEPS)] pub validate_max_steps: u32, #[arg(long)] #[arg(help = "The maximum number of steps available for the account execution logic.")] - #[arg(default_value_t = DEFAULT_INVOKE_MAX_STEPS)] + #[arg(default_value_t = DEFAULT_INVOCATION_MAX_STEPS)] pub invoke_max_steps: u32, #[arg(long = "eth-gas-price")] @@ -282,12 +283,12 @@ impl NodeArgs { let dev = self.dev_config(); let chain = self.chain_spec()?; let metrics = self.metrics_config(); - let starknet = self.starknet_config()?; let forking = self.forking_config()?; + let execution = self.execution_config(); let sequencing = self.sequencer_config(); let messaging = self.messaging.clone(); - Ok(Config { metrics, db, dev, rpc, chain, starknet, sequencing, messaging, forking }) + Ok(Config { metrics, db, dev, rpc, chain, execution, sequencing, messaging, forking }) } fn sequencer_config(&self) -> SequencingConfig { @@ -347,13 +348,12 @@ impl NodeArgs { } } - fn starknet_config(&self) -> Result { - Ok(StarknetConfig { - env: Environment { - invoke_max_steps: self.starknet.environment.invoke_max_steps, - validate_max_steps: self.starknet.environment.validate_max_steps, - }, - }) + fn execution_config(&self) -> ExecutionConfig { + ExecutionConfig { + invocation_max_steps: self.starknet.environment.invoke_max_steps, + validation_max_steps: self.starknet.environment.validate_max_steps, + ..Default::default() + } } fn forking_config(&self) -> Result> { @@ -497,8 +497,8 @@ mod test { assert!(config.dev.fee); assert!(config.dev.account_validation); assert!(config.forking.is_none()); - assert_eq!(config.starknet.env.invoke_max_steps, DEFAULT_INVOKE_MAX_STEPS); - assert_eq!(config.starknet.env.validate_max_steps, DEFAULT_VALIDATE_MAX_STEPS); + assert_eq!(config.execution.invocation_max_steps, DEFAULT_INVOCATION_MAX_STEPS); + assert_eq!(config.execution.validation_max_steps, DEFAULT_VALIDATION_MAX_STEPS); assert_eq!(config.db.dir, None); assert_eq!(config.chain.id, ChainId::parse("KATANA").unwrap()); assert_eq!(config.chain.genesis.gas_prices.eth, DEFAULT_ETH_L1_GAS_PRICE); @@ -529,8 +529,8 @@ mod test { assert!(!config.dev.fee); assert!(!config.dev.account_validation); - assert_eq!(config.starknet.env.invoke_max_steps, 200); - assert_eq!(config.starknet.env.validate_max_steps, 100); + assert_eq!(config.execution.invocation_max_steps, 200); + assert_eq!(config.execution.validation_max_steps, 100); assert_eq!(config.db.dir, Some(PathBuf::from("/path/to/db"))); assert_eq!(config.chain.id, ChainId::GOERLI); assert_eq!(config.chain.genesis.gas_prices.eth, 10); diff --git a/crates/dojo-test-utils/src/sequencer.rs b/crates/dojo-test-utils/src/sequencer.rs index 87a795812c..99acaf4b8c 100644 --- a/crates/dojo-test-utils/src/sequencer.rs +++ b/crates/dojo-test-utils/src/sequencer.rs @@ -2,13 +2,12 @@ use std::collections::HashSet; use std::sync::Arc; use jsonrpsee::core::Error; -pub use katana_core::backend::config::{Environment, StarknetConfig}; use katana_core::backend::Backend; use katana_core::constants::DEFAULT_SEQUENCER_ADDRESS; use katana_executor::implementation::blockifier::BlockifierFactory; use katana_node::config::dev::DevConfig; use katana_node::config::rpc::{ApiKind, RpcConfig, DEFAULT_RPC_ADDR, DEFAULT_RPC_MAX_CONNECTIONS}; -use katana_node::config::{Config, SequencingConfig}; +pub use katana_node::config::*; use katana_node::LaunchedNode; use katana_primitives::chain::ChainId; use katana_primitives::chain_spec::ChainSpec; diff --git a/crates/katana/core/src/backend/config.rs b/crates/katana/core/src/backend/config.rs deleted file mode 100644 index b4c2922d89..0000000000 --- a/crates/katana/core/src/backend/config.rs +++ /dev/null @@ -1,29 +0,0 @@ -use crate::constants::{DEFAULT_INVOKE_MAX_STEPS, DEFAULT_VALIDATE_MAX_STEPS}; -use crate::env::BlockContextGenerator; - -#[derive(Debug, Clone, Default)] -pub struct StarknetConfig { - pub env: Environment, -} - -impl StarknetConfig { - pub fn block_context_generator(&self) -> BlockContextGenerator { - BlockContextGenerator::default() - } -} - -// TODO: i think block limits should be included in chain spec -#[derive(Debug, Clone)] -pub struct Environment { - pub invoke_max_steps: u32, - pub validate_max_steps: u32, -} - -impl Default for Environment { - fn default() -> Self { - Self { - invoke_max_steps: DEFAULT_INVOKE_MAX_STEPS, - validate_max_steps: DEFAULT_VALIDATE_MAX_STEPS, - } - } -} diff --git a/crates/katana/core/src/backend/mod.rs b/crates/katana/core/src/backend/mod.rs index 0287887f93..d8c957b538 100644 --- a/crates/katana/core/src/backend/mod.rs +++ b/crates/katana/core/src/backend/mod.rs @@ -13,11 +13,9 @@ use katana_provider::traits::block::{BlockHashProvider, BlockWriter}; use parking_lot::RwLock; use tracing::info; -pub mod config; pub mod contract; pub mod storage; -use self::config::StarknetConfig; use self::storage::Blockchain; use crate::env::BlockContextGenerator; use crate::service::block_producer::{BlockProductionError, MinedBlockOutcome}; @@ -27,9 +25,6 @@ pub(crate) const LOG_TARGET: &str = "katana::core::backend"; #[derive(Debug)] pub struct Backend { - /// The config used to generate the backend. - pub config: StarknetConfig, - pub chain_spec: ChainSpec, /// stores all block related data in memory pub blockchain: Blockchain, diff --git a/crates/katana/core/src/constants.rs b/crates/katana/core/src/constants.rs index 7cfe3555b5..0d5a31b24f 100644 --- a/crates/katana/core/src/constants.rs +++ b/crates/katana/core/src/constants.rs @@ -6,11 +6,6 @@ use starknet::macros::felt; pub const DEFAULT_ETH_L1_GAS_PRICE: u128 = 100 * u128::pow(10, 9); // Given in units of Wei. pub const DEFAULT_STRK_L1_GAS_PRICE: u128 = 100 * u128::pow(10, 9); // Given in units of STRK. -pub const DEFAULT_INVOKE_MAX_STEPS: u32 = 10_000_000; -pub const DEFAULT_VALIDATE_MAX_STEPS: u32 = 1_000_000; - -pub const MAX_RECURSION_DEPTH: usize = 1000; - lazy_static! { // Predefined contract addresses diff --git a/crates/katana/node/src/config/dev.rs b/crates/katana/node/src/config/dev.rs index e5030d8842..bd1dce94cf 100644 --- a/crates/katana/node/src/config/dev.rs +++ b/crates/katana/node/src/config/dev.rs @@ -1,5 +1,5 @@ /// Development configuration. -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone)] pub struct DevConfig { /// Whether to enable paying fees for transactions. /// @@ -21,3 +21,9 @@ pub struct DevConfig { /// validation is disabled is a no-op. pub account_validation: bool, } + +impl std::default::Default for DevConfig { + fn default() -> Self { + Self { fee: true, account_validation: true } + } +} diff --git a/crates/katana/node/src/config/execution.rs b/crates/katana/node/src/config/execution.rs new file mode 100644 index 0000000000..69db1edb83 --- /dev/null +++ b/crates/katana/node/src/config/execution.rs @@ -0,0 +1,21 @@ +pub const MAX_RECURSION_DEPTH: usize = 1000; + +pub const DEFAULT_INVOCATION_MAX_STEPS: u32 = 10_000_000; +pub const DEFAULT_VALIDATION_MAX_STEPS: u32 = 1_000_000; + +#[derive(Debug, Clone)] +pub struct ExecutionConfig { + pub invocation_max_steps: u32, + pub validation_max_steps: u32, + pub max_recursion_depth: usize, +} + +impl std::default::Default for ExecutionConfig { + fn default() -> Self { + Self { + max_recursion_depth: MAX_RECURSION_DEPTH, + invocation_max_steps: DEFAULT_INVOCATION_MAX_STEPS, + validation_max_steps: DEFAULT_VALIDATION_MAX_STEPS, + } + } +} diff --git a/crates/katana/node/src/config/mod.rs b/crates/katana/node/src/config/mod.rs index 1c9fa68041..b79ae25a97 100644 --- a/crates/katana/node/src/config/mod.rs +++ b/crates/katana/node/src/config/mod.rs @@ -1,13 +1,14 @@ pub mod db; pub mod dev; +pub mod execution; pub mod fork; pub mod metrics; pub mod rpc; use db::DbConfig; use dev::DevConfig; +use execution::ExecutionConfig; use fork::ForkingConfig; -use katana_core::backend::config::StarknetConfig; use katana_core::service::messaging::MessagingConfig; use katana_primitives::chain_spec::ChainSpec; use metrics::MetricsConfig; @@ -33,8 +34,8 @@ pub struct Config { /// Metrics options. pub metrics: Option, - /// Starknet options. - pub starknet: StarknetConfig, + /// Execution options. + pub execution: ExecutionConfig, /// Messaging options. pub messaging: Option, diff --git a/crates/katana/node/src/lib.rs b/crates/katana/node/src/lib.rs index 09ccd54d1e..253f54b3fb 100644 --- a/crates/katana/node/src/lib.rs +++ b/crates/katana/node/src/lib.rs @@ -20,7 +20,6 @@ use jsonrpsee::server::{AllowHosts, ServerBuilder, ServerHandle}; use jsonrpsee::RpcModule; use katana_core::backend::storage::Blockchain; use katana_core::backend::Backend; -use katana_core::constants::MAX_RECURSION_DEPTH; use katana_core::env::BlockContextGenerator; use katana_core::service::block_producer::BlockProducer; use katana_core::service::messaging::MessagingConfig; @@ -165,9 +164,9 @@ pub async fn build(mut config: Config) -> Result { let cfg_env = CfgEnv { chain_id: config.chain.id, - invoke_tx_max_n_steps: config.starknet.env.invoke_max_steps, - validate_max_n_steps: config.starknet.env.validate_max_steps, - max_recursion_depth: MAX_RECURSION_DEPTH, + invoke_tx_max_n_steps: config.execution.invocation_max_steps, + validate_max_n_steps: config.execution.validation_max_steps, + max_recursion_depth: config.execution.max_recursion_depth, fee_token_addresses: FeeTokenAddressses { eth: config.chain.fee_contracts.eth, strk: config.chain.fee_contracts.strk, @@ -199,7 +198,6 @@ pub async fn build(mut config: Config) -> Result { blockchain, executor_factory, block_context_generator, - config: config.starknet, chain_spec: config.chain, });