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

Implement the eth_getFilterLogs endpoint #217

Merged
merged 4 commits into from
Apr 26, 2024

Conversation

m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Apr 26, 2024

Closes: #214

Description

Example call:

curl -XPOST 'localhost:8545' --header 'Content-Type: application/json' --data-raw '{"jsonrpc":"2.0","method":"eth_getFilterLogs","params":["0x2a3599c866a95d2cce5fe4c9c894e794"],"id":5}' | jq

Example result:

{
  "jsonrpc": "2.0",
  "id": 5,
  "result": [
    {
      "address": "0x99466ed2e37b892a2ee3e9cd55a98b68f5735db2",
      "topics": [
        "0x24abdb5865df5079dcc5ac590ff6f01d5c16edbc5fab4e195d9febd1114503da"
      ],
      "data": "0x000000000000000000000000000000000000000000000000000000000000002a",
      "blockNumber": "0x4",
      "transactionHash": "0x9da005357b95da4b5c485c08f2ac41ecfe868ead4e6856b909a45dc27a6fcf7d",
      "transactionIndex": "0x0",
      "blockHash": "0x347f563ae38a292c0bafcc8b12f3aac63f61f4a35c66036229cd145ca928ce68",
      "logIndex": "0x0",
      "removed": false
    },
    {
      "address": "0x99466ed2e37b892a2ee3e9cd55a98b68f5735db2",
      "topics": [
        "0x24abdb5865df5079dcc5ac590ff6f01d5c16edbc5fab4e195d9febd1114503da"
      ],
      "data": "0x0000000000000000000000000000000000000000000000000000000000000069",
      "blockNumber": "0x5",
      "transactionHash": "0x65bcabe54b9c578fa9e4cf9ca2acf099e64b850661d60d6df5d1925e88badd0f",
      "transactionIndex": "0x0",
      "blockHash": "0xbb0f964dfc45b4bf9ce7bc8e508ee82ea944e54c06ce46809db6f0a52b298879",
      "logIndex": "0x0",
      "removed": false
    }
  ]
}

For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • New Features

    • Enhanced error handling and validation in the log filtering functionality.
    • Introduced new end-to-end test scenarios for log filtering.
    • Introduced functionality to create logs filters, call eth_getFilterLogs, deploy contracts, make contract function calls, and verify logs in a testing environment.
  • Bug Fixes

    • Improved filter expiration checks to ensure timely updates.
  • Tests

    • Added new test cases for eth_getFilterLogs to verify functionality and robustness.
  • Documentation

    • Updated internal testing documentation with new dependencies and test cases.

@m-Peter m-Peter added this to the Flow-EVM-M2 milestone Apr 26, 2024
@m-Peter m-Peter self-assigned this Apr 26, 2024
Copy link
Contributor

coderabbitai bot commented Apr 26, 2024

Walkthrough

The update focuses on enhancing the eth_getFilterLogs functionality in the PullAPI by incorporating improved error handling, filter expiration checks, and type validations. Additionally, a new test case and JavaScript testing tools have been introduced to ensure the endpoint's reliability and robustness.

Changes

File Path Change Summary
api/pull.go Enhanced GetFilterLogs function with error handling, filter expiration checks, and type validations
tests/e2e_web3js_test.go Added a new test case for eth_getFilterLogs
tests/web3js/eth_get_filter_logs_test.js Introduced new functionality for testing eth_getFilterLogs
tests/web3js/helpers.js Added functionality for making POST requests to a JSON-RPC API server
tests/web3js/package.json Updated dependencies by adding "chai-http": "^4.4.0"

Assessment against linked issues

Objective Addressed Explanation
Implement the eth_getFilterLogs endpoint (#214)

Poem

🐇 Hoppity hop, in the code we drop,
A nifty tweak, no bug can sneak. 🐾
With logs we play, in a coder's way,
Filters check, no tech wreck! 🌟
Cheers to the devs, with their clever clefs! 🎶


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between d2952b8 and 75a5815.
Files selected for processing (2)
  • tests/web3js/eth_get_filter_logs_test.js (1 hunks)
  • tests/web3js/helpers.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/web3js/eth_get_filter_logs_test.js

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@m-Peter m-Peter force-pushed the implement-eth-get-filter-logs branch from 5bce7fa to bb2e508 Compare April 26, 2024 09:43
@m-Peter m-Peter marked this pull request as ready for review April 26, 2024 09:45

filter, ok := api.filters[id]
if !ok {
return nil, errors.Join(
Copy link
Contributor

Choose a reason for hiding this comment

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

according to the above description it should return empty array if not found, I suggest adding a test where the filter is not found as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point regarding the test case, I will add it right away.
Good catch as well regarding the description. This is actually a wrong description copied from geth, See https://github.com/ethereum/go-ethereum/blob/8d42e115b1cae4f09fd02b71c06ec9c85f22ad4f/eth/filters/api.go#L383-L417 😅 I will update the description, the geth behavior is to always return nil, instead of an empty array, at least for this specific endpoint.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated in d2952b8

@m-Peter m-Peter force-pushed the implement-eth-get-filter-logs branch from bb2e508 to d2952b8 Compare April 26, 2024 14:38
@m-Peter m-Peter requested a review from devbugging April 26, 2024 15:11
let contractAddress = deployed.receipt.contractAddress

// create logs filter on the address of the deployed contract
let response = await callRPCMethod('eth_newFilter', [{ 'address': contractAddress }])
Copy link
Contributor

Choose a reason for hiding this comment

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

why we don't use the web3.js client for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately web3.eth does not expose any methods for working with filters. So the only way around was to simply create a POST HTTP call.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Comment on lines +16 to +36
const abi = require(`../fixtures/${name}ABI.json`)
const code = await fs.promises.readFile(`${__dirname}/../fixtures/${name}.byte`, 'utf8')
const contractABI = new web3.eth.Contract(abi)

let data = contractABI
.deploy({ data: `0x${code}` })
.encodeABI()

let signed = await conf.eoa.signTransaction({
from: conf.eoa.address,
data: data,
value: '0',
gasPrice: '0',
})

let receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction)
let receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction)

return {
contract: new web3.eth.Contract(abi, receipt.contractAddress),
receipt: receipt
}
return {
contract: new web3.eth.Contract(abi, receipt.contractAddress),
receipt: receipt
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding explicit error handling for operations like file reading and contract deployment to enhance robustness.

Comment on lines +42 to +49
const signedTx = await conf.eoa.signTransaction(tx)
// send transaction and make sure interaction was success
const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction)

return {
hash: signedTx.transactionHash,
receipt: receipt,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add explicit error handling for the network operations to ensure robustness, especially in case of network failures.

Comment on lines +52 to +65
// callRPCMethod accepts a method name and its params and
// makes a POST request to the JSON-RPC API server.
// Returns a promise for the response.
async function callRPCMethod(methodName, params) {
return chai.request('http://127.0.0.1:8545')
.post('/')
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.send({
'jsonrpc': '2.0',
'method': methodName,
'id': 1,
'params': params
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding error handling for the HTTP requests to handle potential issues like network errors or invalid responses.

@m-Peter m-Peter merged commit f58f744 into onflow:main Apr 26, 2024
2 checks passed
@m-Peter m-Peter deleted the implement-eth-get-filter-logs branch April 26, 2024 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Implement the eth_getFilterLogs endpoint
2 participants