Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions crates/rpc/rpc/src/eth/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,22 +465,35 @@ where
) -> Result<Vec<Log>, EthFilterError> {
match filter.block_option {
FilterBlockOption::AtBlockHash(block_hash) => {
// for all matching logs in the block
// get the block header with the hash
let header = self
.provider()
.header_by_hash_or_number(block_hash.into())?
.ok_or_else(|| ProviderError::HeaderNotFound(block_hash.into()))?;
// First try to get cached block and receipts, as it's likely they're already cached
let (maybe_block, maybe_receipts) =
self.eth_cache().maybe_cached_block_and_receipts(block_hash).await?;

// Get header - from cached block if available, otherwise from provider
let header = if let Some(ref block) = maybe_block {
block.header().clone()
} else {
self.provider()
.header_by_hash_or_number(block_hash.into())?
.ok_or_else(|| ProviderError::HeaderNotFound(block_hash.into()))?
};

let block_num_hash = BlockNumHash::new(header.number(), block_hash);

// we also need to ensure that the receipts are available and return an error if
// not, in case the block hash been reorged
let (receipts, maybe_block) = self
.eth_cache()
.get_receipts_and_maybe_block(block_num_hash.hash)
.await?
.ok_or(EthApiError::HeaderNotFound(block_hash.into()))?;
// Get receipts - from cache if available, otherwise use
// get_receipts_and_maybe_block
let (receipts, maybe_block) = match maybe_receipts {
Some(receipts) => (receipts, maybe_block),
None => {
// Not cached - use get_receipts_and_maybe_block as before
let (receipts, maybe_block) = self
.eth_cache()
.get_receipts_and_maybe_block(block_num_hash.hash)
.await?
.ok_or(EthApiError::HeaderNotFound(block_hash.into()))?;
(receipts, maybe_block)
}
};

let mut all_logs = Vec::new();
append_matching_block_logs(
Expand Down
Loading