From cf378ca12bfac279b38228141dbd1c61d344d602 Mon Sep 17 00:00:00 2001 From: tedison Date: Thu, 7 Nov 2024 10:12:51 -0500 Subject: [PATCH 1/3] Add builder pattern for katana config --- Cargo.lock | 1 - bin/katana/src/cli/node.rs | 30 +-- crates/dojo/test-utils/src/sequencer.rs | 20 +- crates/katana/core/Cargo.toml | 1 - crates/katana/core/src/constants.rs | 9 +- crates/katana/node/src/config/execution.rs | 2 +- crates/katana/node/src/config/mod.rs | 289 ++++++++++++++++++++- 7 files changed, 310 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2c5537c005..cc8f758237 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8138,7 +8138,6 @@ dependencies = [ "katana-provider", "katana-tasks", "katana-trie", - "lazy_static", "metrics", "num-traits 0.2.19", "parking_lot 0.12.3", diff --git a/bin/katana/src/cli/node.rs b/bin/katana/src/cli/node.rs index f06fb84db4..bfc4f51860 100644 --- a/bin/katana/src/cli/node.rs +++ b/bin/katana/src/cli/node.rs @@ -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}; @@ -282,17 +282,17 @@ impl NodeArgs { } fn config(&self) -> Result { - 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 }) + Ok(ConfigBuilder::new() + .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 { @@ -325,7 +325,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 @@ -533,7 +533,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] @@ -559,7 +559,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] diff --git a/crates/dojo/test-utils/src/sequencer.rs b/crates/dojo/test-utils/src/sequencer.rs index 63356be4ad..2e9907adcd 100644 --- a/crates/dojo/test-utils/src/sequencer.rs +++ b/crates/dojo/test-utils/src/sequencer.rs @@ -113,17 +113,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() } diff --git a/crates/katana/core/Cargo.toml b/crates/katana/core/Cargo.toml index 2d166c6795..04b4fb8dd8 100644 --- a/crates/katana/core/Cargo.toml +++ b/crates/katana/core/Cargo.toml @@ -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 diff --git a/crates/katana/core/src/constants.rs b/crates/katana/core/src/constants.rs index b47908205f..5bd7847654 100644 --- a/crates/katana/core/src/constants.rs +++ b/crates/katana/core/src/constants.rs @@ -1,5 +1,4 @@ use katana_primitives::contract::ContractAddress; -use lazy_static::lazy_static; use starknet::macros::felt; // Default gas prices @@ -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")); \ No newline at end of file diff --git a/crates/katana/node/src/config/execution.rs b/crates/katana/node/src/config/execution.rs index 69db1edb83..55ee0b4be4 100644 --- a/crates/katana/node/src/config/execution.rs +++ b/crates/katana/node/src/config/execution.rs @@ -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, } } } diff --git a/crates/katana/node/src/config/mod.rs b/crates/katana/node/src/config/mod.rs index b79ae25a97..f144f1cb0d 100644 --- a/crates/katana/node/src/config/mod.rs +++ b/crates/katana/node/src/config/mod.rs @@ -5,14 +5,30 @@ pub mod fork; pub mod metrics; pub mod rpc; +use std::{ + collections::{BTreeMap, HashSet}, + net::{IpAddr, SocketAddr}, + path::PathBuf, + str::FromStr, +}; + use db::DbConfig; -use dev::DevConfig; +use dev::{DevConfig, FixedL1GasPriceConfig}; use execution::ExecutionConfig; use fork::ForkingConfig; use katana_core::service::messaging::MessagingConfig; -use katana_primitives::chain_spec::ChainSpec; +use katana_primitives::{ + block::{BlockHash, BlockHashOrNumber, BlockNumber, GasPrices}, + chain::ChainId, + chain_spec::ChainSpec, + class::ClassHash, + genesis::{allocation::GenesisAllocation, GenesisClass}, + version::ProtocolVersion, + ContractAddress, Felt, +}; use metrics::MetricsConfig; -use rpc::RpcConfig; +use rpc::{ApiKind, RpcConfig}; +use starknet::providers::Url; /// Node configurations. /// @@ -58,3 +74,270 @@ pub struct SequencingConfig { /// Allowing block to only be produced manually. pub no_mining: bool, } + +#[derive(Default)] +pub struct ConfigBuilder { + config: Config, +} + +impl ConfigBuilder { + pub fn new() -> Self { + ConfigBuilder::default() + } + + pub fn chain_id(mut self, chain_id: ChainId) -> Self { + self.config.chain.id = chain_id; + self + } + + pub fn genesis_parent_hash(mut self, parent_hash: BlockHash) -> Self { + self.config.chain.genesis.parent_hash = parent_hash; + self + } + + pub fn genesis_state_root(mut self, state_root: Felt) -> Self { + self.config.chain.genesis.state_root = state_root; + self + } + + pub fn genesis_number(mut self, number: BlockNumber) -> Self { + self.config.chain.genesis.number = number; + self + } + + pub fn genesis_timestamp(mut self, timestamp: u64) -> Self { + self.config.chain.genesis.timestamp = timestamp; + self + } + + pub fn genesis_sequencer_address(mut self, sequencer_address: ContractAddress) -> Self { + self.config.chain.genesis.sequencer_address = sequencer_address; + self + } + + pub fn genesis_gas_prices(mut self, gas_prices: GasPrices) -> Self { + self.config.chain.genesis.gas_prices = gas_prices; + self + } + + pub fn genesis_classes(mut self, classes: BTreeMap) -> Self { + self.config.chain.genesis.classes = classes; + self + } + + pub fn genesis_allocations( + mut self, + allocations: BTreeMap, + ) -> Self { + self.config.chain.genesis.allocations = allocations; + self + } + + pub fn fee_contracts_eth(mut self, eth: ContractAddress) -> Self { + self.config.chain.fee_contracts.eth = eth; + self + } + + pub fn fee_contracts_strk(mut self, strk: ContractAddress) -> Self { + self.config.chain.fee_contracts.strk = strk; + self + } + + pub fn chain_protocol_version(mut self, version: ProtocolVersion) -> Self { + self.config.chain.version = version; + self + } + + pub fn db_dir(mut self, dir: Option) -> Self { + self.config.db.dir = dir; + self + } + + pub fn forking(mut self, forking: Option) -> Self { + self.config.forking = forking; + self + } + + pub fn fork_url(mut self, url: Url) -> Self { + self.config.forking.get_or_insert(ForkingConfig { url, block: None }).url = url.clone(); + self + } + + pub fn fork_block(mut self, block: Option) -> Self { + self.config + .forking + .get_or_insert(ForkingConfig { url: Url::from_str("").unwrap(), block: None }) + .block = block; + self + } + + pub fn rpc_port(mut self, port: u16) -> Self { + self.config.rpc.port = port; + self + } + + pub fn rpc_addr(mut self, addr: IpAddr) -> Self { + self.config.rpc.addr = addr; + self + } + + pub fn rpc_max_connections(mut self, max_connections: u32) -> Self { + self.config.rpc.max_connections = max_connections; + self + } + + pub fn rpc_allowed_origins(mut self, allowed_origins: Option>) -> Self { + self.config.rpc.allowed_origins = allowed_origins; + self + } + + pub fn rpc_apis(mut self, apis: HashSet) -> Self { + self.config.rpc.apis = apis; + self + } + + pub fn metrics_addr(mut self, addr: SocketAddr) -> Self { + self.config.metrics.get_or_insert(MetricsConfig { addr }).addr = addr; + self + } + + pub fn execution_invocation_max_steps(mut self, steps: u32) -> Self { + self.config.execution.invocation_max_steps = steps; + self + } + + pub fn execution_validation_max_steps(mut self, steps: u32) -> Self { + self.config.execution.validation_max_steps = steps; + self + } + + pub fn execution_max_recursion_depth(mut self, depth: usize) -> Self { + self.config.execution.max_recursion_depth = depth; + self + } + + pub fn messaging_chain(mut self, chain: String) -> Self { + self.config + .messaging + .get_or_insert(MessagingConfig { chain, ..Default::default() }) + .chain = chain.clone(); + self + } + + pub fn messaging_rpc_url(mut self, rpc_url: String) -> Self { + self.config + .messaging + .get_or_insert(MessagingConfig { rpc_url, ..Default::default() }) + .rpc_url = rpc_url.clone(); + self + } + + pub fn messaging_contract_address(mut self, contract_address: String) -> Self { + self.config + .messaging + .get_or_insert(MessagingConfig { contract_address, ..Default::default() }) + .contract_address = contract_address.clone(); + self + } + + pub fn messaging_sender_address(mut self, sender_address: String) -> Self { + self.config + .messaging + .get_or_insert(MessagingConfig { sender_address, ..Default::default() }) + .sender_address = sender_address.clone(); + self + } + + pub fn messaging_private_key(mut self, private_key: String) -> Self { + self.config + .messaging + .get_or_insert(MessagingConfig { private_key, ..Default::default() }) + .private_key = private_key.clone(); + self + } + + pub fn messaging_interval(mut self, interval: u64) -> Self { + self.config + .messaging + .get_or_insert(MessagingConfig { interval, ..Default::default() }) + .interval = interval; + self + } + + pub fn messaging_from_block(mut self, from_block: u64) -> Self { + self.config + .messaging + .get_or_insert(MessagingConfig { from_block, ..Default::default() }) + .from_block = from_block; + self + } + + pub fn sequencing_block_time(mut self, block_time: Option) -> Self { + self.config.sequencing.block_time = block_time; + self + } + + pub fn sequencing_no_mining(mut self, no_mining: bool) -> Self { + self.config.sequencing.no_mining = no_mining; + self + } + + pub fn dev_fee(mut self, fee: bool) -> Self { + self.config.dev.fee = fee; + self + } + + pub fn dev_account_validation(mut self, validation: bool) -> Self { + self.config.dev.account_validation = validation; + self + } + + pub fn dev_fixed_gas_prices(mut self, gas_prices: Option) -> Self { + self.config.dev.fixed_gas_prices = gas_prices; + self + } + + pub fn chain(mut self, chain: ChainSpec) -> Self { + self.config.chain = chain; + self + } + + pub fn db(mut self, db: DbConfig) -> Self { + self.config.db = db; + self + } + + pub fn rpc(mut self, rpc: RpcConfig) -> Self { + self.config.rpc = rpc; + self + } + + pub fn metrics(mut self, metrics: Option) -> Self { + self.config.metrics = metrics; + self + } + + pub fn execution(mut self, execution: ExecutionConfig) -> Self { + self.config.execution = execution; + self + } + + pub fn messaging(mut self, messaging: Option) -> Self { + self.config.messaging = messaging; + self + } + + pub fn sequencing(mut self, sequencing: SequencingConfig) -> Self { + self.config.sequencing = sequencing; + self + } + + pub fn dev(mut self, dev: DevConfig) -> Self { + self.config.dev = dev; + self + } + + pub fn build(self) -> Config { + self.config + } +} From 9b1729e547786a58fa4906df94829906e9a47305 Mon Sep 17 00:00:00 2001 From: tedison Date: Thu, 7 Nov 2024 10:22:48 -0500 Subject: [PATCH 2/3] Add debug trait + format --- crates/dojo/test-utils/src/sequencer.rs | 4 +--- crates/katana/core/src/constants.rs | 2 +- crates/katana/node/src/config/mod.rs | 29 +++++++++++-------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/crates/dojo/test-utils/src/sequencer.rs b/crates/dojo/test-utils/src/sequencer.rs index 2e9907adcd..3835f76f53 100644 --- a/crates/dojo/test-utils/src/sequencer.rs +++ b/crates/dojo/test-utils/src/sequencer.rs @@ -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}; diff --git a/crates/katana/core/src/constants.rs b/crates/katana/core/src/constants.rs index 5bd7847654..99b95ef776 100644 --- a/crates/katana/core/src/constants.rs +++ b/crates/katana/core/src/constants.rs @@ -9,4 +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. -pub const DEFAULT_SEQUENCER_ADDRESS: ContractAddress = ContractAddress(felt!("0x1")); \ No newline at end of file +pub const DEFAULT_SEQUENCER_ADDRESS: ContractAddress = ContractAddress(felt!("0x1")); diff --git a/crates/katana/node/src/config/mod.rs b/crates/katana/node/src/config/mod.rs index f144f1cb0d..e36e73555e 100644 --- a/crates/katana/node/src/config/mod.rs +++ b/crates/katana/node/src/config/mod.rs @@ -5,27 +5,24 @@ pub mod fork; pub mod metrics; pub mod rpc; -use std::{ - collections::{BTreeMap, HashSet}, - net::{IpAddr, SocketAddr}, - path::PathBuf, - str::FromStr, -}; +use std::collections::{BTreeMap, HashSet}; +use std::net::{IpAddr, SocketAddr}; +use std::path::PathBuf; +use std::str::FromStr; use db::DbConfig; use dev::{DevConfig, FixedL1GasPriceConfig}; use execution::ExecutionConfig; use fork::ForkingConfig; use katana_core::service::messaging::MessagingConfig; -use katana_primitives::{ - block::{BlockHash, BlockHashOrNumber, BlockNumber, GasPrices}, - chain::ChainId, - chain_spec::ChainSpec, - class::ClassHash, - genesis::{allocation::GenesisAllocation, GenesisClass}, - version::ProtocolVersion, - ContractAddress, Felt, -}; +use katana_primitives::block::{BlockHash, BlockHashOrNumber, BlockNumber, GasPrices}; +use katana_primitives::chain::ChainId; +use katana_primitives::chain_spec::ChainSpec; +use katana_primitives::class::ClassHash; +use katana_primitives::genesis::allocation::GenesisAllocation; +use katana_primitives::genesis::GenesisClass; +use katana_primitives::version::ProtocolVersion; +use katana_primitives::{ContractAddress, Felt}; use metrics::MetricsConfig; use rpc::{ApiKind, RpcConfig}; use starknet::providers::Url; @@ -75,7 +72,7 @@ pub struct SequencingConfig { pub no_mining: bool, } -#[derive(Default)] +#[derive(Default, Debug)] pub struct ConfigBuilder { config: Config, } From 52dc08444d0dd87f47f8840307abf130e8cb4036 Mon Sep 17 00:00:00 2001 From: tedison Date: Fri, 8 Nov 2024 16:13:35 -0500 Subject: [PATCH 3/3] use mutable references instead of consuming the self in ConfigBuilder --- bin/katana/src/cli/node.rs | 3 +- crates/katana/node/src/config/mod.rs | 96 ++++++++++++++-------------- 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/bin/katana/src/cli/node.rs b/bin/katana/src/cli/node.rs index bfc4f51860..45df247ecf 100644 --- a/bin/katana/src/cli/node.rs +++ b/bin/katana/src/cli/node.rs @@ -282,7 +282,8 @@ impl NodeArgs { } fn config(&self) -> Result { - Ok(ConfigBuilder::new() + let mut builder = ConfigBuilder::new(); + Ok(builder .metrics(self.metrics_config()) .db(self.db_config()) .dev(self.dev_config()) diff --git a/crates/katana/node/src/config/mod.rs b/crates/katana/node/src/config/mod.rs index e36e73555e..e4f34bc4dd 100644 --- a/crates/katana/node/src/config/mod.rs +++ b/crates/katana/node/src/config/mod.rs @@ -82,85 +82,85 @@ impl ConfigBuilder { ConfigBuilder::default() } - pub fn chain_id(mut self, chain_id: ChainId) -> Self { + pub fn chain_id(&mut self, chain_id: ChainId) -> &mut Self { self.config.chain.id = chain_id; self } - pub fn genesis_parent_hash(mut self, parent_hash: BlockHash) -> Self { + pub fn genesis_parent_hash(&mut self, parent_hash: BlockHash) -> &mut Self { self.config.chain.genesis.parent_hash = parent_hash; self } - pub fn genesis_state_root(mut self, state_root: Felt) -> Self { + pub fn genesis_state_root(&mut self, state_root: Felt) -> &mut Self { self.config.chain.genesis.state_root = state_root; self } - pub fn genesis_number(mut self, number: BlockNumber) -> Self { + pub fn genesis_number(&mut self, number: BlockNumber) -> &mut Self { self.config.chain.genesis.number = number; self } - pub fn genesis_timestamp(mut self, timestamp: u64) -> Self { + pub fn genesis_timestamp(&mut self, timestamp: u64) -> &mut Self { self.config.chain.genesis.timestamp = timestamp; self } - pub fn genesis_sequencer_address(mut self, sequencer_address: ContractAddress) -> Self { + pub fn genesis_sequencer_address(&mut self, sequencer_address: ContractAddress) -> &mut Self { self.config.chain.genesis.sequencer_address = sequencer_address; self } - pub fn genesis_gas_prices(mut self, gas_prices: GasPrices) -> Self { + pub fn genesis_gas_prices(&mut self, gas_prices: GasPrices) -> &mut Self { self.config.chain.genesis.gas_prices = gas_prices; self } - pub fn genesis_classes(mut self, classes: BTreeMap) -> Self { + pub fn genesis_classes(&mut self, classes: BTreeMap) -> &mut Self { self.config.chain.genesis.classes = classes; self } pub fn genesis_allocations( - mut self, + &mut self, allocations: BTreeMap, - ) -> Self { + ) -> &mut Self { self.config.chain.genesis.allocations = allocations; self } - pub fn fee_contracts_eth(mut self, eth: ContractAddress) -> Self { + pub fn fee_contracts_eth(&mut self, eth: ContractAddress) -> &mut Self { self.config.chain.fee_contracts.eth = eth; self } - pub fn fee_contracts_strk(mut self, strk: ContractAddress) -> Self { + pub fn fee_contracts_strk(&mut self, strk: ContractAddress) -> &mut Self { self.config.chain.fee_contracts.strk = strk; self } - pub fn chain_protocol_version(mut self, version: ProtocolVersion) -> Self { + pub fn chain_protocol_version(&mut self, version: ProtocolVersion) -> &mut Self { self.config.chain.version = version; self } - pub fn db_dir(mut self, dir: Option) -> Self { + pub fn db_dir(&mut self, dir: Option) -> &mut Self { self.config.db.dir = dir; self } - pub fn forking(mut self, forking: Option) -> Self { + pub fn forking(&mut self, forking: Option) -> &mut Self { self.config.forking = forking; self } - pub fn fork_url(mut self, url: Url) -> Self { + pub fn fork_url(&mut self, url: Url) -> &mut Self { self.config.forking.get_or_insert(ForkingConfig { url, block: None }).url = url.clone(); self } - pub fn fork_block(mut self, block: Option) -> Self { + pub fn fork_block(&mut self, block: Option) -> &mut Self { self.config .forking .get_or_insert(ForkingConfig { url: Url::from_str("").unwrap(), block: None }) @@ -168,52 +168,52 @@ impl ConfigBuilder { self } - pub fn rpc_port(mut self, port: u16) -> Self { + pub fn rpc_port(&mut self, port: u16) -> &mut Self { self.config.rpc.port = port; self } - pub fn rpc_addr(mut self, addr: IpAddr) -> Self { + pub fn rpc_addr(&mut self, addr: IpAddr) -> &mut Self { self.config.rpc.addr = addr; self } - pub fn rpc_max_connections(mut self, max_connections: u32) -> Self { + pub fn rpc_max_connections(&mut self, max_connections: u32) -> &mut Self { self.config.rpc.max_connections = max_connections; self } - pub fn rpc_allowed_origins(mut self, allowed_origins: Option>) -> Self { + pub fn rpc_allowed_origins(&mut self, allowed_origins: Option>) -> &mut Self { self.config.rpc.allowed_origins = allowed_origins; self } - pub fn rpc_apis(mut self, apis: HashSet) -> Self { + pub fn rpc_apis(&mut self, apis: HashSet) -> &mut Self { self.config.rpc.apis = apis; self } - pub fn metrics_addr(mut self, addr: SocketAddr) -> Self { + pub fn metrics_addr(&mut self, addr: SocketAddr) -> &mut Self { self.config.metrics.get_or_insert(MetricsConfig { addr }).addr = addr; self } - pub fn execution_invocation_max_steps(mut self, steps: u32) -> Self { + pub fn execution_invocation_max_steps(&mut self, steps: u32) -> &mut Self { self.config.execution.invocation_max_steps = steps; self } - pub fn execution_validation_max_steps(mut self, steps: u32) -> Self { + pub fn execution_validation_max_steps(&mut self, steps: u32) -> &mut Self { self.config.execution.validation_max_steps = steps; self } - pub fn execution_max_recursion_depth(mut self, depth: usize) -> Self { + pub fn execution_max_recursion_depth(&mut self, depth: usize) -> &mut Self { self.config.execution.max_recursion_depth = depth; self } - pub fn messaging_chain(mut self, chain: String) -> Self { + pub fn messaging_chain(&mut self, chain: String) -> &mut Self { self.config .messaging .get_or_insert(MessagingConfig { chain, ..Default::default() }) @@ -221,7 +221,7 @@ impl ConfigBuilder { self } - pub fn messaging_rpc_url(mut self, rpc_url: String) -> Self { + pub fn messaging_rpc_url(&mut self, rpc_url: String) -> &mut Self { self.config .messaging .get_or_insert(MessagingConfig { rpc_url, ..Default::default() }) @@ -229,7 +229,7 @@ impl ConfigBuilder { self } - pub fn messaging_contract_address(mut self, contract_address: String) -> Self { + pub fn messaging_contract_address(&mut self, contract_address: String) -> &mut Self { self.config .messaging .get_or_insert(MessagingConfig { contract_address, ..Default::default() }) @@ -237,7 +237,7 @@ impl ConfigBuilder { self } - pub fn messaging_sender_address(mut self, sender_address: String) -> Self { + pub fn messaging_sender_address(&mut self, sender_address: String) -> &mut Self { self.config .messaging .get_or_insert(MessagingConfig { sender_address, ..Default::default() }) @@ -245,7 +245,7 @@ impl ConfigBuilder { self } - pub fn messaging_private_key(mut self, private_key: String) -> Self { + pub fn messaging_private_key(&mut self, private_key: String) -> &mut Self { self.config .messaging .get_or_insert(MessagingConfig { private_key, ..Default::default() }) @@ -253,7 +253,7 @@ impl ConfigBuilder { self } - pub fn messaging_interval(mut self, interval: u64) -> Self { + pub fn messaging_interval(&mut self, interval: u64) -> &mut Self { self.config .messaging .get_or_insert(MessagingConfig { interval, ..Default::default() }) @@ -261,7 +261,7 @@ impl ConfigBuilder { self } - pub fn messaging_from_block(mut self, from_block: u64) -> Self { + pub fn messaging_from_block(&mut self, from_block: u64) -> &mut Self { self.config .messaging .get_or_insert(MessagingConfig { from_block, ..Default::default() }) @@ -269,72 +269,72 @@ impl ConfigBuilder { self } - pub fn sequencing_block_time(mut self, block_time: Option) -> Self { + pub fn sequencing_block_time(&mut self, block_time: Option) -> &mut Self { self.config.sequencing.block_time = block_time; self } - pub fn sequencing_no_mining(mut self, no_mining: bool) -> Self { + pub fn sequencing_no_mining(&mut self, no_mining: bool) -> &mut Self { self.config.sequencing.no_mining = no_mining; self } - pub fn dev_fee(mut self, fee: bool) -> Self { + pub fn dev_fee(&mut self, fee: bool) -> &mut Self { self.config.dev.fee = fee; self } - pub fn dev_account_validation(mut self, validation: bool) -> Self { + pub fn dev_account_validation(&mut self, validation: bool) -> &mut Self { self.config.dev.account_validation = validation; self } - pub fn dev_fixed_gas_prices(mut self, gas_prices: Option) -> Self { + pub fn dev_fixed_gas_prices(&mut self, gas_prices: Option) -> &mut Self { self.config.dev.fixed_gas_prices = gas_prices; self } - pub fn chain(mut self, chain: ChainSpec) -> Self { + pub fn chain(&mut self, chain: ChainSpec) -> &mut Self { self.config.chain = chain; self } - pub fn db(mut self, db: DbConfig) -> Self { + pub fn db(&mut self, db: DbConfig) -> &mut Self { self.config.db = db; self } - pub fn rpc(mut self, rpc: RpcConfig) -> Self { + pub fn rpc(&mut self, rpc: RpcConfig) -> &mut Self { self.config.rpc = rpc; self } - pub fn metrics(mut self, metrics: Option) -> Self { + pub fn metrics(&mut self, metrics: Option) -> &mut Self { self.config.metrics = metrics; self } - pub fn execution(mut self, execution: ExecutionConfig) -> Self { + pub fn execution(&mut self, execution: ExecutionConfig) -> &mut Self { self.config.execution = execution; self } - pub fn messaging(mut self, messaging: Option) -> Self { + pub fn messaging(&mut self, messaging: Option) -> &mut Self { self.config.messaging = messaging; self } - pub fn sequencing(mut self, sequencing: SequencingConfig) -> Self { + pub fn sequencing(&mut self, sequencing: SequencingConfig) -> &mut Self { self.config.sequencing = sequencing; self } - pub fn dev(mut self, dev: DevConfig) -> Self { + pub fn dev(&mut self, dev: DevConfig) -> &mut Self { self.config.dev = dev; self } - pub fn build(self) -> Config { - self.config + pub fn build(&mut self) -> Config { + self.config.clone() } }