diff --git a/crates/dojo/test-utils/src/sequencer.rs b/crates/dojo/test-utils/src/sequencer.rs index 6d876b3f44..43e154e072 100644 --- a/crates/dojo/test-utils/src/sequencer.rs +++ b/crates/dojo/test-utils/src/sequencer.rs @@ -126,5 +126,5 @@ pub fn get_default_test_config(sequencing: SequencingConfig) -> Config { max_event_page_size: Some(100), }; - Config { sequencing, rpc, dev, chain, ..Default::default() } + Config { sequencing, rpc, dev, chain: chain.into(), ..Default::default() } } diff --git a/crates/katana/cli/src/args.rs b/crates/katana/cli/src/args.rs index 12060a23d5..0c9bf2868d 100644 --- a/crates/katana/cli/src/args.rs +++ b/crates/katana/cli/src/args.rs @@ -2,6 +2,7 @@ use std::collections::HashSet; use std::path::PathBuf; +use std::sync::Arc; use alloy_primitives::U256; use anyhow::{Context, Ok, Result}; @@ -220,7 +221,7 @@ impl NodeArgs { } } - fn chain_spec(&self) -> Result { + fn chain_spec(&self) -> Result> { let mut chain_spec = chain_spec::DEV_UNALLOCATED.clone(); if let Some(id) = self.starknet.environment.chain_id { @@ -246,7 +247,7 @@ impl NodeArgs { katana_slot_controller::add_controller_account(&mut chain_spec.genesis)?; } - Ok(chain_spec) + Ok(Arc::new(chain_spec)) } fn dev_config(&self) -> DevConfig { diff --git a/crates/katana/core/src/backend/mod.rs b/crates/katana/core/src/backend/mod.rs index 7d8d74a142..47908816bc 100644 --- a/crates/katana/core/src/backend/mod.rs +++ b/crates/katana/core/src/backend/mod.rs @@ -33,7 +33,7 @@ pub(crate) const LOG_TARGET: &str = "katana::core::backend"; #[derive(Debug)] pub struct Backend { - pub chain_spec: ChainSpec, + pub chain_spec: Arc, /// stores all block related data in memory pub blockchain: Blockchain, /// The block context generator. diff --git a/crates/katana/node/src/config/mod.rs b/crates/katana/node/src/config/mod.rs index 6e4ace435f..5f94451b16 100644 --- a/crates/katana/node/src/config/mod.rs +++ b/crates/katana/node/src/config/mod.rs @@ -5,6 +5,8 @@ pub mod fork; pub mod metrics; pub mod rpc; +use std::sync::Arc; + use db::DbConfig; use dev::DevConfig; use execution::ExecutionConfig; @@ -21,7 +23,7 @@ use url::Url; #[derive(Debug, Clone, Default)] pub struct Config { /// The chain specification. - pub chain: ChainSpec, + pub chain: Arc, /// Database options. pub db: DbConfig, diff --git a/crates/katana/node/src/lib.rs b/crates/katana/node/src/lib.rs index 6f72916604..7358e70153 100644 --- a/crates/katana/node/src/lib.rs +++ b/crates/katana/node/src/lib.rs @@ -10,9 +10,8 @@ use std::sync::Arc; use std::time::Duration; use anyhow::Result; -use config::metrics::MetricsConfig; use config::rpc::{ApiKind, RpcConfig}; -use config::{Config, SequencingConfig}; +use config::Config; use dojo_metrics::exporters::prometheus::PrometheusRecorder; use dojo_metrics::{Report, Server as MetricsServer}; use hyper::{Method, Uri}; @@ -28,7 +27,6 @@ use katana_core::constants::{ }; use katana_core::env::BlockContextGenerator; use katana_core::service::block_producer::BlockProducer; -use katana_core::service::messaging::MessagingConfig; use katana_db::mdbx::DbEnv; use katana_executor::implementation::blockifier::BlockifierFactory; use katana_executor::{ExecutionFlags, ExecutorFactory}; @@ -91,11 +89,7 @@ pub struct Node { pub task_manager: TaskManager, pub backend: Arc>, pub block_producer: BlockProducer, - pub rpc_config: RpcConfig, - pub metrics_config: Option, - pub sequencing_config: SequencingConfig, - pub messaging_config: Option, - pub l1_provider_url: Option, + pub config: Arc, forked_client: Option, } @@ -108,7 +102,7 @@ impl Node { info!(%chain, "Starting node."); // TODO: maybe move this to the build stage - if let Some(ref cfg) = self.metrics_config { + if let Some(ref cfg) = self.config.metrics { let addr = cfg.socket_addr(); let mut reports: Vec> = Vec::new(); @@ -135,7 +129,7 @@ impl Node { backend.clone(), self.task_manager.task_spawner(), block_producer.clone(), - self.messaging_config.clone(), + self.config.messaging.clone(), ); self.task_manager @@ -146,7 +140,7 @@ impl Node { .spawn(sequencing.into_future()); let node_components = (pool, backend, block_producer, validator, self.forked_client.take()); - let rpc = spawn(node_components, self.rpc_config.clone()).await?; + let rpc = spawn(node_components, self.config.rpc.clone()).await?; // --- build and start the gas oracle worker task @@ -196,8 +190,9 @@ pub async fn build(mut config: Config) -> Result { // --- build backend let (blockchain, db, forked_client) = if let Some(cfg) = &config.forking { + let chain_spec = Arc::get_mut(&mut config.chain).expect("get mut Arc"); let (bc, block_num) = - Blockchain::new_from_forked(cfg.url.clone(), cfg.block, &mut config.chain).await?; + Blockchain::new_from_forked(cfg.url.clone(), cfg.block, chain_spec).await?; // TODO: it'd bee nice if the client can be shared on both the rpc and forked backend side let forked_client = ForkedClient::new_http(cfg.url.clone(), block_num); @@ -214,15 +209,12 @@ pub async fn build(mut config: Config) -> Result { // --- build l1 gas oracle // Check if the user specify a fixed gas price in the dev config. - // cases to cover: - // 1. Fixed price by user - // 2. No fixed price by user and no sampling - // 3. Sampling with user input provider url - let gas_oracle = if let Some(fixed_prices) = config.dev.fixed_gas_prices { - // Use fixed gas prices if provided in the configuration - L1GasOracle::fixed(fixed_prices.gas_price, fixed_prices.data_gas_price) - } else if config.l1_provider_url.as_ref().is_none() { - // Use default fixed gas prices if `gpo` is `None` + let gas_oracle = if let Some(fixed_prices) = &config.dev.fixed_gas_prices { + L1GasOracle::fixed(fixed_prices.gas_price.clone(), fixed_prices.data_gas_price.clone()) + } + // TODO: for now we just use the default gas prices, but this should be a proper oracle in the + // future that can perform actual sampling. + else { L1GasOracle::fixed( GasPrices { eth: DEFAULT_ETH_L1_GAS_PRICE, strk: DEFAULT_STRK_L1_GAS_PRICE }, GasPrices { eth: DEFAULT_ETH_L1_DATA_GAS_PRICE, strk: DEFAULT_STRK_L1_DATA_GAS_PRICE }, @@ -238,7 +230,7 @@ pub async fn build(mut config: Config) -> Result { blockchain, executor_factory, block_context_generator, - chain_spec: config.chain, + chain_spec: config.chain.clone(), }); // --- build block producer @@ -264,10 +256,7 @@ pub async fn build(mut config: Config) -> Result { backend, forked_client, block_producer, - rpc_config: config.rpc, - metrics_config: config.metrics, - messaging_config: config.messaging, - sequencing_config: config.sequencing, + config: Arc::new(config), task_manager: TaskManager::current(), l1_provider_url: config.l1_provider_url, };