diff --git a/bin/builder.rs b/bin/builder.rs index 1058849..f8378d5 100644 --- a/bin/builder.rs +++ b/bin/builder.rs @@ -1,15 +1,11 @@ use builder::{ - config::BuilderConfig, service::serve_builder, tasks::{ - block::sim::Simulator, cache::CacheTasks, env::EnvTask, metrics::MetricsTask, + block::sim::SimulatorTask, cache::CacheTasks, env::EnvTask, metrics::MetricsTask, submit::FlashbotsTask, }, }; -use init4_bin_base::{ - deps::tracing::{info, info_span}, - utils::from_env::FromEnv, -}; +use init4_bin_base::deps::tracing::{info, info_span}; use tokio::select; // Note: Must be set to `multi_thread` to support async tasks. @@ -18,46 +14,33 @@ use tokio::select; async fn main() -> eyre::Result<()> { let _guard = init4_bin_base::init4(); let init_span_guard = info_span!("builder initialization"); + builder::config_from_env(); - // Pull the configuration from the environment - let config = BuilderConfig::from_env()?.clone(); - - // We connect the providers greedily, so we can fail early if the - // RU WS connection is invalid. - let (ru_provider, host_provider) = - tokio::try_join!(config.connect_ru_provider(), config.connect_host_provider(),)?; - let quincey = config.connect_quincey().await?; + // Set up env and metrics tasks + let (env_task, metrics_task) = tokio::try_join!(EnvTask::new(), MetricsTask::new())?; - // Spawn the EnvTask - let env_task = - EnvTask::new(config.clone(), host_provider.clone(), quincey, ru_provider.clone()); + // Spawn the env and metrics tasks let (block_env, env_jh) = env_task.spawn(); + let (tx_channel, metrics_jh) = metrics_task.spawn(); - // Spawn the cache system - let cache_tasks = CacheTasks::new(config.clone(), block_env.clone()); - let cache_system = cache_tasks.spawn(); - - // Set up the metrics task - let metrics = MetricsTask::new(host_provider.clone()); - let (tx_channel, metrics_jh) = metrics.spawn(); + // Set up the cache, submit, and simulator tasks + let cache_tasks = CacheTasks::new(block_env.clone()); + let (submit_task, simulator_task) = + tokio::try_join!(FlashbotsTask::new(tx_channel.clone()), SimulatorTask::new(block_env),)?; - // Spawn the Flashbots task - let submit = FlashbotsTask::new(config.clone(), tx_channel).await?; - let (submit_channel, submit_jh) = submit.spawn(); - - // Set up the simulator - let sim = Simulator::new(&config, host_provider, ru_provider, block_env); - let build_jh = sim.spawn_simulator_task(cache_system.sim_cache, submit_channel); + // Spawn the cache, submit, and simulator tasks + let cache_system = cache_tasks.spawn(); + let (submit_channel, submit_jh) = submit_task.spawn(); + let build_jh = simulator_task.spawn_simulator_task(cache_system.sim_cache, submit_channel); // Start the healthcheck server - let server = serve_builder(([0, 0, 0, 0], config.builder_port)); + let server = serve_builder(([0, 0, 0, 0], builder::config().builder_port)); // We have finished initializing the builder, so we can drop the init span // guard. drop(init_span_guard); select! { - _ = env_jh => { info!("env task finished"); }, diff --git a/src/config.rs b/src/config.rs index c7d93bb..7e19523 100644 --- a/src/config.rs +++ b/src/config.rs @@ -215,13 +215,10 @@ impl BuilderConfig { } /// Connect to a Flashbots bundle provider. - pub async fn connect_flashbots( - &self, - config: &BuilderConfig, - ) -> Result { + pub async fn connect_flashbots(&self) -> Result { let endpoint = - config.flashbots_endpoint.clone().expect("flashbots endpoint must be configured"); - let signer = config.connect_builder_signer().await?; + self.flashbots_endpoint.clone().expect("flashbots endpoint must be configured"); + let signer = self.connect_builder_signer().await?; let flashbots: FlashbotsProvider = ProviderBuilder::new().wallet(signer).connect_http(endpoint); Ok(flashbots) diff --git a/src/lib.rs b/src/lib.rs index 322ba68..b727a41 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,5 +33,41 @@ pub mod utils; /// Test utilitites pub mod test_utils; +use init4_bin_base::utils::from_env::FromEnv; // Anonymous import suppresses warnings about unused imports. use openssl as _; +use signet_constants::SignetSystemConstants; +use std::sync::OnceLock; + +/// Global static configuration for the Builder binary. +pub static CONFIG: OnceLock = OnceLock::new(); + +/// Load the Builder configuration from the environment and store it in the +/// global static CONFIG variable. Returns a reference to the configuration. +/// +/// # Panics +/// +/// Panics if the configuration cannot be loaded from the environment AND no +/// other configuration has been previously initialized. +pub fn config_from_env() -> &'static config::BuilderConfig { + CONFIG.get_or_init(|| config::BuilderConfig::from_env().expect("Failed to load Builder config")) +} + +/// Get a reference to the global Builder configuration. +/// +/// # Panics +/// +/// Panics if the configuration has not been initialized. +pub fn config() -> &'static config::BuilderConfig { + CONFIG.get().expect("Builder config not initialized") +} + +/// Get a reference to the Signet system constants from the global Builder +/// configuration. +/// +/// # Panics +/// +/// Panics if the configuration has not been initialized. +pub fn constants() -> &'static SignetSystemConstants { + &config().constants +} diff --git a/src/quincey.rs b/src/quincey.rs index eab5262..57c0b6d 100644 --- a/src/quincey.rs +++ b/src/quincey.rs @@ -5,7 +5,6 @@ use alloy::{ use eyre::bail; use init4_bin_base::{perms::SharedToken, utils::signer::LocalOrAws}; use reqwest::Client; -use signet_constants::SignetSystemConstants; use signet_types::{SignRequest, SignResponse}; use tracing::{debug, info, instrument, trace}; @@ -95,15 +94,12 @@ impl Quincey { /// Perform a preflight check to ensure that the Quincey service will /// be able to sign a request with the provided parameters at this /// point in time. - #[instrument(skip(self, constants))] - pub async fn preflight_check( - &self, - constants: &SignetSystemConstants, - host_block_number: u64, - ) -> eyre::Result<()> { + #[instrument(skip(self))] + pub async fn preflight_check(&self, host_block_number: u64) -> eyre::Result<()> { if self.is_local() { return Ok(()); } + let constants = crate::constants(); let req = SignRequest { host_block_number: U256::from(host_block_number), host_chain_id: U256::from(constants.host_chain_id()), diff --git a/src/tasks/block/sim.rs b/src/tasks/block/sim.rs index a294538..97f434b 100644 --- a/src/tasks/block/sim.rs +++ b/src/tasks/block/sim.rs @@ -22,21 +22,6 @@ use tokio::{ }; use tracing::{Instrument, Span, debug, instrument}; -/// `Simulator` is responsible for periodically building blocks and submitting them for -/// signing and inclusion in the blockchain. It wraps a rollup provider and a slot -/// calculator with a builder configuration. -#[derive(Debug)] -pub struct Simulator { - /// Configuration for the builder. - pub config: BuilderConfig, - /// Host Provider to interact with the host chain. - pub host_provider: HostProvider, - /// A provider that cannot sign transactions, used for interacting with the rollup. - pub ru_provider: RuProvider, - /// The block configuration environment on which to simulate - pub sim_env: watch::Receiver>, -} - /// SimResult bundles a BuiltBlock to the BlockEnv it was simulated against. #[derive(Debug, Clone)] pub struct SimResult { @@ -79,25 +64,30 @@ impl SimResult { } } -impl Simulator { - /// Creates a new `Simulator` instance. - /// - /// # Arguments - /// - /// - `config`: The configuration for the builder. - /// - `ru_provider`: A provider for interacting with the rollup. - /// - `block_env`: A receiver for the block environment to simulate against. - /// - /// # Returns - /// - /// A new `Simulator` instance. - pub fn new( - config: &BuilderConfig, - host_provider: HostProvider, - ru_provider: RuProvider, - sim_env: watch::Receiver>, - ) -> Self { - Self { config: config.clone(), host_provider, ru_provider, sim_env } +/// A task that builds blocks based on incoming [`SimEnv`]s and a simulation +/// cache. +#[derive(Debug)] +pub struct SimulatorTask { + /// Configuration for the builder. + config: &'static BuilderConfig, + /// Host Provider to interact with the host chain. + host_provider: HostProvider, + /// A provider that cannot sign transactions, used for interacting with the rollup. + ru_provider: RuProvider, + /// The block configuration environments on which to simulate + envs: watch::Receiver>, +} + +impl SimulatorTask { + /// Create a new `SimulatorTask` instance. This task must be spawned to + /// begin processing incoming block environments. + pub async fn new(envs: watch::Receiver>) -> eyre::Result { + let config = crate::config(); + + let (host_provider, ru_provider) = + tokio::try_join!(config.connect_host_provider(), config.connect_ru_provider())?; + + Ok(Self { config, host_provider, ru_provider, envs }) } /// Get the slot calculator. @@ -110,18 +100,17 @@ impl Simulator { &self.config.constants } - /// Handles building a single block. + /// Build a single block /// - /// Builds a block in the block environment with items from the simulation cache - /// against the database state. When the `finish_by` deadline is reached, it - /// stops simulating and returns the block. + /// Build a block in the sim environment with items from the simulation + /// cache against the database state. When the `finish_by` deadline is + /// reached, it stops simulating and returns the block. /// /// # Arguments /// - /// - `constants`: The system constants for the rollup. /// - `sim_items`: The simulation cache containing transactions and bundles. /// - `finish_by`: The deadline by which the block must be built. - /// - `block_env`: The block environment to simulate against. + /// - `sim_env`: The block environment to simulate against. /// /// # Returns /// @@ -209,11 +198,11 @@ impl Simulator { ) { loop { // Wait for the block environment to be set - if self.sim_env.changed().await.is_err() { + if self.envs.changed().await.is_err() { tracing::error!("block_env channel closed - shutting down simulator task"); return; } - let Some(sim_env) = self.sim_env.borrow_and_update().clone() else { return }; + let Some(sim_env) = self.envs.borrow_and_update().clone() else { return }; let span = sim_env.span(); span_info!(span, "new block environment received"); diff --git a/src/tasks/cache/bundle.rs b/src/tasks/cache/bundle.rs index 7a09e7c..b27c568 100644 --- a/src/tasks/cache/bundle.rs +++ b/src/tasks/cache/bundle.rs @@ -17,34 +17,33 @@ const POLL_INTERVAL_MS: u64 = 1000; #[derive(Debug)] pub struct BundlePoller { /// The builder configuration values. - pub config: BuilderConfig, + config: &'static BuilderConfig, /// Authentication module that periodically fetches and stores auth tokens. - pub token: SharedToken, + token: SharedToken, /// Holds a Reqwest client - pub client: Client, + client: Client, /// Defines the interval at which the bundler polls the tx-pool for bundles. - pub poll_interval_ms: u64, + poll_interval_ms: u64, +} + +impl Default for BundlePoller { + fn default() -> Self { + Self::new() + } } /// Implements a poller for the block builder to pull bundles from the tx-pool. impl BundlePoller { /// Creates a new BundlePoller from the provided builder config. - pub fn new(config: &BuilderConfig, token: SharedToken) -> Self { - Self { - config: config.clone(), - token, - client: Client::new(), - poll_interval_ms: POLL_INTERVAL_MS, - } + pub fn new() -> Self { + Self::new_with_poll_interval_ms(POLL_INTERVAL_MS) } /// Creates a new BundlePoller from the provided builder config and with the specified poll interval in ms. - pub fn new_with_poll_interval_ms( - config: &BuilderConfig, - token: SharedToken, - poll_interval_ms: u64, - ) -> Self { - Self { config: config.clone(), token, client: Client::new(), poll_interval_ms } + pub fn new_with_poll_interval_ms(poll_interval_ms: u64) -> Self { + let config = crate::config(); + let token = config.oauth_token(); + Self { config, token, client: Client::new(), poll_interval_ms } } /// Fetches bundles from the transaction cache and returns them. diff --git a/src/tasks/cache/system.rs b/src/tasks/cache/system.rs index 90c7aaf..cd9d231 100644 --- a/src/tasks/cache/system.rs +++ b/src/tasks/cache/system.rs @@ -1,38 +1,33 @@ use signet_sim::SimCache; use tokio::{sync::watch, task::JoinHandle}; -use crate::{ - config::BuilderConfig, - tasks::{ - cache::{BundlePoller, CacheTask, TxPoller}, - env::SimEnv, - }, +use crate::tasks::{ + cache::{BundlePoller, CacheTask, TxPoller}, + env::SimEnv, }; /// The block builder's cache system. #[derive(Debug)] pub struct CacheTasks { - /// The builder config. - pub config: BuilderConfig, /// The block environment receiver. - pub block_env: watch::Receiver>, + block_env: watch::Receiver>, } impl CacheTasks { /// Create a new [`CacheSystem`] with the given components. - pub const fn new(config: BuilderConfig, block_env: watch::Receiver>) -> Self { - Self { config, block_env } + pub const fn new(block_env: watch::Receiver>) -> Self { + Self { block_env } } /// Spawn a new [`CacheSystem`], which starts the /// [`CacheTask`], [`TxPoller`], and [`BundlePoller`] internally and yields their [`JoinHandle`]s. pub fn spawn(&self) -> CacheSystem { // Tx Poller pulls transactions from the cache - let tx_poller = TxPoller::new(&self.config); + let tx_poller = TxPoller::new(); let (tx_receiver, tx_poller) = tx_poller.spawn(); // Bundle Poller pulls bundles from the cache - let bundle_poller = BundlePoller::new(&self.config, self.config.oauth_token()); + let bundle_poller = BundlePoller::new(); let (bundle_receiver, bundle_poller) = bundle_poller.spawn(); // Set up the cache task diff --git a/src/tasks/cache/tx.rs b/src/tasks/cache/tx.rs index 4a2ae8e..0043f9f 100644 --- a/src/tasks/cache/tx.rs +++ b/src/tasks/cache/tx.rs @@ -18,15 +18,22 @@ struct TxPoolResponse { transactions: Vec, } -/// Implements a poller for the block builder to pull transactions from the transaction pool. +/// Implements a poller for the block builder to pull transactions from the +/// transaction pool. #[derive(Debug, Clone)] pub struct TxPoller { /// Config values from the Builder. - pub config: BuilderConfig, + config: &'static BuilderConfig, /// Reqwest Client for fetching transactions from the cache. - pub client: Client, + client: Client, /// Defines the interval at which the service should poll the cache. - pub poll_interval_ms: u64, + poll_interval_ms: u64, +} + +impl Default for TxPoller { + fn default() -> Self { + Self::new() + } } /// [`TxPoller`] implements a poller task that fetches transactions from the transaction pool @@ -34,13 +41,14 @@ pub struct TxPoller { impl TxPoller { /// Returns a new [`TxPoller`] with the given config. /// * Defaults to 1000ms poll interval (1s). - pub fn new(config: &BuilderConfig) -> Self { - Self { config: config.clone(), client: Client::new(), poll_interval_ms: POLL_INTERVAL_MS } + pub fn new() -> Self { + Self::new_with_poll_interval_ms(POLL_INTERVAL_MS) } /// Returns a new [`TxPoller`] with the given config and cache polling interval in milliseconds. - pub fn new_with_poll_interval_ms(config: &BuilderConfig, poll_interval_ms: u64) -> Self { - Self { config: config.clone(), client: Client::new(), poll_interval_ms } + pub fn new_with_poll_interval_ms(poll_interval_ms: u64) -> Self { + let config = crate::config(); + Self { config, client: Client::new(), poll_interval_ms } } /// Returns the poll duration as a [`Duration`]. diff --git a/src/tasks/env.rs b/src/tasks/env.rs index c5be9fa..d34f0f4 100644 --- a/src/tasks/env.rs +++ b/src/tasks/env.rs @@ -186,7 +186,7 @@ impl SimEnv { #[derive(Debug, Clone)] pub struct EnvTask { /// Builder configuration values. - config: BuilderConfig, + config: &'static BuilderConfig, /// Host provider is used to get the latest host block header for /// constructing the next block environment. @@ -202,13 +202,16 @@ pub struct EnvTask { impl EnvTask { /// Create a new [`EnvTask`] with the given config and providers. - pub const fn new( - config: BuilderConfig, - host_provider: HostProvider, - quincey: Quincey, - ru_provider: RuProvider, - ) -> Self { - Self { config, host_provider, quincey, ru_provider } + pub async fn new() -> eyre::Result { + let config = crate::config(); + + let (host_provider, quincey, ru_provider) = tokio::try_join!( + config.connect_host_provider(), + config.connect_quincey(), + config.connect_ru_provider(), + )?; + + Ok(Self { config, host_provider, quincey, ru_provider }) } /// Construct a [`BlockEnv`] for the next host block from the previous host header. @@ -278,7 +281,7 @@ impl EnvTask { let (host_block_res, quincey_res) = tokio::join!( self.host_provider.get_block_by_number(host_block_number.into()), - self.quincey.preflight_check(&self.config.constants, host_block_number) + self.quincey.preflight_check(host_block_number) ); res_unwrap_or_continue!( diff --git a/src/tasks/metrics.rs b/src/tasks/metrics.rs index a282354..699978c 100644 --- a/src/tasks/metrics.rs +++ b/src/tasks/metrics.rs @@ -17,8 +17,11 @@ pub struct MetricsTask { impl MetricsTask { /// Create a new MetricsTask with the given provider - pub const fn new(host_provider: HostProvider) -> Self { - Self { host_provider } + pub async fn new() -> eyre::Result { + let config = crate::config(); + let host_provider = config.connect_host_provider().await?; + + Ok(Self { host_provider }) } /// Given a transaction hash, record metrics on the result of the diff --git a/src/tasks/submit/flashbots.rs b/src/tasks/submit/flashbots.rs index 83edd79..f90a7a7 100644 --- a/src/tasks/submit/flashbots.rs +++ b/src/tasks/submit/flashbots.rs @@ -21,7 +21,7 @@ use tracing::{Instrument, debug, debug_span}; #[derive(Debug)] pub struct FlashbotsTask { /// Builder configuration for the task. - config: BuilderConfig, + config: &'static BuilderConfig, /// Quincey instance for block signing. quincey: Quincey, /// Zenith instance. @@ -37,14 +37,13 @@ pub struct FlashbotsTask { impl FlashbotsTask { /// Returns a new `FlashbotsTask` instance that receives `SimResult` types from the given /// channel and handles their preparation, submission to the Flashbots network. - pub async fn new( - config: BuilderConfig, - outbound: mpsc::UnboundedSender, - ) -> eyre::Result { + pub async fn new(outbound: mpsc::UnboundedSender) -> eyre::Result { + let config = crate::config(); + let (quincey, host_provider, flashbots, builder_key) = tokio::try_join!( config.connect_quincey(), config.connect_host_provider(), - config.connect_flashbots(&config), + config.connect_flashbots(), config.connect_builder_signer() )?; diff --git a/src/test_utils.rs b/src/test_utils.rs index c239366..05c45e5 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -20,43 +20,44 @@ use std::str::FromStr; use trevm::revm::{context::BlockEnv, context_interface::block::BlobExcessGasAndPrice}; /// Sets up a block builder with test values -pub fn setup_test_config() -> Result { - let config = BuilderConfig { - // host_chain_id: signet_constants::pecorino::HOST_CHAIN_ID, - host_rpc: "ws://host-rpc.pecorino.signet.sh" - .parse::() - .map(ProviderConfig::new) - .unwrap(), - ru_rpc: "ws://rpc.pecorino.signet.sh" - .parse::() - .unwrap() - .try_into() - .unwrap(), - flashbots_endpoint: Some("https://relay-sepolia.flashbots.net:443".parse().unwrap()), - quincey_url: "http://localhost:8080".into(), - sequencer_key: None, - builder_key: env::var("SEPOLIA_ETH_PRIV_KEY") - .unwrap_or_else(|_| B256::repeat_byte(0x42).to_string()), - builder_port: 8080, - builder_rewards_address: Address::default(), - rollup_block_gas_limit: 3_000_000_000, - tx_pool_url: "http://localhost:9000/".parse().unwrap(), - oauth: OAuthConfig { - oauth_client_id: "some_client_id".into(), - oauth_client_secret: "some_client_secret".into(), - oauth_authenticate_url: "http://localhost:8080".parse().unwrap(), - oauth_token_url: "http://localhost:8080".parse().unwrap(), - oauth_token_refresh_interval: 300, // 5 minutes - }, - concurrency_limit: None, // NB: Defaults to available parallelism - slot_calculator: SlotCalculator::new( - 1740681556, // pecorino start timestamp as sane default - 0, 1, - ), - max_host_gas_coefficient: Some(80), - constants: SignetSystemConstants::pecorino(), - }; - Ok(config) +pub fn setup_test_config() -> &'static BuilderConfig { + crate::CONFIG.get_or_init(|| { + BuilderConfig { + // host_chain_id: signet_constants::pecorino::HOST_CHAIN_ID, + host_rpc: "ws://host-rpc.pecorino.signet.sh" + .parse::() + .map(ProviderConfig::new) + .unwrap(), + ru_rpc: "ws://rpc.pecorino.signet.sh" + .parse::() + .unwrap() + .try_into() + .unwrap(), + flashbots_endpoint: Some("https://relay-sepolia.flashbots.net:443".parse().unwrap()), + quincey_url: "http://localhost:8080".into(), + sequencer_key: None, + builder_key: env::var("SEPOLIA_ETH_PRIV_KEY") + .unwrap_or_else(|_| B256::repeat_byte(0x42).to_string()), + builder_port: 8080, + builder_rewards_address: Address::default(), + rollup_block_gas_limit: 3_000_000_000, + tx_pool_url: "http://localhost:9000/".parse().unwrap(), + oauth: OAuthConfig { + oauth_client_id: "some_client_id".into(), + oauth_client_secret: "some_client_secret".into(), + oauth_authenticate_url: "http://localhost:8080".parse().unwrap(), + oauth_token_url: "http://localhost:8080".parse().unwrap(), + oauth_token_refresh_interval: 300, // 5 minutes + }, + concurrency_limit: None, // NB: Defaults to available parallelism + slot_calculator: SlotCalculator::new( + 1740681556, // pecorino start timestamp as sane default + 0, 1, + ), + max_host_gas_coefficient: Some(80), + constants: SignetSystemConstants::pecorino(), + } + }) } /// Returns a new signed test transaction with the provided nonce, value, and mpfpg. @@ -91,12 +92,8 @@ pub fn setup_logging() { /// Returns a Pecorino block environment for simulation with the timestamp set to `finish_by`, /// the block number set to latest + 1, system gas configs, and a beneficiary address. -pub fn test_block_env( - config: BuilderConfig, - number: u64, - basefee: u64, - timestamp: u64, -) -> BlockEnv { +pub fn test_block_env(number: u64, basefee: u64, timestamp: u64) -> BlockEnv { + let config = setup_test_config(); BlockEnv { number: U256::from(number), beneficiary: Address::repeat_byte(1), diff --git a/tests/block_builder_test.rs b/tests/block_builder_test.rs index a45e4a6..d972cc1 100644 --- a/tests/block_builder_test.rs +++ b/tests/block_builder_test.rs @@ -1,16 +1,12 @@ //! Tests for the block building task. use alloy::{ - eips::BlockId, - network::Ethereum, - node_bindings::Anvil, - primitives::U256, - providers::{Provider, RootProvider}, + eips::BlockId, node_bindings::Anvil, primitives::U256, providers::Provider, signers::local::PrivateKeySigner, }; use builder::{ tasks::{ - block::sim::Simulator, + block::sim::SimulatorTask, env::{EnvTask, Environment, SimEnv}, }, test_utils::{new_signed_tx, setup_logging, setup_test_config, test_block_env}, @@ -18,7 +14,7 @@ use builder::{ use signet_sim::SimCache; use std::time::{Duration, Instant}; -/// Tests the `handle_build` method of the `Simulator`. +/// Tests the `handle_build` method of the `SimulatorTask`. /// /// This test sets up a simulated environment using Anvil, creates a block builder, /// and verifies that the block builder can successfully build a block containing @@ -29,7 +25,7 @@ async fn test_handle_build() { setup_logging(); // Make a test config - let config = setup_test_config().unwrap(); + let config = setup_test_config(); // Create an anvil instance for testing let anvil_instance = Anvil::new().chain_id(signet_constants::pecorino::RU_CHAIN_ID).spawn(); @@ -39,18 +35,9 @@ async fn test_handle_build() { let test_key_0 = PrivateKeySigner::from_signing_key(keys[0].clone().into()); let test_key_1 = PrivateKeySigner::from_signing_key(keys[1].clone().into()); - // Create a rollup provider - let ru_provider = RootProvider::::new_http(anvil_instance.endpoint_url()); - let host_provider = config.connect_host_provider().await.unwrap(); + let block_env = EnvTask::new().await.unwrap().spawn().0; - // Create a quincey client - let quincey = config.connect_quincey().await.unwrap(); - - let block_env = - EnvTask::new(config.clone(), host_provider.clone(), quincey, ru_provider.clone()).spawn().0; - - let block_builder = - Simulator::new(&config, host_provider.clone(), ru_provider.clone(), block_env); + let block_builder = SimulatorTask::new(block_env).await.unwrap(); // Setup a sim cache let sim_items = SimCache::new(); @@ -64,10 +51,12 @@ async fn test_handle_build() { // Setup the block envs let finish_by = Instant::now() + Duration::from_secs(2); + + let ru_provider = builder::config().connect_ru_provider().await.unwrap(); let ru_header = ru_provider.get_block(BlockId::latest()).await.unwrap().unwrap().header.inner; let number = ru_header.number + 1; let timestamp = ru_header.timestamp + config.slot_calculator.slot_duration(); - let block_env = test_block_env(config, number, 7, timestamp); + let block_env = test_block_env(number, 7, timestamp); // Spawn the block builder task let sim_env = SimEnv { diff --git a/tests/bundle_poller_test.rs b/tests/bundle_poller_test.rs index 2e7a811..c49ac8f 100644 --- a/tests/bundle_poller_test.rs +++ b/tests/bundle_poller_test.rs @@ -1,13 +1,13 @@ -use builder::test_utils; +use builder::test_utils::{setup_logging, setup_test_config}; use eyre::Result; #[ignore = "integration test"] #[tokio::test] async fn test_bundle_poller_roundtrip() -> Result<()> { - let config = test_utils::setup_test_config().unwrap(); - let token = config.oauth_token(); + setup_logging(); + setup_test_config(); - let mut bundle_poller = builder::tasks::cache::BundlePoller::new(&config, token); + let mut bundle_poller = builder::tasks::cache::BundlePoller::new(); let _ = bundle_poller.check_bundle_cache().await?; diff --git a/tests/cache.rs b/tests/cache.rs index d975fca..5e9e796 100644 --- a/tests/cache.rs +++ b/tests/cache.rs @@ -9,17 +9,10 @@ use std::time::Duration; #[tokio::test] async fn test_bundle_poller_roundtrip() -> eyre::Result<()> { setup_logging(); + setup_test_config(); - let config = setup_test_config().unwrap(); - - let (block_env, _jh) = EnvTask::new( - config.clone(), - config.connect_host_provider().await?, - config.connect_quincey().await?, - config.connect_ru_provider().await?, - ) - .spawn(); - let cache_tasks = CacheTasks::new(config.clone(), block_env); + let (block_env, _jh) = EnvTask::new().await?.spawn(); + let cache_tasks = CacheTasks::new(block_env); let cache_system = cache_tasks.spawn(); tokio::time::sleep(Duration::from_secs(12)).await; diff --git a/tests/env.rs b/tests/env.rs index 634b459..c11c7de 100644 --- a/tests/env.rs +++ b/tests/env.rs @@ -7,16 +7,9 @@ use builder::{ #[tokio::test] async fn test_bundle_poller_roundtrip() -> eyre::Result<()> { setup_logging(); + let _ = setup_test_config(); - let config = setup_test_config().unwrap(); - - let (mut env_watcher, _jh) = EnvTask::new( - config.clone(), - config.connect_host_provider().await?, - config.connect_quincey().await?, - config.connect_ru_provider().await?, - ) - .spawn(); + let (mut env_watcher, _jh) = EnvTask::new().await?.spawn(); env_watcher.changed().await.unwrap(); let env = env_watcher.borrow_and_update(); diff --git a/tests/tx_poller_test.rs b/tests/tx_poller_test.rs index e48338f..075433a 100644 --- a/tests/tx_poller_test.rs +++ b/tests/tx_poller_test.rs @@ -1,6 +1,5 @@ use alloy::{primitives::U256, signers::local::PrivateKeySigner}; use builder::{ - config::BuilderConfig, tasks::cache::TxPoller, test_utils::{new_signed_tx, setup_logging, setup_test_config}, }; @@ -11,15 +10,13 @@ use eyre::{Ok, Result}; #[tokio::test] async fn test_tx_roundtrip() -> Result<()> { setup_logging(); - - // Create a new test environment - let config = setup_test_config()?; + setup_test_config(); // Post a transaction to the cache - post_tx(&config).await?; + post_tx().await?; // Create a new poller - let mut poller = TxPoller::new(&config); + let mut poller = TxPoller::new(); // Fetch transactions the pool let transactions = poller.check_tx_cache().await?; @@ -30,13 +27,13 @@ async fn test_tx_roundtrip() -> Result<()> { Ok(()) } -async fn post_tx(config: &BuilderConfig) -> Result<()> { +async fn post_tx() -> Result<()> { let client = reqwest::Client::new(); let wallet = PrivateKeySigner::random(); let tx_envelope = new_signed_tx(&wallet, 1, U256::from(1), 10_000)?; - let url = format!("{}/transactions", config.tx_pool_url); + let url = format!("{}/transactions", builder::config().tx_pool_url); let response = client.post(&url).json(&tx_envelope).send().await?; if !response.status().is_success() {