dojoengine/dojo

feat(katana): node config builder

kariy opened this issue · 1 comments

Problem

we have a main config struct that encapsulates bunch of other smaller configs. this config struct is then passed to the katana_node::build() method.

/// Node configurations.
///
/// List of all possible options that can be used to configure a node.
#[derive(Debug, Clone, Default)]
pub struct Config {
/// The chain specification.
pub chain: ChainSpec,
/// Database options.
pub db: DbConfig,
/// Forking options.

/// Build the node components from the given [`Config`].
///
/// This returns a [`Node`] instance which can be launched with the all the necessary components
/// configured.
pub async fn build(mut config: Config) -> Result<Node> {
if config.metrics.is_some() {
// Metrics recorder must be initialized before calling any of the metrics macros, in order

because there are many configurations, it can be quite a hassle to specify each one of them. especially when you only want to specify some of them and want to use the default values for the rest. for example, in the dojo-test-utils:

pub fn get_default_test_config(sequencing: SequencingConfig) -> Config {
let dev = DevConfig { fee: false, account_validation: true, fixed_gas_prices: None };
let mut chain = ChainSpec { id: ChainId::SEPOLIA, ..Default::default() };
chain.genesis.sequencer_address = *DEFAULT_SEQUENCER_ADDRESS;
let rpc = RpcConfig {
allowed_origins: None,
port: 0,


it'd be nice to have a ConfigBuilder where you can set individual values using the builder pattern. the logic for the katana_node::build() can then be moved to ConfigBuilder::build() method.

Hey! Would be down to work on this!