Skip to content

Commit ae49c60

Browse files
author
Naohiro Yoshida
committed
make cache optional
1 parent c3b1745 commit ae49c60

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

server/src/host/single/handler.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use tokio::sync::RwLock;
2929

3030
#[derive(Debug, Clone)]
3131
pub struct DerivationRequest {
32-
pub cache: Cache,
32+
pub cache: Option<Cache>,
3333
pub metrics: Arc<Metrics>,
3434
pub config: Config,
3535
pub rollup_config: RollupConfig,
@@ -79,12 +79,15 @@ impl DerivationRequest {
7979

8080
fn http_provider<N: Network>(
8181
url: &str,
82-
cache: Cache,
82+
cache: Option<Cache>,
8383
metrics: Arc<Metrics>,
8484
) -> RootProvider<N> {
8585
let url = url.parse().unwrap();
8686
let http = Http::<Client>::new(url);
87-
let http = HttpProxy::new(cache, metrics, http);
87+
if let Some(cache) = cache {
88+
let http = HttpProxy::new(cache, metrics, http);
89+
return RootProvider::new(RpcClient::new(http, true));
90+
}
8891
RootProvider::new(RpcClient::new(http, true))
8992
}
9093

server/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ async fn main() -> anyhow::Result<()> {
2727
.with(filter)
2828
.init();
2929
info!("start optimism preimage-maker");
30+
let cache = if config.cache_size > 0 {
31+
info!("enable rpc cache with size {}", config.cache_size);
32+
Some(new_cache(config.cache_size))
33+
} else {
34+
info!("disable rpc cache with size");
35+
None
36+
};
3037

3138
let l2_client = L2Client::new(
3239
config.l2_rollup_address.to_string(),
@@ -41,7 +48,7 @@ async fn main() -> anyhow::Result<()> {
4148
DerivationState {
4249
rollup_config: rollup_config.clone(),
4350
config: config.clone(),
44-
cache: new_cache(config.cache_size),
51+
cache,
4552
metrics: Arc::new(Metrics::new()),
4653
l2_chain_id: chain_id,
4754
},

server/src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct DerivationState {
2020
pub rollup_config: RollupConfig,
2121
pub config: Config,
2222
pub l2_chain_id: u64,
23-
pub cache: Cache,
23+
pub cache: Option<Cache>,
2424
pub metrics: Arc<Metrics>,
2525
}
2626

0 commit comments

Comments
 (0)