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

feat(rpc): enhance eth_getLogs error handling with block range feedback #12790

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Quertyy
Copy link
Contributor

@Quertyy Quertyy commented Nov 22, 2024

Description

Improve the error handling for eth_getLogs by providing the last successfully processed block number when the maximum logs limit is reached. This allows clients to automatically adjust their block range for subsequent queries.

Changes

  • Modify append_matching_block_logs to return Option<u64> representing the last valid block number when max logs limit is reached
  • Update the error handling to include this information in EthFilterError::QueryExceedsMaxResults
  • Return block_num_hash.number - 1 as the last valid block to ensure a safe retry point

Motivation

Currently, when querying logs over a large block range that exceeds the maximum logs limit, clients need to guess a smaller range through trial and error. This enhancement provides explicit feedback about the highest block number that can be safely queried, enabling more efficient log indexing strategies.

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

this feature makes sense, but the way the max_logs_per_response is enforced doesn't look correct because it doesn't check the matched logs

Comment on lines 134 to 140
// Check if we have reached the max logs per response and return the last block if so
if let Some(max_logs_per_response) = max_logs_per_response {
if log_index >= max_logs_per_response as u64 {
return Ok(Some(block_num_hash.number.saturating_sub(1)));
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this doesn't look correct to me, this compares the index against the max logs per response. this is not what we want here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh mb, just need to compare against the logs array length?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, only those should be enforced

Comment on lines 732 to 734
/// Query result is too large.
#[error("query exceeds max results {0}")]
QueryExceedsMaxResults(usize),
#[error("query exceeds max results {0}, retry with the range {1}-{2}")]
QueryExceedsMaxResults(usize, u64, u64),
Copy link
Collaborator

Choose a reason for hiding this comment

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

needs docs what these numbers represent, not obvious

@mattsse mattsse added the A-rpc Related to the RPC implementation label Nov 26, 2024
Comment on lines +137 to +142
// Check if we have reached the max logs per response and return the last block if so
if let Some(max_logs_per_response) = max_logs_per_response {
if all_logs.len() > max_logs_per_response {
return Ok(Some(block_num_hash.number.saturating_sub(1)));
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find this check a bit out of place here because we now only need this to get the last block hash.

for the purpose of this check, we can move this to

https://github.com/paradigmxyz/reth/pull/12790/files#diff-d45b799806905149d455157b0d93125d80d302c75be6c5c0f84882a45ec9ed6bR522 entirely because we can get the same info from the last log in all_logs then we don't need to apply this check per log

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving the check outside would mean we'd always process the entire block range, even when we know early on that the result will exceed the response size limit?

Copy link
Collaborator

Choose a reason for hiding this comment

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

good point
then lets move this to block scope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc Related to the RPC implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants