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 5 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.

26 changes: 11 additions & 15 deletions crates/dojo/test-utils/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,15 @@ 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 {
cors_origins: Vec::new(),
port: 0,
addr: DEFAULT_RPC_ADDR,
apis: RpcModulesList::all(),
max_connections: DEFAULT_RPC_MAX_CONNECTIONS,
max_event_page_size: Some(100),
max_proof_keys: Some(100),
};

Config { sequencing, rpc, dev, chain: chain.into(), ..Default::default() }
let mut chain_spec = ChainSpec { id: ChainId::SEPOLIA, ..Default::default() };
chain_spec.genesis.sequencer_address =
katana_primitives::ContractAddress(*DEFAULT_SEQUENCER_ADDRESS);
ConfigBuilder::new()
.dev_fee(false)
.chain(chain_spec)
.rpc_apis(RpcModulesList::all())
.rpc_max_event_page_size(Some(100))
.rpc_max_proof_keys(Some(100))
.sequencing(sequencing)
.build()
}
13 changes: 10 additions & 3 deletions crates/katana/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ 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 =
katana_primitives::ContractAddress(*DEFAULT_SEQUENCER_ADDRESS);
}

// generate dev accounts
Expand Down Expand Up @@ -423,7 +424,10 @@ 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,
katana_primitives::ContractAddress(*DEFAULT_SEQUENCER_ADDRESS)
);
}

#[test]
Expand All @@ -450,7 +454,10 @@ 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,
katana_primitives::ContractAddress(*DEFAULT_SEQUENCER_ADDRESS)
);
}

#[test]
Expand Down
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 = 20 * u128::pow(10, 9); // Given in u
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, 6); // 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,
}
}
}
6 changes: 6 additions & 0 deletions crates/katana/node/src/config/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ impl MetricsConfig {
SocketAddr::new(self.addr, self.port)
}
}

impl Default for MetricsConfig {
fn default() -> Self {
MetricsConfig { addr: DEFAULT_METRICS_ADDR, port: DEFAULT_METRICS_PORT }
}
}
Loading
Loading