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

refactor(katana): rename starknet config to execution config #2557

Merged
merged 1 commit into from
Oct 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
36 changes: 18 additions & 18 deletions bin/katana/src/cli/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -347,13 +348,12 @@ impl NodeArgs {
}
}

fn starknet_config(&self) -> Result<StarknetConfig> {
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<Option<ForkingConfig>> {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions crates/dojo-test-utils/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 0 additions & 29 deletions crates/katana/core/src/backend/config.rs

This file was deleted.

5 changes: 0 additions & 5 deletions crates/katana/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -27,9 +25,6 @@ pub(crate) const LOG_TARGET: &str = "katana::core::backend";

#[derive(Debug)]
pub struct Backend<EF: ExecutorFactory> {
/// The config used to generate the backend.
pub config: StarknetConfig,

pub chain_spec: ChainSpec,
/// stores all block related data in memory
pub blockchain: Blockchain,
Expand Down
5 changes: 0 additions & 5 deletions crates/katana/core/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion crates/katana/node/src/config/dev.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Development configuration.
#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone)]
pub struct DevConfig {
/// Whether to enable paying fees for transactions.
///
Expand All @@ -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 }
}
}
21 changes: 21 additions & 0 deletions crates/katana/node/src/config/execution.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
}
7 changes: 4 additions & 3 deletions crates/katana/node/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -33,8 +34,8 @@ pub struct Config {
/// Metrics options.
pub metrics: Option<MetricsConfig>,

/// Starknet options.
pub starknet: StarknetConfig,
/// Execution options.
pub execution: ExecutionConfig,

/// Messaging options.
pub messaging: Option<MessagingConfig>,
Expand Down
8 changes: 3 additions & 5 deletions crates/katana/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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;
Expand Down Expand Up @@ -165,9 +164,9 @@

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,

Check warning on line 169 in crates/katana/node/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/node/src/lib.rs#L167-L169

Added lines #L167 - L169 were not covered by tests
fee_token_addresses: FeeTokenAddressses {
eth: config.chain.fee_contracts.eth,
strk: config.chain.fee_contracts.strk,
Expand Down Expand Up @@ -199,7 +198,6 @@
blockchain,
executor_factory,
block_context_generator,
config: config.starknet,
chain_spec: config.chain,
});

Expand Down
Loading