Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return an error if block does nit exist #7374

Merged
merged 2 commits into from Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/rpc/rpc-builder/tests/it/http.rs
Expand Up @@ -546,7 +546,9 @@ async fn test_eth_logs_args() {
let mut params = ArrayParams::default();
params.insert( serde_json::json!({"blockHash":"0x58dc57ab582b282c143424bd01e8d923cddfdcda9455bad02a29522f6274a948"})).unwrap();

let _resp = client.request::<Vec<Log>, _>("eth_getLogs", params).await.unwrap();
let resp = client.request::<Vec<Log>, _>("eth_getLogs", params).await;
// block does not exist
assert!(resp.is_err());
Comment on lines +549 to +551
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

}

#[tokio::test(flavor = "multi_thread")]
Expand Down
38 changes: 24 additions & 14 deletions crates/rpc/rpc/src/eth/filter.rs
Expand Up @@ -349,21 +349,31 @@ where
async fn logs_for_filter(&self, filter: Filter) -> Result<Vec<Log>, FilterError> {
match filter.block_option {
FilterBlockOption::AtBlockHash(block_hash) => {
// all matching logs in the block
let block_number = self
.provider
.block_number_for_id(block_hash.into())?
.ok_or_else(|| EthApiError::UnknownBlockNumber)?;

// 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 = self
.eth_cache
.get_receipts(block_hash)
.await?
.ok_or_else(|| EthApiError::UnknownBlockNumber)?;

let mut all_logs = Vec::new();
// all matching logs in the block, if it exists
if let Some(block_number) = self.provider.block_number_for_id(block_hash.into())? {
if let Some(receipts) = self.eth_cache.get_receipts(block_hash).await? {
let filter = FilteredParams::new(Some(filter));
logs_utils::append_matching_block_logs(
&mut all_logs,
&self.provider,
&filter,
(block_hash, block_number).into(),
&receipts,
false,
)?;
}
}
let filter = FilteredParams::new(Some(filter));
logs_utils::append_matching_block_logs(
&mut all_logs,
&self.provider,
&filter,
(block_hash, block_number).into(),
&receipts,
false,
)?;

Ok(all_logs)
}
FilterBlockOption::Range { from_block, to_block } => {
Expand Down