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): include config in the node struct #2742

Merged
merged 1 commit into from
Nov 30, 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
2 changes: 1 addition & 1 deletion crates/dojo/test-utils/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}
5 changes: 3 additions & 2 deletions crates/katana/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::collections::HashSet;
use std::path::PathBuf;
use std::sync::Arc;

use alloy_primitives::U256;
use anyhow::{Context, Result};
Expand Down Expand Up @@ -203,7 +204,7 @@ impl NodeArgs {
}
}

fn chain_spec(&self) -> Result<ChainSpec> {
fn chain_spec(&self) -> Result<Arc<ChainSpec>> {
let mut chain_spec = chain_spec::DEV_UNALLOCATED.clone();

if let Some(id) = self.starknet.environment.chain_id {
Expand All @@ -229,7 +230,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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/katana/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(crate) const LOG_TARGET: &str = "katana::core::backend";

#[derive(Debug)]
pub struct Backend<EF: ExecutorFactory> {
pub chain_spec: ChainSpec,
pub chain_spec: Arc<ChainSpec>,
/// stores all block related data in memory
pub blockchain: Blockchain,
/// The block context generator.
Expand Down
4 changes: 3 additions & 1 deletion crates/katana/node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +22,7 @@ use rpc::RpcConfig;
#[derive(Debug, Clone, Default)]
pub struct Config {
/// The chain specification.
pub chain: ChainSpec,
pub chain: Arc<ChainSpec>,

/// Database options.
pub db: DbConfig,
Expand Down
29 changes: 11 additions & 18 deletions crates/katana/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
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};
Expand All @@ -28,7 +27,6 @@
};
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};
Expand Down Expand Up @@ -90,10 +88,7 @@
pub task_manager: TaskManager,
pub backend: Arc<Backend<BlockifierFactory>>,
pub block_producer: BlockProducer<BlockifierFactory>,
pub rpc_config: RpcConfig,
pub metrics_config: Option<MetricsConfig>,
pub sequencing_config: SequencingConfig,
pub messaging_config: Option<MessagingConfig>,
pub config: Arc<Config>,
forked_client: Option<ForkedClient>,
}

Expand All @@ -106,7 +101,7 @@
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<Box<dyn Report>> = Vec::new();

Expand All @@ -133,7 +128,7 @@
backend.clone(),
self.task_manager.task_spawner(),
block_producer.clone(),
self.messaging_config.clone(),
self.config.messaging.clone(),
);

self.task_manager
Expand All @@ -144,7 +139,7 @@
.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?;

Ok(LaunchedNode { node: self, rpc })
}
Expand Down Expand Up @@ -183,8 +178,9 @@
// --- 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);
Expand All @@ -201,8 +197,8 @@
// --- build l1 gas oracle

// Check if the user specify a fixed gas price in the dev config.
let gas_oracle = if let Some(fixed_prices) = config.dev.fixed_gas_prices {
L1GasOracle::fixed(fixed_prices.gas_price, fixed_prices.data_gas_price)
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())

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

View check run for this annotation

Codecov / codecov/patch

crates/katana/node/src/lib.rs#L201

Added line #L201 was not covered by tests
}
// 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.
Expand All @@ -219,7 +215,7 @@
blockchain,
executor_factory,
block_context_generator,
chain_spec: config.chain,
chain_spec: config.chain.clone(),
});

// --- build block producer
Expand All @@ -245,10 +241,7 @@
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(),
};

Expand Down
Loading