Skip to content

feat: rpc call 'eth_getLogs'#360

Merged
fkrause98 merged 46 commits into
mainfrom
log-request
Oct 1, 2024
Merged

feat: rpc call 'eth_getLogs'#360
fkrause98 merged 46 commits into
mainfrom
log-request

Conversation

@fkrause98

@fkrause98 fkrause98 commented Sep 9, 2024

Copy link
Copy Markdown
Contributor

Motivation

  • One of the milestones is to have an endpoint to fetch transaction logs, which describe events emitted
    by certain addresses.
    Description
  • Add parser and handler for the mentioned endpoint.

Closes #333

Comment thread crates/rpc/eth/block.rs Outdated
@fkrause98 fkrause98 changed the title RPC Call: eth_getLogs feat: RPC call 'eth_getLogs' Sep 16, 2024
Comment thread crates/rpc/eth/logs.rs Outdated
Comment thread crates/core/types/receipt.rs Outdated
Comment thread crates/rpc/eth/logs.rs Outdated
Comment thread crates/rpc/eth/logs.rs Outdated
Comment thread crates/rpc/eth/logs.rs Outdated
Comment thread crates/rpc/eth/logs.rs
Comment thread crates/rpc/eth/logs.rs Outdated

@mpaulucci mpaulucci left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

looking good! some minor comments

Comment thread crates/rpc/eth/logs.rs Outdated
Comment thread crates/rpc/eth/logs.rs Outdated
Comment thread crates/rpc/eth/logs.rs Outdated
Comment thread crates/rpc/eth/logs.rs Outdated
Comment on lines +88 to +93
let Ok(Some(from)) = self.from_block.resolve_block_number(&storage) else {
return Err(RpcErr::WrongParam("fromBlock".to_string()));
};
let Ok(Some(to)) = self.to_block.resolve_block_number(&storage) else {
return Err(RpcErr::WrongParam("toBlock".to_string()));
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
let Ok(Some(from)) = self.from_block.resolve_block_number(&storage) else {
return Err(RpcErr::WrongParam("fromBlock".to_string()));
};
let Ok(Some(to)) = self.to_block.resolve_block_number(&storage) else {
return Err(RpcErr::WrongParam("toBlock".to_string()));
};
let Some(from) = self.from_block.resolve_block_number(&storage)? else {
return Err(RpcErr::WrongParam("fromBlock".to_string()));
};
let Some(to) = self.to_block.resolve_block_number(&storage)? else {
return Err(RpcErr::WrongParam("toBlock".to_string()));
};

A StorageError here means failure to read from the DB, it doesn't mean that the parameter in the request is wrong. StorageErrors get mapped to RpcErr::Internal which is the correct error to return for these cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But what if we were given a block number higher than what exists? Shouldn't that be a wrong parameter?
We can do the following:

  1. Return WrongParam if we were given a block number.
  2. Return an Internal error if we were given a tag.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think she is suggesting something like this


        let block_number = self
            .from_block
            .resolve_block_number(&storage)?
            .ok_or(RpcErr::WrongParam("fromBlock".to_string())?;

If resolve_block_number returns an error, it will be sent as StoreError and converted into InternalError

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed here

@fkrause98 fkrause98 added this pull request to the merge queue Oct 1, 2024
Merged via the queue into main with commit 0e0cb95 Oct 1, 2024
@fkrause98 fkrause98 deleted the log-request branch October 1, 2024 17:23
mpaulucci pushed a commit that referenced this pull request Oct 16, 2024
**Motivation**
- One of the milestones is to have an endpoint to fetch transaction
logs, which describe events emitted
by certain addresses.
**Description**
- Add parser and handler for the mentioned endpoint.
<!-- A clear and concise general description of the changes this PR
introduces -->

<!-- Link to issues: Resolves #111, Resolves #222 -->

Closes #333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hive Testing: eth_getLogs

3 participants