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

feat(katana): add builder pattern for katana config #2653

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 16 additions & 15 deletions bin/katana/src/cli/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use katana_node::config::metrics::MetricsConfig;
use katana_node::config::rpc::{
ApiKind, RpcConfig, DEFAULT_RPC_ADDR, DEFAULT_RPC_MAX_CONNECTIONS, DEFAULT_RPC_PORT,
};
use katana_node::config::{Config, SequencingConfig};
use katana_node::config::{ConfigBuilder, SequencingConfig};
use katana_primitives::block::{BlockHashOrNumber, GasPrices};
use katana_primitives::chain::ChainId;
use katana_primitives::chain_spec::{self, ChainSpec};
Expand Down Expand Up @@ -282,17 +282,18 @@ impl NodeArgs {
}

fn config(&self) -> Result<katana_node::config::Config> {
let db = self.db_config();
let rpc = self.rpc_config();
let dev = self.dev_config();
let chain = self.chain_spec()?;
let metrics = self.metrics_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, execution, sequencing, messaging, forking })
let mut builder = ConfigBuilder::new();
Ok(builder
.metrics(self.metrics_config())
.db(self.db_config())
.dev(self.dev_config())
.rpc(self.rpc_config())
.chain(self.chain_spec()?)
.execution(self.execution_config())
.sequencing(self.sequencer_config())
.messaging(self.messaging.clone())
.forking(self.forking_config()?)
.build())
}

fn sequencer_config(&self) -> SequencingConfig {
Expand Down Expand Up @@ -325,7 +326,7 @@ impl NodeArgs {
if let Some(genesis) = self.starknet.genesis.clone() {
chain_spec.genesis = genesis;
} else {
chain_spec.genesis.sequencer_address = *DEFAULT_SEQUENCER_ADDRESS;
chain_spec.genesis.sequencer_address = DEFAULT_SEQUENCER_ADDRESS;
}

// generate dev accounts
Expand Down Expand Up @@ -533,7 +534,7 @@ mod test {
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.sequencer_address, *DEFAULT_SEQUENCER_ADDRESS);
assert_eq!(config.chain.genesis.sequencer_address, DEFAULT_SEQUENCER_ADDRESS);
}

#[test]
Expand All @@ -559,7 +560,7 @@ mod test {
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.sequencer_address, *DEFAULT_SEQUENCER_ADDRESS);
assert_eq!(config.chain.genesis.sequencer_address, DEFAULT_SEQUENCER_ADDRESS);
}

#[test]
Expand Down
24 changes: 8 additions & 16 deletions crates/dojo/test-utils/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ use jsonrpsee::core::Error;
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::rpc::ApiKind;
pub use katana_node::config::*;
use katana_node::LaunchedNode;
use katana_primitives::chain::ChainId;
use katana_primitives::chain_spec::ChainSpec;
use starknet::accounts::{ExecutionEncoding, SingleOwnerAccount};
use starknet::core::chain_id;
use starknet::core::types::{BlockId, BlockTag, Felt};
Expand Down Expand Up @@ -113,17 +111,11 @@ impl TestSequencer {
}

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,
addr: DEFAULT_RPC_ADDR,
max_connections: DEFAULT_RPC_MAX_CONNECTIONS,
apis: HashSet::from([ApiKind::Starknet, ApiKind::Dev, ApiKind::Saya, ApiKind::Torii]),
};

Config { sequencing, rpc, dev, chain, ..Default::default() }
ConfigBuilder::new()
.dev_fee(false)
.chain_id(ChainId::SEPOLIA)
.genesis_sequencer_address(DEFAULT_SEQUENCER_ADDRESS)
.rpc_apis(HashSet::from([ApiKind::Starknet, ApiKind::Dev, ApiKind::Saya, ApiKind::Torii]))
.sequencing(sequencing)
.build()
}
1 change: 0 additions & 1 deletion crates/katana/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ async-trait.workspace = true
derive_more.workspace = true
dojo-metrics.workspace = true
futures.workspace = true
lazy_static.workspace = true
metrics.workspace = true
num-traits.workspace = true
parking_lot.workspace = true
Expand Down
9 changes: 1 addition & 8 deletions crates/katana/core/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use katana_primitives::contract::ContractAddress;
use lazy_static::lazy_static;
use starknet::macros::felt;

// Default gas prices
Expand All @@ -10,10 +9,4 @@ pub const DEFAULT_STRK_L1_GAS_PRICE: u128 = 100 * u128::pow(10, 9); // Given in
pub const DEFAULT_ETH_L1_DATA_GAS_PRICE: u128 = u128::pow(10, 6); // Given in units of Wei.
pub const DEFAULT_STRK_L1_DATA_GAS_PRICE: u128 = u128::pow(10, 9); // Given in units of STRK.

lazy_static! {

// Predefined contract addresses

pub static ref DEFAULT_SEQUENCER_ADDRESS: ContractAddress = ContractAddress(felt!("0x1"));

}
pub const DEFAULT_SEQUENCER_ADDRESS: ContractAddress = ContractAddress(felt!("0x1"));
2 changes: 1 addition & 1 deletion crates/katana/node/src/config/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ pub struct ExecutionConfig {
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,
max_recursion_depth: MAX_RECURSION_DEPTH,
}
}
}
Loading
Loading