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

Pass the gateway config to NetAPI so it can return the proper network ID #311

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Jun 21, 2024

Closes: #310

Description

Until now, the net_version was hard-coded to return the testnet chain ID.


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

    • Implemented enhanced network information retrieval for JSON-RPC endpoints, including network ID, listening status, and peer count.
    • Added end-to-end tests to validate the new network information retrieval functionality.
  • Bug Fixes

    • Corrected expected result values in batch request tests to reflect updated responses.
  • Tests

    • Introduced new test cases for net_* JSON-RPC endpoints and network information retrieval using web3.eth.net.

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

coderabbitai bot commented Jun 21, 2024

Walkthrough

The changes integrate the configuration parameter into various components, ensuring the net_version JSON-RPC endpoint returns the correct network ID based on the configuration. This involves passing a configuration object through the SupportedAPIs function and updating the NetAPI initialization to use this configuration. New test cases for network information retrieval ensure the adjustments function correctly.

Changes

Files Change Summary
api/api.go Updated SupportedAPIs function to include config parameter. Adjusted NetAPI initialization to use NewNetAPI(config).
api/net.go Added config field to NetAPI struct and used it in Version method. Added NewNetAPI function.
bootstrap/bootstrap.go Modified startServer function to pass config to SupportedAPIs.
tests/e2e_web3js_test.go Added an end-to-end test for net_* JSON-RPC endpoints.
tests/web3js/eth_non_interactive_test.js Updated expected result for a batch request test case.
tests/web3js/net_namespace_test.js New file added with tests for network information retrieval using web3.eth.net.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant Config
    participant NetAPI
    
    Client ->> API: Call SupportedAPIs(..., config)
    API ->> NetAPI: Initialize with NewNetAPI(config)
    NetAPI ->> Config: Get EVMNetworkID
    Config -->> NetAPI: Return EVMNetworkID
    NetAPI -->> Client: Return network ID
Loading

Assessment against linked issues

Objective Addressed Explanation
net_version should return the appropriate network chain ID (#310)

Poem

Amidst the code where logic lies,
Config whispers, network ties.
APIs align, tests unfold,
A tale of functions, brave and bold.
🎉 The ID's right, the bugs took flight,
In Rabbit's world, it’s coded delight! 🐇✨


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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d5292a2 and dd8a1b0.

Files selected for processing (6)
  • api/api.go (2 hunks)
  • api/net.go (2 hunks)
  • bootstrap/bootstrap.go (1 hunks)
  • tests/e2e_web3js_test.go (1 hunks)
  • tests/web3js/eth_non_interactive_test.js (1 hunks)
  • tests/web3js/net_namespace_test.js (1 hunks)
Additional comments not posted (8)
tests/web3js/net_namespace_test.js (3)

5-8: Approved: Correct implementation of network ID test.

This test case correctly checks if the network ID returned by web3.eth.net.getId() matches the expected value, aligning with the PR's objective to dynamically provide the correct network ID.


10-13: Approved: Network listening status test.

The test correctly asserts that the network is always listening, which is a fundamental aspect of the network's functionality.


15-18: Approved: Peer count test.

This test case correctly checks the peer count. Ensure that the test environment is configured to have exactly one peer, as expected by this test.

api/net.go (2)

11-19: Approved: Correct implementation of NetAPI with configuration.

The NetAPI struct is correctly defined with a configuration field, and the constructor NewNetAPI properly initializes this field. This setup is crucial for the dynamic retrieval of network IDs.


34-34: Approved: Dynamic network ID retrieval in Version method.

The Version method correctly retrieves the network ID from the configuration, replacing the previously hardcoded value. This change aligns perfectly with the PR's objectives.

tests/e2e_web3js_test.go (1)

21-23: Approved: Addition of new test case for net_* JSON-RPC endpoints.

The inclusion of the net_namespace_test.js in the test suite is a crucial step for ensuring that the new network functionality is thoroughly tested. This aligns with the PR's objectives of enhancing test coverage.

tests/web3js/eth_non_interactive_test.js (1)

193-193: Approved: Updated expected result for net_version in batch request test.

The update to the expected result for the net_version method in the batch request test case correctly reflects the new dynamic configuration capability. This ensures that the test remains accurate and aligns with the PR's objectives.

api/api.go (1)

Line range hint 36-52: Approval: Updated SupportedAPIs to include configuration.

The update to include a config parameter in the SupportedAPIs function and the initialization of NetAPI with this configuration are in line with the PR objectives. This allows the NetAPI to dynamically use the network ID from the configuration, addressing the issue of a hardcoded network ID. Ensure that all calls to SupportedAPIs across the codebase are updated to pass the new parameter.

Comment on lines +347 to +353
supportedAPIs := api.SupportedAPIs(
blockchainAPI,
streamAPI,
pullAPI,
debugAPI,
cfg,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor suggestion: Pass configuration to SupportedAPIs method.

The change to pass the cfg object to SupportedAPIs aligns with the PR objectives to make the network ID dynamic based on configuration. This is a crucial change for the flexibility of the NetAPI. Ensure that all dependencies and usages of SupportedAPIs have been updated accordingly to handle the new parameter.

@devbugging devbugging merged commit 28fae42 into onflow:main Jun 24, 2024
2 checks passed
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.

net_version is hard-coded to testnet chain ID
2 participants