Skip to main content

anvil/eth/backend/
fork.rs

1//! Support for forking off another client
2
3use crate::eth::{backend::db::Db, error::BlockchainError, pool::transactions::PoolTransaction};
4use alloy_consensus::{BlockHeader, TrieAccount};
5use alloy_eips::eip2930::AccessListResult;
6use alloy_network::{
7    AnyNetwork, AnyRpcBlock, BlockResponse, Network, TransactionResponse,
8    primitives::HeaderResponse,
9};
10use alloy_primitives::{
11    Address, B256, Bytes, StorageValue, U256,
12    map::{FbHashMap, HashMap, HashSet},
13};
14use alloy_provider::{
15    Provider,
16    ext::{DebugApi, TraceApi},
17};
18use alloy_rpc_types::{
19    BlockId, BlockNumberOrTag as BlockNumber, BlockTransactions, EIP1186AccountProofResponse,
20    FeeHistory, Filter, Log,
21    simulate::{SimulatePayload, SimulatedBlock},
22    trace::{
23        geth::{GethDebugTracingOptions, GethTrace},
24        parity::{LocalizedTransactionTrace as Trace, TraceResultsWithTransactionHash, TraceType},
25    },
26};
27use alloy_transport::TransportError;
28use foundry_common::provider::{ProviderBuilder, RetryProvider};
29use foundry_primitives::{FoundryTxEnvelope, FoundryTxReceipt};
30use parking_lot::{
31    RawRwLock, RwLock,
32    lock_api::{RwLockReadGuard, RwLockWriteGuard},
33};
34use revm::context_interface::block::BlobExcessGasAndPrice;
35use std::{sync::Arc, time::Duration};
36use tokio::sync::RwLock as AsyncRwLock;
37
38/// Represents a fork of a remote client
39///
40/// This type contains a subset of the [`EthApi`](crate::eth::EthApi) functions but will exclusively
41/// fetch the requested data from the remote client, if it wasn't already fetched.
42#[derive(Clone, Debug)]
43pub struct ClientFork<N: Network = AnyNetwork> {
44    /// Contains the cached data
45    pub storage: Arc<RwLock<ForkedStorage<N>>>,
46    /// contains the info how the fork is configured
47    // Wrapping this in a lock, ensures we can update this on the fly via additional custom RPC
48    // endpoints
49    pub config: Arc<RwLock<ClientForkConfig<N>>>,
50    /// This also holds a handle to the underlying database
51    pub database: Arc<AsyncRwLock<Box<dyn Db>>>,
52}
53
54impl<N: Network> ClientFork<N> {
55    /// Creates a new instance of the fork
56    pub fn new(config: ClientForkConfig<N>, database: Arc<AsyncRwLock<Box<dyn Db>>>) -> Self {
57        Self { storage: Default::default(), config: Arc::new(RwLock::new(config)), database }
58    }
59
60    /// Removes all data cached from previous responses
61    pub fn clear_cached_storage(&self) {
62        self.storage.write().clear()
63    }
64
65    /// Returns true whether the block predates the fork
66    pub fn predates_fork(&self, block: u64) -> bool {
67        block < self.block_number()
68    }
69
70    /// Returns true whether the block predates the fork _or_ is the same block as the fork
71    pub fn predates_fork_inclusive(&self, block: u64) -> bool {
72        block <= self.block_number()
73    }
74
75    pub fn timestamp(&self) -> u64 {
76        self.config.read().timestamp
77    }
78
79    pub fn block_number(&self) -> u64 {
80        self.config.read().block_number
81    }
82
83    /// Returns the transaction hash we forked off of, if any.
84    pub fn transaction_hash(&self) -> Option<B256> {
85        self.config.read().transaction_hash
86    }
87
88    pub fn total_difficulty(&self) -> U256 {
89        self.config.read().total_difficulty
90    }
91
92    pub fn base_fee(&self) -> Option<u128> {
93        self.config.read().base_fee
94    }
95
96    pub fn block_hash(&self) -> B256 {
97        self.config.read().block_hash
98    }
99
100    pub fn eth_rpc_url(&self) -> String {
101        self.config.read().eth_rpc_url.clone()
102    }
103
104    pub fn chain_id(&self) -> u64 {
105        self.config.read().chain_id
106    }
107
108    fn provider(&self) -> Arc<RetryProvider<N>> {
109        self.config.read().provider.clone()
110    }
111
112    fn storage_read(&self) -> RwLockReadGuard<'_, RawRwLock, ForkedStorage<N>> {
113        self.storage.read()
114    }
115
116    fn storage_write(&self) -> RwLockWriteGuard<'_, RawRwLock, ForkedStorage<N>> {
117        self.storage.write()
118    }
119
120    /// Returns the fee history  `eth_feeHistory`
121    pub async fn fee_history(
122        &self,
123        block_count: u64,
124        newest_block: BlockNumber,
125        reward_percentiles: &[f64],
126    ) -> Result<FeeHistory, TransportError> {
127        self.provider().get_fee_history(block_count, newest_block, reward_percentiles).await
128    }
129
130    /// Sends `eth_getProof`
131    pub async fn get_proof(
132        &self,
133        address: Address,
134        keys: Vec<B256>,
135        block_number: Option<BlockId>,
136    ) -> Result<EIP1186AccountProofResponse, TransportError> {
137        self.provider().get_proof(address, keys).block_id(block_number.unwrap_or_default()).await
138    }
139
140    pub async fn storage_at(
141        &self,
142        address: Address,
143        index: U256,
144        number: Option<BlockNumber>,
145    ) -> Result<StorageValue, TransportError> {
146        self.provider()
147            .get_storage_at(address, index)
148            .block_id(number.unwrap_or_default().into())
149            .await
150    }
151
152    pub async fn logs(&self, filter: &Filter) -> Result<Vec<Log>, TransportError> {
153        if let Some(logs) = self.storage_read().logs.get(filter).cloned() {
154            return Ok(logs);
155        }
156
157        let logs = self.provider().get_logs(filter).await?;
158
159        let mut storage = self.storage_write();
160        storage.logs.insert(filter.clone(), logs.clone());
161        Ok(logs)
162    }
163
164    pub async fn get_code(
165        &self,
166        address: Address,
167        blocknumber: u64,
168    ) -> Result<Bytes, TransportError> {
169        trace!(target: "backend::fork", "get_code={:?}", address);
170        if let Some(code) = self.storage_read().code_at.get(&(address, blocknumber)).cloned() {
171            return Ok(code);
172        }
173
174        let block_id = BlockId::number(blocknumber);
175
176        let code = self.provider().get_code_at(address).block_id(block_id).await?;
177
178        let mut storage = self.storage_write();
179        storage.code_at.insert((address, blocknumber), code.clone());
180
181        Ok(code)
182    }
183
184    pub async fn get_balance(
185        &self,
186        address: Address,
187        blocknumber: u64,
188    ) -> Result<U256, TransportError> {
189        trace!(target: "backend::fork", "get_balance={:?}", address);
190        self.provider().get_balance(address).block_id(blocknumber.into()).await
191    }
192
193    pub async fn get_nonce(&self, address: Address, block: u64) -> Result<u64, TransportError> {
194        trace!(target: "backend::fork", "get_nonce={:?}", address);
195        self.provider().get_transaction_count(address).block_id(block.into()).await
196    }
197
198    pub async fn get_account(
199        &self,
200        address: Address,
201        blocknumber: u64,
202    ) -> Result<TrieAccount, TransportError> {
203        trace!(target: "backend::fork", "get_account={:?}", address);
204        self.provider().get_account(address).block_id(blocknumber.into()).await
205    }
206
207    pub async fn trace_transaction(&self, hash: B256) -> Result<Vec<Trace>, TransportError> {
208        if let Some(traces) = self.storage_read().transaction_traces.get(&hash).cloned() {
209            return Ok(traces);
210        }
211
212        let traces = self.provider().trace_transaction(hash).await?.into_iter().collect::<Vec<_>>();
213
214        let mut storage = self.storage_write();
215        storage.transaction_traces.insert(hash, traces.clone());
216
217        Ok(traces)
218    }
219
220    pub async fn debug_trace_transaction(
221        &self,
222        hash: B256,
223        opts: GethDebugTracingOptions,
224    ) -> Result<GethTrace, TransportError> {
225        if let Some(traces) = self.storage_read().geth_transaction_traces.get(&hash).cloned() {
226            return Ok(traces);
227        }
228
229        let trace = self.provider().debug_trace_transaction(hash, opts).await?;
230
231        let mut storage = self.storage_write();
232        storage.geth_transaction_traces.insert(hash, trace.clone());
233
234        Ok(trace)
235    }
236
237    pub async fn debug_code_by_hash(
238        &self,
239        code_hash: B256,
240        block_id: Option<BlockId>,
241    ) -> Result<Option<Bytes>, TransportError> {
242        self.provider().debug_code_by_hash(code_hash, block_id).await
243    }
244
245    pub async fn trace_block(&self, number: u64) -> Result<Vec<Trace>, TransportError> {
246        if let Some(traces) = self.storage_read().block_traces.get(&number).cloned() {
247            return Ok(traces);
248        }
249
250        let traces =
251            self.provider().trace_block(number.into()).await?.into_iter().collect::<Vec<_>>();
252
253        let mut storage = self.storage_write();
254        storage.block_traces.insert(number, traces.clone());
255
256        Ok(traces)
257    }
258
259    pub async fn trace_replay_block_transactions(
260        &self,
261        number: u64,
262        trace_types: HashSet<TraceType>,
263    ) -> Result<Vec<TraceResultsWithTransactionHash>, TransportError> {
264        // Forward to upstream provider for historical blocks
265        let params = (number, trace_types.iter().map(|t| format!("{t:?}")).collect::<Vec<_>>());
266        self.provider().raw_request("trace_replayBlockTransactions".into(), params).await
267    }
268
269    /// Reset the fork to a fresh forked state, and optionally update the fork config
270    pub async fn reset(
271        &self,
272        url: Option<String>,
273        block_number: impl Into<BlockId>,
274    ) -> Result<(), BlockchainError> {
275        let block_number = block_number.into();
276        {
277            self.database
278                .write()
279                .await
280                .maybe_reset(url.clone(), block_number)
281                .map_err(BlockchainError::Internal)?;
282        }
283
284        if let Some(url) = url {
285            self.config.write().update_url(url)?;
286            let override_chain_id = self.config.read().override_chain_id;
287            let chain_id = if let Some(chain_id) = override_chain_id {
288                chain_id
289            } else {
290                self.provider().get_chain_id().await?
291            };
292            self.config.write().chain_id = chain_id;
293        }
294
295        let provider = self.provider();
296        let block =
297            provider.get_block(block_number).await?.ok_or(BlockchainError::BlockNotFound)?;
298        let block_hash = block.header().hash();
299        let timestamp = block.header().timestamp();
300        let base_fee = block.header().base_fee_per_gas();
301        let total_difficulty = block.header().difficulty();
302
303        let number = block.header().number();
304        self.config.write().update_block(
305            number,
306            block_hash,
307            timestamp,
308            base_fee.map(|g| g as u128),
309            total_difficulty,
310        );
311
312        self.clear_cached_storage();
313
314        self.database.write().await.insert_block_hash(U256::from(number), block_hash);
315
316        Ok(())
317    }
318
319    /// Sends `eth_call`
320    pub async fn call(
321        &self,
322        request: &N::TransactionRequest,
323        block: Option<BlockNumber>,
324    ) -> Result<Bytes, TransportError> {
325        let block = block.unwrap_or(BlockNumber::Latest);
326        let res = self.provider().call(request.clone()).block(block.into()).await?;
327
328        Ok(res)
329    }
330
331    /// Sends `eth_simulateV1`
332    pub async fn simulate_v1(
333        &self,
334        request: &SimulatePayload,
335        block: Option<BlockNumber>,
336    ) -> Result<Vec<SimulatedBlock<N::BlockResponse>>, TransportError> {
337        let mut simulate_call = self.provider().simulate(request);
338        if let Some(n) = block {
339            simulate_call = simulate_call.number(n.as_number().unwrap());
340        }
341
342        let res = simulate_call.await?;
343
344        Ok(res)
345    }
346
347    /// Sends `eth_estimateGas`
348    pub async fn estimate_gas(
349        &self,
350        request: &N::TransactionRequest,
351        block: Option<BlockNumber>,
352    ) -> Result<u128, TransportError> {
353        let block = block.unwrap_or_default();
354        let res = self.provider().estimate_gas(request.clone()).block(block.into()).await?;
355
356        Ok(res as u128)
357    }
358
359    /// Sends `eth_createAccessList`
360    pub async fn create_access_list(
361        &self,
362        request: &N::TransactionRequest,
363        block: Option<BlockNumber>,
364    ) -> Result<AccessListResult, TransportError> {
365        self.provider().create_access_list(request).block_id(block.unwrap_or_default().into()).await
366    }
367
368    pub async fn transaction_by_block_number_and_index(
369        &self,
370        number: u64,
371        index: usize,
372    ) -> Result<Option<N::TransactionResponse>, TransportError> {
373        let block = self.block_by_number(number).await?;
374        self.transaction_at_block_index(block, index).await
375    }
376
377    pub async fn transaction_by_block_hash_and_index(
378        &self,
379        hash: B256,
380        index: usize,
381    ) -> Result<Option<N::TransactionResponse>, TransportError> {
382        let block = self.block_by_hash(hash).await?;
383        self.transaction_at_block_index(block, index).await
384    }
385
386    async fn transaction_at_block_index(
387        &self,
388        block: Option<N::BlockResponse>,
389        index: usize,
390    ) -> Result<Option<N::TransactionResponse>, TransportError> {
391        if let Some(block) = block {
392            match block.transactions() {
393                BlockTransactions::Full(txs) => {
394                    if let Some(tx) = txs.get(index) {
395                        return Ok(Some(tx.clone()));
396                    }
397                }
398                BlockTransactions::Hashes(hashes) => {
399                    if let Some(tx_hash) = hashes.get(index) {
400                        return self.transaction_by_hash(*tx_hash).await;
401                    }
402                }
403                BlockTransactions::Uncle => {}
404            }
405        }
406        Ok(None)
407    }
408
409    pub async fn transaction_by_hash(
410        &self,
411        hash: B256,
412    ) -> Result<Option<N::TransactionResponse>, TransportError> {
413        trace!(target: "backend::fork", "transaction_by_hash={:?}", hash);
414        if let tx @ Some(_) = self.storage_read().transactions.get(&hash).cloned() {
415            return Ok(tx);
416        }
417
418        let tx = self.provider().get_transaction_by_hash(hash).await?;
419        if let Some(tx) = tx.clone() {
420            let mut storage = self.storage_write();
421            storage.transactions.insert(hash, tx);
422        }
423        Ok(tx)
424    }
425
426    pub async fn block_by_hash(
427        &self,
428        hash: B256,
429    ) -> Result<Option<N::BlockResponse>, TransportError> {
430        if let Some(mut block) = self.storage_read().blocks.get(&hash).cloned() {
431            block.transactions_mut().convert_to_hashes();
432            return Ok(Some(block));
433        }
434
435        Ok(self.fetch_full_block(hash).await?.map(|mut b| {
436            b.transactions_mut().convert_to_hashes();
437            b
438        }))
439    }
440
441    pub async fn block_by_hash_full(
442        &self,
443        hash: B256,
444    ) -> Result<Option<N::BlockResponse>, TransportError> {
445        if let Some(block) = self.storage_read().blocks.get(&hash).cloned() {
446            return Ok(Some(self.convert_to_full_block(block)));
447        }
448        self.fetch_full_block(hash).await
449    }
450
451    pub async fn block_by_number(
452        &self,
453        block_number: u64,
454    ) -> Result<Option<N::BlockResponse>, TransportError> {
455        if let Some(mut block) = self
456            .storage_read()
457            .hashes
458            .get(&block_number)
459            .and_then(|hash| self.storage_read().blocks.get(hash).cloned())
460        {
461            block.transactions_mut().convert_to_hashes();
462            return Ok(Some(block));
463        }
464
465        let mut block = self.fetch_full_block(block_number).await?;
466        if let Some(block) = &mut block {
467            block.transactions_mut().convert_to_hashes();
468        }
469        Ok(block)
470    }
471
472    pub async fn block_by_number_full(
473        &self,
474        block_number: u64,
475    ) -> Result<Option<N::BlockResponse>, TransportError> {
476        if let Some(block) = self
477            .storage_read()
478            .hashes
479            .get(&block_number)
480            .copied()
481            .and_then(|hash| self.storage_read().blocks.get(&hash).cloned())
482        {
483            return Ok(Some(self.convert_to_full_block(block)));
484        }
485
486        self.fetch_full_block(block_number).await
487    }
488
489    async fn fetch_full_block(
490        &self,
491        block_id: impl Into<BlockId>,
492    ) -> Result<Option<N::BlockResponse>, TransportError> {
493        if let Some(block) = self.provider().get_block(block_id.into()).full().await? {
494            let hash = block.header().hash();
495            let block_number = block.header().number();
496            let mut storage = self.storage_write();
497            // also insert all transactions
498            let block_txs = match block.transactions() {
499                BlockTransactions::Full(txs) => txs.to_owned(),
500                _ => vec![],
501            };
502            storage.transactions.extend(block_txs.iter().map(|tx| (tx.tx_hash(), tx.clone())));
503            storage.hashes.insert(block_number, hash);
504            storage.blocks.insert(hash, block.clone());
505            return Ok(Some(block));
506        }
507
508        Ok(None)
509    }
510
511    /// Converts a block of hashes into a full block
512    fn convert_to_full_block(&self, mut block: N::BlockResponse) -> N::BlockResponse {
513        let storage = self.storage.read();
514        let transactions = block
515            .transactions()
516            .hashes()
517            .filter_map(|hash| storage.transactions.get(&hash).cloned())
518            .collect();
519        *block.transactions_mut() = BlockTransactions::Full(transactions);
520        block
521    }
522}
523
524impl ClientFork {
525    pub async fn transaction_receipt(
526        &self,
527        hash: B256,
528    ) -> Result<Option<FoundryTxReceipt>, BlockchainError> {
529        if let Some(receipt) = self.storage_read().transaction_receipts.get(&hash).cloned() {
530            return Ok(Some(receipt));
531        }
532
533        if let Some(receipt) = self.provider().get_transaction_receipt(hash).await? {
534            let receipt = FoundryTxReceipt::try_from(receipt)
535                .map_err(|_| BlockchainError::FailedToDecodeReceipt)?;
536            let mut storage = self.storage_write();
537            storage.transaction_receipts.insert(hash, receipt.clone());
538            return Ok(Some(receipt));
539        }
540
541        Ok(None)
542    }
543
544    pub async fn block_receipts(
545        &self,
546        number: u64,
547    ) -> Result<Option<Vec<FoundryTxReceipt>>, BlockchainError> {
548        if let receipts @ Some(_) = self.storage_read().block_receipts.get(&number).cloned() {
549            return Ok(receipts);
550        }
551
552        // TODO Needs to be removed.
553        // Since alloy doesn't indicate in the result whether the block exists,
554        // this is being temporarily implemented in anvil.
555        if self.predates_fork_inclusive(number) {
556            let receipts = self.provider().get_block_receipts(BlockId::from(number)).await?;
557            let receipts = receipts
558                .map(|r| {
559                    r.into_iter()
560                        .map(|r| {
561                            FoundryTxReceipt::try_from(r)
562                                .map_err(|_| BlockchainError::FailedToDecodeReceipt)
563                        })
564                        .collect::<Result<Vec<_>, _>>()
565                })
566                .transpose()?;
567
568            if let Some(receipts) = receipts.clone() {
569                let mut storage = self.storage_write();
570                storage.block_receipts.insert(number, receipts);
571            }
572
573            return Ok(receipts);
574        }
575
576        Ok(None)
577    }
578
579    pub async fn uncle_by_block_hash_and_index(
580        &self,
581        hash: B256,
582        index: usize,
583    ) -> Result<Option<AnyRpcBlock>, TransportError> {
584        if let Some(block) = self.block_by_hash(hash).await? {
585            return self.uncles_by_block_and_index(block, index).await;
586        }
587        Ok(None)
588    }
589
590    pub async fn uncle_by_block_number_and_index(
591        &self,
592        number: u64,
593        index: usize,
594    ) -> Result<Option<AnyRpcBlock>, TransportError> {
595        if let Some(block) = self.block_by_number(number).await? {
596            return self.uncles_by_block_and_index(block, index).await;
597        }
598        Ok(None)
599    }
600
601    async fn uncles_by_block_and_index(
602        &self,
603        block: AnyRpcBlock,
604        index: usize,
605    ) -> Result<Option<AnyRpcBlock>, TransportError> {
606        let block_hash = block.header().hash();
607        let block_number = block.header().number();
608        if let Some(uncles) = self.storage_read().uncles.get(&block_hash) {
609            return Ok(uncles.get(index).cloned());
610        }
611
612        let mut uncles = Vec::with_capacity(block.uncles.len());
613        for (uncle_idx, _) in block.uncles.iter().enumerate() {
614            let uncle =
615                match self.provider().get_uncle(block_number.into(), uncle_idx as u64).await? {
616                    Some(u) => u,
617                    None => return Ok(None),
618                };
619            uncles.push(uncle);
620        }
621        self.storage_write().uncles.insert(block_hash, uncles.clone());
622        Ok(uncles.get(index).cloned())
623    }
624}
625
626/// Contains all fork metadata
627#[derive(Clone, Debug)]
628pub struct ClientForkConfig<N: Network = AnyNetwork> {
629    pub eth_rpc_url: String,
630    /// The block number of the forked block
631    pub block_number: u64,
632    /// The hash of the forked block
633    pub block_hash: B256,
634    /// The transaction hash we forked off of, if any.
635    pub transaction_hash: Option<B256>,
636    pub provider: Arc<RetryProvider<N>>,
637    pub chain_id: u64,
638    pub override_chain_id: Option<u64>,
639    /// The timestamp for the forked block
640    pub timestamp: u64,
641    /// The basefee of the forked block
642    pub base_fee: Option<u128>,
643    /// Blob gas used of the forked block
644    pub blob_gas_used: Option<u128>,
645    /// Blob excess gas and price of the forked block
646    pub blob_excess_gas_and_price: Option<BlobExcessGasAndPrice>,
647    /// request timeout
648    pub timeout: Duration,
649    /// request retries for spurious networks
650    pub retries: u32,
651    /// request retries for spurious networks
652    pub backoff: Duration,
653    /// available CUPS
654    pub compute_units_per_second: u64,
655    /// total difficulty of the chain until this block
656    pub total_difficulty: U256,
657    /// Transactions to force include in the forked chain
658    pub force_transactions: Option<Vec<PoolTransaction<FoundryTxEnvelope>>>,
659}
660
661impl<N: Network> ClientForkConfig<N> {
662    /// Updates the provider URL
663    ///
664    /// # Errors
665    ///
666    /// This will fail if no new provider could be established (erroneous URL)
667    fn update_url(&mut self, url: String) -> Result<(), BlockchainError> {
668        // let interval = self.provider.get_interval();
669        self.provider = Arc::new(
670            ProviderBuilder::<N>::new(url.as_str())
671                .timeout(self.timeout)
672                // .timeout_retry(self.retries)
673                .max_retry(self.retries)
674                .initial_backoff(self.backoff.as_millis() as u64)
675                .compute_units_per_second(self.compute_units_per_second)
676                .build()
677                .map_err(|e| BlockchainError::InvalidUrl(format!("{url}: {e}")))?, /* .interval(interval), */
678        );
679        trace!(target: "fork", "Updated rpc url  {}", url);
680        self.eth_rpc_url = url;
681        Ok(())
682    }
683    /// Updates the block forked off `(block number, block hash, timestamp)`
684    pub fn update_block(
685        &mut self,
686        block_number: u64,
687        block_hash: B256,
688        timestamp: u64,
689        base_fee: Option<u128>,
690        total_difficulty: U256,
691    ) {
692        self.block_number = block_number;
693        self.block_hash = block_hash;
694        self.timestamp = timestamp;
695        self.base_fee = base_fee;
696        self.total_difficulty = total_difficulty;
697        trace!(target: "fork", "Updated block number={} hash={:?}", block_number, block_hash);
698    }
699}
700
701/// Contains cached state fetched to serve EthApi requests
702///
703/// This is used as a cache so repeated requests to the same data are not sent to the remote client
704#[derive(Clone, Debug)]
705pub struct ForkedStorage<N: Network = AnyNetwork> {
706    pub uncles: FbHashMap<32, Vec<N::BlockResponse>>,
707    pub blocks: FbHashMap<32, N::BlockResponse>,
708    pub hashes: HashMap<u64, B256>,
709    pub transactions: FbHashMap<32, N::TransactionResponse>,
710    pub transaction_receipts: FbHashMap<32, FoundryTxReceipt>,
711    pub transaction_traces: FbHashMap<32, Vec<Trace>>,
712    pub logs: HashMap<Filter, Vec<Log>>,
713    pub geth_transaction_traces: FbHashMap<32, GethTrace>,
714    pub block_traces: HashMap<u64, Vec<Trace>>,
715    pub block_receipts: HashMap<u64, Vec<FoundryTxReceipt>>,
716    pub code_at: HashMap<(Address, u64), Bytes>,
717}
718
719impl<N: Network> Default for ForkedStorage<N> {
720    fn default() -> Self {
721        Self {
722            uncles: Default::default(),
723            blocks: Default::default(),
724            hashes: Default::default(),
725            transactions: Default::default(),
726            transaction_receipts: Default::default(),
727            transaction_traces: Default::default(),
728            logs: Default::default(),
729            geth_transaction_traces: Default::default(),
730            block_traces: Default::default(),
731            block_receipts: Default::default(),
732            code_at: Default::default(),
733        }
734    }
735}
736
737impl<N: Network> ForkedStorage<N> {
738    /// Clears all data
739    pub fn clear(&mut self) {
740        // simply replace with a completely new, empty instance
741        *self = Self::default()
742    }
743}