Skip to content

Commit

Permalink
chore: remove fork caches for eth call and call estimate (#7333)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Mar 7, 2024
1 parent f787fed commit ebb7162
Showing 1 changed file with 4 additions and 40 deletions.
44 changes: 4 additions & 40 deletions crates/anvil/src/eth/backend/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,8 @@ impl ClientFork {
request: &TransactionRequest,
block: Option<BlockNumber>,
) -> Result<Bytes, TransportError> {
let request = Arc::new(request.clone());
let block = block.unwrap_or(BlockNumber::Latest);

if let BlockNumber::Number(num) = block {
// check if this request was already been sent
let key = (request.clone(), num);
if let Some(res) = self.storage_read().eth_call.get(&key).cloned() {
return Ok(res);
}
}

let block_id: BlockId = block.into();

let res: Bytes = self.provider().call((*request).clone(), Some(block_id)).await?;

if let BlockNumber::Number(num) = block {
// cache result
let mut storage = self.storage_write();
storage.eth_call.insert((request, num), res.clone());
}
let res = self.provider().call((*request).clone(), Some(block.into())).await?;

Ok(res)
}
Expand All @@ -202,26 +184,8 @@ impl ClientFork {
request: &TransactionRequest,
block: Option<BlockNumber>,
) -> Result<U256, TransportError> {
let request = Arc::new(request.clone());
let block = block.unwrap_or(BlockNumber::Latest);

if let BlockNumber::Number(num) = block {
// check if this request was already been sent
let key = (request.clone(), num);
if let Some(res) = self.storage_read().eth_gas_estimations.get(&key).cloned() {
return Ok(res);
}
}

let block_id: BlockId = block.into();

let res = self.provider().estimate_gas((*request).clone(), Some(block_id)).await?;

if let BlockNumber::Number(num) = block {
// cache result
let mut storage = self.storage_write();
storage.eth_gas_estimations.insert((request, num), res);
}
let res = self.provider().estimate_gas(request.clone(), Some(block.into())).await?;

Ok(res)
}
Expand Down Expand Up @@ -662,6 +626,8 @@ impl ClientForkConfig {
}

/// Contains cached state fetched to serve EthApi requests
///
/// This is used as a cache so repeated requests to the same data are not sent to the remote client
#[derive(Clone, Debug, Default)]
pub struct ForkedStorage {
pub uncles: HashMap<B256, Vec<Block>>,
Expand All @@ -674,8 +640,6 @@ pub struct ForkedStorage {
pub geth_transaction_traces: HashMap<B256, GethTrace>,
pub block_traces: HashMap<u64, Vec<Trace>>,
pub block_receipts: HashMap<u64, Vec<TransactionReceipt>>,
pub eth_gas_estimations: HashMap<(Arc<TransactionRequest>, u64), U256>,
pub eth_call: HashMap<(Arc<TransactionRequest>, u64), Bytes>,
pub code_at: HashMap<(Address, u64), Bytes>,
}

Expand Down

0 comments on commit ebb7162

Please sign in to comment.