Skip to content

Commit 6575e67

Browse files
committed
chore(cache): move cache system out of config
There's no reason for this to be contained here, and feels wrong when every other task has its own file / spawn pattern.
1 parent b30b12a commit 6575e67

File tree

5 files changed

+62
-49
lines changed

5 files changed

+62
-49
lines changed

bin/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use builder::{
22
config::BuilderConfig,
33
service::serve_builder,
4-
tasks::{block::sim::Simulator, metrics::MetricsTask, submit::SubmitTask},
4+
tasks::{block::sim::Simulator, cache::CacheSystem, metrics::MetricsTask, submit::SubmitTask},
55
};
66
use init4_bin_base::{
77
deps::tracing::{info, info_span},
@@ -26,7 +26,7 @@ async fn main() -> eyre::Result<()> {
2626
let (block_env, env_jh) = env_task.spawn();
2727

2828
// Spawn the cache system
29-
let cache_system = config.spawn_cache_system(block_env.clone());
29+
let cache_system = CacheSystem::spawn(&config, block_env.clone());
3030

3131
// Prep providers and contracts
3232
let (host_provider, quincey) =

src/config.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
use crate::{
22
quincey::Quincey,
3-
tasks::{
4-
block::cfg::SignetCfgEnv,
5-
cache::{BundlePoller, CacheSystem, CacheTask, TxPoller},
6-
env::{EnvTask, SimEnv},
7-
},
3+
tasks::{block::cfg::SignetCfgEnv, env::EnvTask},
84
};
95
use alloy::{
106
network::{Ethereum, EthereumWallet},
@@ -28,7 +24,6 @@ use init4_bin_base::{
2824
};
2925
use signet_zenith::Zenith;
3026
use std::borrow::Cow;
31-
use tokio::sync::watch;
3227

3328
/// Type alias for the provider used to simulate against rollup state.
3429
pub type RuProvider = RootProvider<Ethereum>;
@@ -255,27 +250,6 @@ impl BuilderConfig {
255250
EnvTask::new(self.clone(), ru_provider)
256251
}
257252

258-
/// Spawn a new [`CacheSystem`] using this config. This contains the
259-
/// joinhandles for [`TxPoller`] and [`BundlePoller`] and [`CacheTask`], as
260-
/// well as the [`SimCache`] and the block env watcher.
261-
///
262-
/// [`SimCache`]: signet_sim::SimCache
263-
pub fn spawn_cache_system(&self, block_env: watch::Receiver<Option<SimEnv>>) -> CacheSystem {
264-
// Tx Poller pulls transactions from the cache
265-
let tx_poller = TxPoller::new(self);
266-
let (tx_receiver, tx_poller) = tx_poller.spawn();
267-
268-
// Bundle Poller pulls bundles from the cache
269-
let bundle_poller = BundlePoller::new(self, self.oauth_token());
270-
let (bundle_receiver, bundle_poller) = bundle_poller.spawn();
271-
272-
// Set up the cache task
273-
let cache_task = CacheTask::new(block_env.clone(), bundle_receiver, tx_receiver);
274-
let (sim_cache, cache_task) = cache_task.spawn();
275-
276-
CacheSystem { cache_task, tx_poller, bundle_poller, sim_cache }
277-
}
278-
279253
/// Create a [`SignetCfgEnv`] using this config.
280254
pub const fn cfg_env(&self) -> SignetCfgEnv {
281255
SignetCfgEnv { chain_id: self.ru_chain_id }

src/tasks/cache/mod.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,5 @@ pub use tx::TxPoller;
77
mod bundle;
88
pub use bundle::BundlePoller;
99

10-
use signet_sim::SimCache;
11-
use tokio::task::JoinHandle;
12-
13-
/// Cache tasks for the block builder.
14-
#[derive(Debug)]
15-
pub struct CacheSystem {
16-
/// The cache task.
17-
pub cache_task: JoinHandle<()>,
18-
19-
/// The transaction poller task.
20-
pub tx_poller: JoinHandle<()>,
21-
22-
/// The bundle poller task.
23-
pub bundle_poller: JoinHandle<()>,
24-
25-
/// The sim cache.
26-
pub sim_cache: SimCache,
27-
}
10+
mod system;
11+
pub use system::CacheSystem;

src/tasks/cache/system.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use signet_sim::SimCache;
2+
use tokio::{sync::watch, task::JoinHandle};
3+
4+
use crate::{
5+
config::BuilderConfig,
6+
tasks::{
7+
cache::{BundlePoller, CacheTask, TxPoller},
8+
env::SimEnv,
9+
},
10+
};
11+
12+
/// Cache tasks for the block builder.
13+
#[derive(Debug)]
14+
pub struct CacheSystem {
15+
/// The cache task.
16+
pub cache_task: JoinHandle<()>,
17+
18+
/// The transaction poller task.
19+
pub tx_poller: JoinHandle<()>,
20+
21+
/// The bundle poller task.
22+
pub bundle_poller: JoinHandle<()>,
23+
24+
/// The sim cache.
25+
pub sim_cache: SimCache,
26+
}
27+
28+
impl CacheSystem {
29+
/// Spawn a new [`CacheSystem`]. This contains the
30+
/// joinhandles for [`TxPoller`] and [`BundlePoller`] and [`CacheTask`], as
31+
/// well as the [`SimCache`] and the block env watcher.
32+
///
33+
/// [`SimCache`]: signet_sim::SimCache
34+
pub fn spawn(
35+
config: &BuilderConfig,
36+
block_env: watch::Receiver<Option<SimEnv>>,
37+
) -> CacheSystem {
38+
// Tx Poller pulls transactions from the cache
39+
let tx_poller = TxPoller::new(config);
40+
let (tx_receiver, tx_poller) = tx_poller.spawn();
41+
42+
// Bundle Poller pulls bundles from the cache
43+
let bundle_poller = BundlePoller::new(config, config.oauth_token());
44+
let (bundle_receiver, bundle_poller) = bundle_poller.spawn();
45+
46+
// Set up the cache task
47+
let cache_task = CacheTask::new(block_env.clone(), bundle_receiver, tx_receiver);
48+
let (sim_cache, cache_task) = cache_task.spawn();
49+
50+
CacheSystem { cache_task, tx_poller, bundle_poller, sim_cache }
51+
}
52+
}

tests/cache.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use builder::test_utils::{setup_logging, setup_test_config};
1+
use builder::{
2+
tasks::cache::CacheSystem,
3+
test_utils::{setup_logging, setup_test_config},
4+
};
25
use init4_bin_base::deps::tracing::warn;
36
use std::time::Duration;
47

@@ -10,7 +13,7 @@ async fn test_bundle_poller_roundtrip() -> eyre::Result<()> {
1013
let config = setup_test_config().unwrap();
1114

1215
let (block_env, _jh) = config.env_task().spawn();
13-
let cache = config.spawn_cache_system(block_env);
16+
let cache = CacheSystem::spawn(&config, block_env);
1417

1518
tokio::time::sleep(Duration::from_secs(12)).await;
1619

0 commit comments

Comments
 (0)