Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

feat(api): improve web3_clientVersion #1404

Merged
merged 1 commit into from
Jan 10, 2024
Merged

feat(api): improve web3_clientVersion #1404

merged 1 commit into from
Jan 10, 2024

Conversation

itsdevbear
Copy link

@itsdevbear itsdevbear commented Jan 10, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a version reporting feature for the host chain within the app.
    • Enhanced the Web3 API to include host chain version information.
  • Refactor

    • Updated the app's internal naming for consistency.
  • Style

    • Minor code formatting for improved readability.
  • Documentation

    • Updated function signatures to reflect the new parameter requirements.

Copy link

coderabbitai bot commented Jan 10, 2024

Walkthrough

The changes involve a rebranding in the Cosmos build scripts, minor tweaks in the Cosmos runtime, and significant updates in the Ethereum compatibility layer to include a host chain version. The eth/polar package underwent modifications to incorporate host chain version information in the backend and API layers, affecting function signatures and data structures.

Changes

File Path Change Summary
build/scripts/cosmos.mk Changed Name and AppName in ldflags from "sim" and "simd" to "polard".
cosmos/runtime/miner/miner.go Added a blank line; no functional changes.
cosmos/x/evm/keeper/host.go
eth/core/host.go
Added Version() method to return the host chain version.
eth/polar/api/web3.go
eth/polar/backend.go
Modified to pass and return Web3Backend, and to use host.Version() respectively.
eth/polar/api_backend.go Added imports and hostChainVersion field; NewAPIBackend takes hostChainVersion parameter; ClientVersion returns formatted string with hostChainVersion.

🐇
In the realm of code, where changes abound,
A rabbit hops through, leaving footprints on the ground.
"Polard" springs forth, a new name takes flight,
In the web of the cosmos, a new star shines bright. 🌟
🐇

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5f28546 and 628820e.
Files selected for processing (7)
  • build/scripts/cosmos.mk (1 hunks)
  • cosmos/runtime/miner/miner.go (1 hunks)
  • cosmos/x/evm/keeper/host.go (2 hunks)
  • eth/core/host.go (1 hunks)
  • eth/polar/api/web3.go (1 hunks)
  • eth/polar/api_backend.go (4 hunks)
  • eth/polar/backend.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • cosmos/runtime/miner/miner.go
Additional comments: 11
eth/polar/api/web3.go (2)
  • 46-48: The NewWeb3API function now returns the Web3Backend interface instead of a concrete type. This change could affect how the function is used throughout the codebase. Ensure that all calls to this function have been updated to handle the interface type correctly.
Verification successful

The search results indicate that the NewWeb3API function is referenced in eth/polar/backend.go and is defined in eth/polar/api/web3.go. There are no other files listed, which suggests that the usage of this function might be limited within the codebase, or that the function is not used outside of the eth/polar package.

Given this information, it seems that the change in the function signature of NewWeb3API to accept and return a Web3Backend type is localized and may not have widespread implications across the entire codebase. However, it is still important to ensure that the change is properly handled in eth/polar/backend.go where the function is used.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for files that use the NewWeb3API function. Expecting list of dependent files.
rg --type go "NewWeb3API"

Length of output: 187

* 43-51: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [50-53]

The ClientVersion and Sha3 methods remain unchanged and correctly implemented.

build/scripts/cosmos.mk (1)
  • 72-73: The ldflags variable has been updated to change the Name and AppName values to "polard". Verify that this renaming is consistent throughout the entire codebase and that no references to the old names remain.
Verification successful

The search results indicate that the terms "sim" and "simd" are still present in the main.mk file, but they do not appear to be related to the Name and AppName values that were changed in cosmos.mk. Instead, they seem to be associated with simulation paths and commands. Therefore, the renaming of application identifiers to "polard" in cosmos.mk does not seem to be inconsistent with these findings.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the old application identifiers "sim" and "simd" to ensure they have been fully replaced.
rg --type make "sim"
rg --type make "simd"

Length of output: 577

cosmos/x/evm/keeper/host.go (2)
  • 36-36: The import of github.com/cosmos/cosmos-sdk/version has been added to support the new Version() method.

  • 116-119: The Version() method has been added to the Host struct to return the version of the host chain. Ensure that this new method is being used correctly wherever the host chain version is required.

Verification successful

The output from the rg command shows several files where the Host struct or the term "host" is mentioned. To verify the correct usage of the new Version() method, we need to focus on instances where the Host struct from the cosmos/x/evm/keeper package is used, as this is where the method is defined.

From the output, we can see that the Host struct is referenced in the cosmos/x/evm/keeper package files, such as keeper.go, host.go, genesis.go, and genesis_test.go. We need to check if the Version() method is being called on instances of the Host struct in these files.

To proceed, we should create a script to search for the usage of the Version() method in the context of the Host struct within the cosmos/x/evm/keeper package.


To verify the usage of the Version() method across the entire codebase, we will create a script to search for calls to this method on instances of the Host struct in all .go files.


To further investigate the usage of the Version() method, we will create scripts to extract more context around the calls in eth/polar/backend.go and eth/polar/api/net.go.


Based on the new context provided:

  1. The host.Version() call in eth/polar/backend.go is used correctly to pass the host chain version information to the NewAPIBackend function, which aligns with the intended use of the Version() method added to the Host struct.

  2. The api.b.Version() call in eth/polar/api/net.go is part of a method that exposes the version information through the netAPI struct. Although it's not explicitly clear if api.b is an instance of the Host struct, the usage pattern is consistent with common practices of delegation or proxying, suggesting that this is also a correct usage of the Version() method.

Therefore, the review comment has been addressed, and the Version() method appears to be used correctly in the provided contexts.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for files that use the Host struct to ensure the new Version method is being utilized correctly.
rg --type go "Host"

Length of output: 4951



Script:

#!/bin/bash
# Search for the usage of the Version() method on instances of the Host struct within the cosmos/x/evm/keeper package.
rg --type go -A 3 "func \(h \*Host\) Version\(\)" cosmos/x/evm/keeper/

Length of output: 355



Script:

#!/bin/bash
# Search for calls to the Version() method on instances of the Host struct across all .go files in the codebase.
rg --type go "\.Version\(\)" 

Length of output: 217



Script:

#!/bin/bash
# Extract more context around the Version() call in eth/polar/backend.go
rg --type go -C 5 "host\.Version\(\)" eth/polar/backend.go

# Extract more context around the Version() call in eth/polar/api/net.go
rg --type go -C 5 "api\.b\.Version\(\)" eth/polar/api/net.go

Length of output: 608

eth/core/host.go (1)
  • 45-46: The PolarisHostChain interface has been extended with a new Version() method. This change is consistent with the addition of the Version() method in the Host struct in the Cosmos-related files.
eth/polar/backend.go (1)
  • 180-182: The APIs method has been reformatted to pass pl.apiBackend as an argument to polarapi.NewWeb3API, aligning with the updated function signature. Ensure that the APIs method is correctly updated wherever it is used.
Verification successful

The output from the eth/eth.go file shows an interface method RegisterAPIs([]rpc.API) which indicates that it expects an array of rpc.API objects. This is consistent with the usage of pl.APIs() in eth/polar/backend.go, where stack.RegisterAPIs(pl.APIs()) is called. Since pl.APIs() returns an array of rpc.API and this is what RegisterAPIs expects, the usage is correct and aligns with the updated method signature.

Based on the information gathered, the APIs method in eth/polar/backend.go is correctly updated and is being used properly in the codebase. The review comment is verified as the changes align with the updated function signature, and the method is used correctly wherever it is called.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for files that use the APIs method of the Polaris type. Expecting list of dependent files.
rg --type go "APIs\("

Length of output: 397



Script:

#!/bin/bash
# Check the usage of `APIs()` in `eth/polar/backend.go` where it is used with `stack.RegisterAPIs(pl.APIs())`
cat eth/polar/backend.go | grep -A 5 -B 5 "stack.RegisterAPIs(pl.APIs())"

# Check the usage of `APIs()` in `eth/eth.go` to ensure compatibility with the updated `APIs()` method signature.
cat eth/eth.go | grep -A 5 -B 5 "RegisterAPIs([]rpc.API)"

Length of output: 554



Script:

#!/bin/bash
# Correcting the syntax error and re-running the script to check the usage of `APIs()` in `eth/eth.go`.
cat eth/eth.go | grep -A 5 -B 5 "RegisterAPIs(\[\]rpc.API"

Length of output: 455

eth/polar/api_backend.go (4)
  • 26-28: The addition of the "fmt" and "strings" packages is appropriate for the string formatting required in the ClientVersion method.

  • 83-83: A new field hostChainVersion has been added to the backend struct. Ensure that all instances where backend is instantiated are updated to initialize this new field.

  • 98-105: The NewAPIBackend function now accepts an additional parameter hostChainVersion. This change will require updates wherever NewAPIBackend is called to include the new argument.

Verification successful

The verification script has confirmed that the NewAPIBackend function is being called with the new hostChainVersion parameter in eth/polar/backend.go. This suggests that the necessary updates to include the new argument have been made in this part of the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for instances where NewAPIBackend is called to ensure the new parameter is being passed.
ast-grep --lang go --pattern $'NewAPIBackend($$$)'

Length of output: 244

* 649-651: The `ClientVersion` method has been updated to return a formatted string that includes the `hostChainVersion` and the client name. This change seems to align with the PR's objective to include host chain version information in the API response. However, ensure that the formatting of the version string meets the expected standards and that the `hostChainVersion` is properly validated before use.

Comment on lines +116 to +117
pl.apiBackend = NewAPIBackend(
pl, stack.ExtRPCEnabled(), allowUnprotectedTxs, pl.config, host.Version(),
Copy link

Choose a reason for hiding this comment

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

The New function call in eth.go does not include the host.Version() argument. This needs to be updated to match the new function signature in eth/polar/backend.go.

Analysis chain

The New function has been updated to include the host chain version when creating a new API backend. Verify that the New function is correctly updated wherever it is used to ensure the host chain version is passed as expected.


This script should help us identify the specific New function for the Polaris type by looking for the function definition and then checking for the presence of Polaris in the surrounding lines.


This script will search for the usage of the New function within the eth.go file, providing some context lines to understand how the function is being called. We're looking to confirm that the host.Version() argument is included in the call.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for files that use the New function of the Polaris type. Expecting list of dependent files.
rg --type go "New\("

Length of output: 11353



Script:

#!/bin/bash
# Filter the output to find usages of the New function specifically for the Polaris type.
rg --type go -A 2 "func New\(" | rg "Polaris"

Length of output: 160



Script:

#!/bin/bash
# Verify the usage of the New function in the eth.go file to ensure it includes the host.Version() argument.
rg --type go -C 3 "polar.New\(" eth/eth.go

Length of output: 277

Copy link

codecov bot commented Jan 10, 2024

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (5f28546) 47.36% compared to head (628820e) 47.32%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1404      +/-   ##
==========================================
- Coverage   47.36%   47.32%   -0.04%     
==========================================
  Files          85       85              
  Lines        5061     5065       +4     
==========================================
  Hits         2397     2397              
- Misses       2487     2491       +4     
  Partials      177      177              
Files Coverage Δ
cosmos/x/evm/keeper/host.go 0.00% <0.00%> (ø)

@itsdevbear itsdevbear merged commit 6f8d547 into main Jan 10, 2024
12 of 14 checks passed
@itsdevbear itsdevbear deleted the web3_version branch January 10, 2024 23:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants