1use crate::{ParamsWithBlock, Provider, ProviderCall, ProviderLayer, RootProvider, RpcWithBlock};
2use alloy_eips::BlockId;
3use alloy_json_rpc::{RpcError, RpcSend};
4use alloy_network::Network;
5use alloy_primitives::{keccak256, Address, Bytes, StorageKey, StorageValue, TxHash, B256, U256};
6use alloy_rpc_types_eth::{BlockNumberOrTag, EIP1186AccountProofResponse, Filter, Log};
7use alloy_transport::{TransportErrorKind, TransportResult};
8use lru::LruCache;
9use parking_lot::RwLock;
10use serde::{Deserialize, Serialize};
11use std::{io::BufReader, marker::PhantomData, num::NonZero, path::PathBuf, sync::Arc};
12#[derive(Debug, Clone)]
20pub struct CacheLayer {
21 cache: SharedCache,
23}
24
25impl CacheLayer {
26 pub fn new(max_items: u32) -> Self {
29 Self { cache: SharedCache::new(max_items) }
30 }
31
32 pub const fn max_items(&self) -> u32 {
34 self.cache.max_items()
35 }
36
37 pub fn cache(&self) -> SharedCache {
39 self.cache.clone()
40 }
41}
42
43impl<P, N> ProviderLayer<P, N> for CacheLayer
44where
45 P: Provider<N>,
46 N: Network,
47{
48 type Provider = CacheProvider<P, N>;
49
50 fn layer(&self, inner: P) -> Self::Provider {
51 CacheProvider::new(inner, self.cache())
52 }
53}
54
55#[derive(Debug, Clone)]
63pub struct CacheProvider<P, N> {
64 inner: P,
66 cache: SharedCache,
68 _pd: PhantomData<N>,
70}
71
72impl<P, N> CacheProvider<P, N>
73where
74 P: Provider<N>,
75 N: Network,
76{
77 pub const fn new(inner: P, cache: SharedCache) -> Self {
79 Self { inner, cache, _pd: PhantomData }
80 }
81}
82
83macro_rules! rpc_call_with_block {
91 ($cache:expr, $client:expr, $req:expr) => {{
92 let client =
93 $client.upgrade().ok_or_else(|| TransportErrorKind::custom_str("RPC client dropped"));
94 let cache = $cache.clone();
95 ProviderCall::BoxedFuture(Box::pin(async move {
96 let client = client?;
97
98 let result = client.request($req.method(), $req.params()).map_params(|params| {
99 ParamsWithBlock::new(params, $req.block_id.unwrap_or(BlockId::latest()))
100 });
101
102 let res = result.await?;
103 let json_str = serde_json::to_string(&res).map_err(TransportErrorKind::custom)?;
105 let hash = $req.params_hash()?;
106 let _ = cache.put(hash, json_str);
107
108 Ok(res)
109 }))
110 }};
111}
112
113macro_rules! cache_rpc_call_with_block {
119 ($cache:expr, $client:expr, $req:expr) => {{
120 if $req.has_block_tag() {
121 return rpc_call_with_block!($cache, $client, $req);
122 }
123
124 let hash = $req.params_hash().ok();
125
126 if let Some(hash) = hash {
127 if let Ok(Some(cached)) = $cache.get_deserialized(&hash) {
128 return ProviderCall::BoxedFuture(Box::pin(async move { Ok(cached) }));
129 }
130 }
131
132 rpc_call_with_block!($cache, $client, $req)
133 }};
134}
135
136#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
137#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
138impl<P, N> Provider<N> for CacheProvider<P, N>
139where
140 P: Provider<N>,
141 N: Network,
142{
143 #[inline(always)]
144 fn root(&self) -> &RootProvider<N> {
145 self.inner.root()
146 }
147
148 fn get_block_receipts(
149 &self,
150 block: BlockId,
151 ) -> ProviderCall<(BlockId,), Option<Vec<N::ReceiptResponse>>> {
152 let req = RequestType::new("eth_getBlockReceipts", (block,));
153
154 let redirect = req.has_block_tag();
155
156 if !redirect {
157 let params_hash = req.params_hash().ok();
158
159 if let Some(hash) = params_hash {
160 if let Ok(Some(cached)) = self.cache.get_deserialized(&hash) {
161 return ProviderCall::BoxedFuture(Box::pin(async move { Ok(cached) }));
162 }
163 }
164 }
165
166 let client = self.inner.weak_client();
167 let cache = self.cache.clone();
168
169 ProviderCall::BoxedFuture(Box::pin(async move {
170 let client = client
171 .upgrade()
172 .ok_or_else(|| TransportErrorKind::custom_str("RPC client dropped"))?;
173
174 let result = client.request(req.method(), req.params()).await?;
175
176 let json_str = serde_json::to_string(&result).map_err(TransportErrorKind::custom)?;
177
178 if !redirect {
179 let hash = req.params_hash()?;
180 let _ = cache.put(hash, json_str);
181 }
182
183 Ok(result)
184 }))
185 }
186
187 fn get_code_at(&self, address: Address) -> RpcWithBlock<Address, Bytes> {
188 let client = self.inner.weak_client();
189 let cache = self.cache.clone();
190 RpcWithBlock::new_provider(move |block_id| {
191 let req = RequestType::new("eth_getCode", address).with_block_id(block_id);
192 cache_rpc_call_with_block!(cache, client, req)
193 })
194 }
195
196 async fn get_logs(&self, filter: &Filter) -> TransportResult<Vec<Log>> {
197 let req = RequestType::new("eth_getLogs", filter.clone());
198
199 let params_hash = req.params_hash().ok();
200
201 if let Some(hash) = params_hash {
202 if let Some(cached) = self.cache.get_deserialized(&hash)? {
203 return Ok(cached);
204 }
205 }
206
207 let result = self.inner.get_logs(filter).await?;
208
209 let json_str = serde_json::to_string(&result).map_err(TransportErrorKind::custom)?;
210
211 let hash = req.params_hash()?;
212 let _ = self.cache.put(hash, json_str);
213
214 Ok(result)
215 }
216
217 fn get_proof(
218 &self,
219 address: Address,
220 keys: Vec<StorageKey>,
221 ) -> RpcWithBlock<(Address, Vec<StorageKey>), EIP1186AccountProofResponse> {
222 let client = self.inner.weak_client();
223 let cache = self.cache.clone();
224 RpcWithBlock::new_provider(move |block_id| {
225 let req =
226 RequestType::new("eth_getProof", (address, keys.clone())).with_block_id(block_id);
227 cache_rpc_call_with_block!(cache, client, req)
228 })
229 }
230
231 fn get_storage_at(
232 &self,
233 address: Address,
234 key: U256,
235 ) -> RpcWithBlock<(Address, U256), StorageValue> {
236 let client = self.inner.weak_client();
237 let cache = self.cache.clone();
238 RpcWithBlock::new_provider(move |block_id| {
239 let req = RequestType::new("eth_getStorageAt", (address, key)).with_block_id(block_id);
240 cache_rpc_call_with_block!(cache, client, req)
241 })
242 }
243
244 fn get_transaction_by_hash(
245 &self,
246 hash: TxHash,
247 ) -> ProviderCall<(TxHash,), Option<N::TransactionResponse>> {
248 let req = RequestType::new("eth_getTransactionByHash", (hash,));
249
250 let params_hash = req.params_hash().ok();
251
252 if let Some(hash) = params_hash {
253 if let Ok(Some(cached)) = self.cache.get_deserialized(&hash) {
254 return ProviderCall::BoxedFuture(Box::pin(async move { Ok(cached) }));
255 }
256 }
257 let client = self.inner.weak_client();
258 let cache = self.cache.clone();
259 ProviderCall::BoxedFuture(Box::pin(async move {
260 let client = client
261 .upgrade()
262 .ok_or_else(|| TransportErrorKind::custom_str("RPC client dropped"))?;
263 let result = client.request(req.method(), req.params()).await?;
264
265 let json_str = serde_json::to_string(&result).map_err(TransportErrorKind::custom)?;
266 let hash = req.params_hash()?;
267 let _ = cache.put(hash, json_str);
268
269 Ok(result)
270 }))
271 }
272
273 fn get_raw_transaction_by_hash(&self, hash: TxHash) -> ProviderCall<(TxHash,), Option<Bytes>> {
274 let req = RequestType::new("eth_getRawTransactionByHash", (hash,));
275
276 let params_hash = req.params_hash().ok();
277
278 if let Some(hash) = params_hash {
279 if let Ok(Some(cached)) = self.cache.get_deserialized(&hash) {
280 return ProviderCall::BoxedFuture(Box::pin(async move { Ok(cached) }));
281 }
282 }
283
284 let client = self.inner.weak_client();
285 let cache = self.cache.clone();
286 ProviderCall::BoxedFuture(Box::pin(async move {
287 let client = client
288 .upgrade()
289 .ok_or_else(|| TransportErrorKind::custom_str("RPC client dropped"))?;
290
291 let result = client.request(req.method(), req.params()).await?;
292
293 let json_str = serde_json::to_string(&result).map_err(TransportErrorKind::custom)?;
294 let hash = req.params_hash()?;
295 let _ = cache.put(hash, json_str);
296
297 Ok(result)
298 }))
299 }
300
301 fn get_transaction_receipt(
302 &self,
303 hash: TxHash,
304 ) -> ProviderCall<(TxHash,), Option<N::ReceiptResponse>> {
305 let req = RequestType::new("eth_getTransactionReceipt", (hash,));
306
307 let params_hash = req.params_hash().ok();
308
309 if let Some(hash) = params_hash {
310 if let Ok(Some(cached)) = self.cache.get_deserialized(&hash) {
311 return ProviderCall::BoxedFuture(Box::pin(async move { Ok(cached) }));
312 }
313 }
314
315 let client = self.inner.weak_client();
316 let cache = self.cache.clone();
317 ProviderCall::BoxedFuture(Box::pin(async move {
318 let client = client
319 .upgrade()
320 .ok_or_else(|| TransportErrorKind::custom_str("RPC client dropped"))?;
321
322 let result = client.request(req.method(), req.params()).await?;
323
324 let json_str = serde_json::to_string(&result).map_err(TransportErrorKind::custom)?;
325 let hash = req.params_hash()?;
326 let _ = cache.put(hash, json_str);
327
328 Ok(result)
329 }))
330 }
331}
332
333struct RequestType<Params: RpcSend> {
335 method: &'static str,
336 params: Params,
337 block_id: Option<BlockId>,
338}
339
340impl<Params: RpcSend> RequestType<Params> {
341 const fn new(method: &'static str, params: Params) -> Self {
342 Self { method, params, block_id: None }
343 }
344
345 const fn with_block_id(mut self, block_id: BlockId) -> Self {
346 self.block_id = Some(block_id);
347 self
348 }
349
350 fn params_hash(&self) -> TransportResult<B256> {
351 let hash = serde_json::to_string(&self.params())
355 .map(|p| {
356 keccak256(
357 match self.block_id {
358 Some(BlockId::Hash(rpc_block_hash)) => {
359 format!("{}{}{}", rpc_block_hash, self.method(), p)
360 }
361 Some(BlockId::Number(BlockNumberOrTag::Number(number))) => {
362 format!("{}{}{}", number, self.method(), p)
363 }
364 _ => format!("{}{}", self.method(), p),
365 }
366 .as_bytes(),
367 )
368 })
369 .map_err(RpcError::ser_err)?;
370
371 Ok(hash)
372 }
373
374 const fn method(&self) -> &'static str {
375 self.method
376 }
377
378 fn params(&self) -> Params {
379 self.params.clone()
380 }
381
382 const fn has_block_tag(&self) -> bool {
385 if let Some(block_id) = self.block_id {
386 return !matches!(
387 block_id,
388 BlockId::Hash(_) | BlockId::Number(BlockNumberOrTag::Number(_))
389 );
390 }
391 false
392 }
393}
394
395#[derive(Debug, Serialize, Deserialize)]
396struct FsCacheEntry {
397 key: B256,
399 value: String,
401}
402
403#[derive(Debug, Clone)]
405pub struct SharedCache {
406 inner: Arc<RwLock<LruCache<B256, String, alloy_primitives::map::FbBuildHasher<32>>>>,
407 max_items: NonZero<usize>,
408}
409
410impl SharedCache {
411 pub fn new(max_items: u32) -> Self {
413 let max_items = NonZero::new(max_items as usize).unwrap_or(NonZero::<usize>::MIN);
414 let inner = Arc::new(RwLock::new(LruCache::with_hasher(max_items, Default::default())));
415 Self { inner, max_items }
416 }
417
418 pub const fn max_items(&self) -> u32 {
420 self.max_items.get() as u32
421 }
422
423 pub fn put(&self, key: B256, value: String) -> TransportResult<bool> {
425 Ok(self.inner.write().put(key, value).is_some())
426 }
427
428 pub fn get(&self, key: &B256) -> Option<String> {
430 self.inner.write().get(key).cloned()
432 }
433
434 pub fn get_deserialized<T>(&self, key: &B256) -> TransportResult<Option<T>>
436 where
437 T: for<'de> Deserialize<'de>,
438 {
439 let Some(cached) = self.get(key) else { return Ok(None) };
440 let result = serde_json::from_str(&cached).map_err(TransportErrorKind::custom)?;
441 Ok(Some(result))
442 }
443
444 pub fn save_cache(&self, path: PathBuf) -> TransportResult<()> {
448 let entries: Vec<FsCacheEntry> = {
449 self.inner
450 .read()
451 .iter()
452 .map(|(key, value)| FsCacheEntry { key: *key, value: value.clone() })
453 .collect()
454 };
455 let file = std::fs::File::create(path).map_err(TransportErrorKind::custom)?;
456 serde_json::to_writer(file, &entries).map_err(TransportErrorKind::custom)?;
457 Ok(())
458 }
459
460 pub fn load_cache(&self, path: PathBuf) -> TransportResult<()> {
463 if !path.exists() {
464 return Ok(());
465 };
466 let file = std::fs::File::open(path).map_err(TransportErrorKind::custom)?;
467 let file = BufReader::new(file);
468 let entries: Vec<FsCacheEntry> =
469 serde_json::from_reader(file).map_err(TransportErrorKind::custom)?;
470 let mut cache = self.inner.write();
471 for entry in entries {
472 cache.put(entry.key, entry.value);
473 }
474
475 Ok(())
476 }
477}
478
479#[cfg(test)]
480mod tests {
481 use super::*;
482 use crate::ProviderBuilder;
483 use alloy_network::TransactionBuilder;
484 use alloy_node_bindings::{utils::run_with_tempdir, Anvil};
485 use alloy_primitives::{bytes, hex, Bytes, FixedBytes};
486 use alloy_rpc_types_eth::{BlockId, TransactionRequest};
487
488 #[tokio::test]
489 async fn test_get_proof() {
490 run_with_tempdir("get-proof", |dir| async move {
491 let cache_layer = CacheLayer::new(100);
492 let shared_cache = cache_layer.cache();
493 let anvil = Anvil::new().block_time_f64(0.3).spawn();
494 let provider = ProviderBuilder::new().layer(cache_layer).connect_http(anvil.endpoint_url());
495
496 let from = anvil.addresses()[0];
497 let path = dir.join("rpc-cache-proof.txt");
498
499 shared_cache.load_cache(path.clone()).unwrap();
500
501 let calldata: Bytes = "0x6080604052348015600f57600080fd5b506101f28061001f6000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80633fb5c1cb146100465780638381f58a14610062578063d09de08a14610080575b600080fd5b610060600480360381019061005b91906100ee565b61008a565b005b61006a610094565b604051610077919061012a565b60405180910390f35b61008861009a565b005b8060008190555050565b60005481565b6000808154809291906100ac90610174565b9190505550565b600080fd5b6000819050919050565b6100cb816100b8565b81146100d657600080fd5b50565b6000813590506100e8816100c2565b92915050565b600060208284031215610104576101036100b3565b5b6000610112848285016100d9565b91505092915050565b610124816100b8565b82525050565b600060208201905061013f600083018461011b565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061017f826100b8565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036101b1576101b0610145565b5b60018201905091905056fea264697066735822122067ac0f21f648b0cacd1b7260772852ad4a0f63e2cc174168c51a6887fd5197a964736f6c634300081a0033".parse().unwrap();
502
503 let tx = TransactionRequest::default()
504 .with_from(from)
505 .with_input(calldata)
506 .with_max_fee_per_gas(1_000_000_000)
507 .with_max_priority_fee_per_gas(1_000_000)
508 .with_gas_limit(1_000_000)
509 .with_nonce(0);
510
511 let tx_receipt = provider.send_transaction(tx).await.unwrap().get_receipt().await.unwrap();
512
513 let counter_addr = tx_receipt.contract_address.unwrap();
514
515 let keys = vec![
516 FixedBytes::with_last_byte(0),
517 FixedBytes::with_last_byte(0x1),
518 FixedBytes::with_last_byte(0x2),
519 FixedBytes::with_last_byte(0x3),
520 FixedBytes::with_last_byte(0x4),
521 ];
522
523 let proof =
524 provider.get_proof(counter_addr, keys.clone()).block_id(1.into()).await.unwrap();
525 let proof2 = provider.get_proof(counter_addr, keys).block_id(1.into()).await.unwrap();
526
527 assert_eq!(proof, proof2);
528
529 shared_cache.save_cache(path).unwrap();
530 }).await;
531 }
532
533 #[tokio::test]
534 async fn test_get_tx_by_hash_and_receipt() {
535 run_with_tempdir("get-tx-by-hash", |dir| async move {
536 let cache_layer = CacheLayer::new(100);
537 let shared_cache = cache_layer.cache();
538 let anvil = Anvil::new().block_time_f64(0.3).spawn();
539 let provider = ProviderBuilder::new()
540 .disable_recommended_fillers()
541 .layer(cache_layer)
542 .connect_http(anvil.endpoint_url());
543
544 let path = dir.join("rpc-cache-tx.txt");
545 shared_cache.load_cache(path.clone()).unwrap();
546
547 let req = TransactionRequest::default()
548 .from(anvil.addresses()[0])
549 .to(Address::repeat_byte(5))
550 .value(U256::ZERO)
551 .input(bytes!("deadbeef").into());
552
553 let tx_hash =
554 *provider.send_transaction(req).await.expect("failed to send tx").tx_hash();
555
556 let tx = provider.get_transaction_by_hash(tx_hash).await.unwrap(); let tx2 = provider.get_transaction_by_hash(tx_hash).await.unwrap(); assert_eq!(tx, tx2);
559
560 let receipt = provider.get_transaction_receipt(tx_hash).await.unwrap(); let receipt2 = provider.get_transaction_receipt(tx_hash).await.unwrap(); assert_eq!(receipt, receipt2);
564
565 shared_cache.save_cache(path).unwrap();
566 })
567 .await;
568 }
569
570 #[tokio::test]
571 async fn test_block_receipts() {
572 run_with_tempdir("get-block-receipts", |dir| async move {
573 let cache_layer = CacheLayer::new(100);
574 let shared_cache = cache_layer.cache();
575 let anvil = Anvil::new().spawn();
576 let provider = ProviderBuilder::new().layer(cache_layer).connect_http(anvil.endpoint_url());
577
578 let path = dir.join("rpc-cache-block-receipts.txt");
579 shared_cache.load_cache(path.clone()).unwrap();
580
581 let receipt = provider
584 .send_raw_transaction(
585 bytes!("f865808477359400825208940000000000000000000000000000000000000000018082f4f5a00505e227c1c636c76fac55795db1a40a4d24840d81b40d2fe0cc85767f6bd202a01e91b437099a8a90234ac5af3cb7ca4fb1432e133f75f9a91678eaf5f487c74b").as_ref()
587 )
588 .await.unwrap().get_receipt().await.unwrap();
589
590 let block_number = receipt.block_number.unwrap();
591
592 let receipts =
593 provider.get_block_receipts(block_number.into()).await.unwrap(); let receipts2 =
595 provider.get_block_receipts(block_number.into()).await.unwrap(); assert_eq!(receipts, receipts2);
597
598 assert!(receipts.is_some_and(|r| r[0] == receipt));
599
600 shared_cache.save_cache(path).unwrap();
601 })
602 .await
603 }
604
605 #[tokio::test]
606 async fn test_get_code() {
607 run_with_tempdir("get-code", |dir| async move {
608 let cache_layer = CacheLayer::new(100);
609 let shared_cache = cache_layer.cache();
610 let provider = ProviderBuilder::new().disable_recommended_fillers().with_gas_estimation().layer(cache_layer).connect_anvil_with_wallet();
611
612 let path = dir.join("rpc-cache-code.txt");
613 shared_cache.load_cache(path.clone()).unwrap();
614
615 let bytecode = hex::decode(
616 "6080806040523460135760df908160198239f35b600080fdfe6080806040526004361015601257600080fd5b60003560e01c9081633fb5c1cb1460925781638381f58a146079575063d09de08a14603c57600080fd5b3460745760003660031901126074576000546000198114605e57600101600055005b634e487b7160e01b600052601160045260246000fd5b600080fd5b3460745760003660031901126074576020906000548152f35b34607457602036600319011260745760043560005500fea2646970667358221220e978270883b7baed10810c4079c941512e93a7ba1cd1108c781d4bc738d9090564736f6c634300081a0033"
618 ).unwrap();
619 let tx = TransactionRequest::default().with_nonce(0).with_deploy_code(bytecode).with_chain_id(31337);
620
621 let receipt = provider.send_transaction(tx).await.unwrap().get_receipt().await.unwrap();
622
623 let counter_addr = receipt.contract_address.unwrap();
624
625 let block_id = BlockId::number(receipt.block_number.unwrap());
626
627 let code = provider.get_code_at(counter_addr).block_id(block_id).await.unwrap(); let code2 = provider.get_code_at(counter_addr).block_id(block_id).await.unwrap(); assert_eq!(code, code2);
630
631 shared_cache.save_cache(path).unwrap();
632 })
633 .await;
634 }
635
636 #[cfg(all(test, feature = "anvil-api"))]
637 #[tokio::test]
638 async fn test_get_storage_at_different_block_ids() {
639 use crate::ext::AnvilApi;
640
641 run_with_tempdir("get-code-different-block-id", |dir| async move {
642 let cache_layer = CacheLayer::new(100);
643 let shared_cache = cache_layer.cache();
644 let provider = ProviderBuilder::new().disable_recommended_fillers().with_gas_estimation().layer(cache_layer).connect_anvil_with_wallet();
645
646 let path = dir.join("rpc-cache-code.txt");
647 shared_cache.load_cache(path.clone()).unwrap();
648
649 let bytecode = hex::decode(
650 "6080806040523460135760df908160198239f35b600080fdfe6080806040526004361015601257600080fd5b60003560e01c9081633fb5c1cb1460925781638381f58a146079575063d09de08a14603c57600080fd5b3460745760003660031901126074576000546000198114605e57600101600055005b634e487b7160e01b600052601160045260246000fd5b600080fd5b3460745760003660031901126074576020906000548152f35b34607457602036600319011260745760043560005500fea2646970667358221220e978270883b7baed10810c4079c941512e93a7ba1cd1108c781d4bc738d9090564736f6c634300081a0033"
652 ).unwrap();
653
654 let tx = TransactionRequest::default().with_nonce(0).with_deploy_code(bytecode).with_chain_id(31337);
655 let receipt = provider.send_transaction(tx).await.unwrap().get_receipt().await.unwrap();
656 let counter_addr = receipt.contract_address.unwrap();
657 let block_id = BlockId::number(receipt.block_number.unwrap());
658
659 let counter = provider.get_storage_at(counter_addr, U256::ZERO).block_id(block_id).await.unwrap(); assert_eq!(counter, U256::ZERO);
661 let counter_cached = provider.get_storage_at(counter_addr, U256::ZERO).block_id(block_id).await.unwrap(); assert_eq!(counter, counter_cached);
663
664 provider.anvil_mine(Some(1), None).await.unwrap();
665
666 let tx2 = TransactionRequest::default().with_nonce(1).to(counter_addr).input(hex::decode("d09de08a").unwrap().into()).with_chain_id(31337);
668 let receipt2 = provider.send_transaction(tx2).await.unwrap().get_receipt().await.unwrap();
669 let block_id2 = BlockId::number(receipt2.block_number.unwrap());
670
671 let counter2 = provider.get_storage_at(counter_addr, U256::ZERO).block_id(block_id2).await.unwrap(); assert_eq!(counter2, U256::from(1));
673 let counter2_cached = provider.get_storage_at(counter_addr, U256::ZERO).block_id(block_id2).await.unwrap(); assert_eq!(counter2, counter2_cached);
675
676 shared_cache.save_cache(path).unwrap();
677 })
678 .await;
679 }
680}