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

eth_getLogs - add support for multiple addresses #719

Merged
merged 17 commits into from
Dec 7, 2022

Conversation

Ivo-Yankov
Copy link
Collaborator

@Ivo-Yankov Ivo-Yankov commented Nov 28, 2022

Description:

  • Allows filtering of eth_getLogs results by multiple addresses. It is now possible to pass an array value for the address param.
  • Refactors eth_getLogs by reducing the function complexity.

Related issue(s):

Fixes #

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
@Ivo-Yankov Ivo-Yankov linked an issue Nov 28, 2022 that may be closed by this pull request
@Ivo-Yankov Ivo-Yankov self-assigned this Nov 28, 2022
@Ivo-Yankov Ivo-Yankov added the bug Something isn't working label Nov 28, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 28, 2022

Codecov Report

Base: 72.53% // Head: 72.74% // Increases project coverage by +0.21% 🎉

Coverage data is based on head (c896281) compared to base (f9e0dc5).
Patch coverage: 80.76% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #719      +/-   ##
==========================================
+ Coverage   72.53%   72.74%   +0.21%     
==========================================
  Files          16       16              
  Lines        1227     1244      +17     
  Branches      224      229       +5     
==========================================
+ Hits          890      905      +15     
- Misses        279      280       +1     
- Partials       58       59       +1     
Impacted Files Coverage Δ
packages/relay/src/lib/errors/JsonRpcError.ts 75.00% <ø> (ø)
packages/relay/src/lib/eth.ts 83.33% <80.76%> (+0.15%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
@Ivo-Yankov Ivo-Yankov linked an issue Nov 29, 2022 that may be closed by this pull request
@Ivo-Yankov Ivo-Yankov marked this pull request as ready for review November 29, 2022 12:42
@Ivo-Yankov Ivo-Yankov added the enhancement New feature or request label Nov 29, 2022
params.timestamp = [`gte:${blockResponse.timestamp.from}`, `lte:${blockResponse.timestamp.to}`];
} else {
params.timestamp = [];
// Use the `toBlock` if it is the only passed tag, if not utilize the `fromBlock`
Copy link
Collaborator

@dimitrovmaksim dimitrovmaksim Nov 30, 2022

Choose a reason for hiding this comment

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

I can't quite get what this means. However I think if toBlock is passed without fromBlock and the block number/tag is not latest/pending, we can either return an error (Alchemy) or an empty response (Infura). In the case of Infura I think it returns an empty response, because if not passed the fromBlock defaults to latest and it becomes fromBlock > toBlock, which results to logs not being found.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's return an error like Alchemy but make sure the error notes that it's due to a missing fromBlock when a toBlock was provided

Copy link
Collaborator

@dimitrovmaksim dimitrovmaksim Dec 2, 2022

Choose a reason for hiding this comment

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

For context:
When toBlock param value is the tag "latest" or "pending" -> returns logs for latest block
When toBlock param is hex number >= "latest" block number -> returns logs for latest block
When toBlock param is hex number < "latest" block number -> {"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"One of the blocks specified in filter (fromBlock, toBlock or blockHash) cannot be found."}}

Unfortunately the 2 seconds per block creation time in hedera may sometimes be a problem here.

Copy link
Collaborator

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

Logic is good, just a bit cryptic so we should update the noted method name and comments to make it easy to understand

packages/relay/src/lib/eth.ts Outdated Show resolved Hide resolved
# Conflicts:
#	packages/server/tests/acceptance/index.spec.ts
Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
# Conflicts:
#	packages/relay/src/lib/eth.ts
@dimitrovmaksim dimitrovmaksim mentioned this pull request Dec 2, 2022
2 tasks
Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
Nana-EC
Nana-EC previously approved these changes Dec 2, 2022
Copy link
Collaborator

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

LG

} else {
const blockRangeLimit = Number(process.env.ETH_GET_LOGS_BLOCK_RANGE_LIMIT) || constants.DEFAULT_ETH_GET_LOGS_BLOCK_RANGE_LIMIT;
// toBlock is not specified or is `latest` or `pending`
if (EthImpl.blockTagIsLatestOrPending(toBlock)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't we combine this if with the else if, for example something like if (!EthImpl.blockTagIsLatestOrPending(toBlock) && toBlockNumber < latestBlockNumber, imo it is unnecessary to assign "latest" to the toBlock if it already is either latest or pending

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It could also be null in this case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The name blockTagIsLatestOrPending does not suggest it checks for null, and personally I don't think it should.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it's better to handle this here, https://github.com/hashgraph/hedera-json-rpc-relay/blob/main/packages/server/src/server.ts#L409-L410 instead of || null to be || "latest"


// Set default blockTag if fromBlock is not specified
if (!fromBlock) {
toBlock = "latest";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be also fromBlock?

Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 5, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Ivo-Yankov Ivo-Yankov merged commit 75dc43f into main Dec 7, 2022
@Ivo-Yankov Ivo-Yankov deleted the 675-get-logs-multiple-addresses branch December 7, 2022 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request limechain P2
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Refactor and simplify eth_getLogs method eth_getLogs does not support filtering by an array of addresses
5 participants