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

refactor(proto): generate pulsar protobuf files #742

Merged
merged 1 commit into from
Oct 16, 2024
Merged

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Oct 16, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new message types for handling address conversion and gas price queries.
    • Added support for ERC20 module genesis state management.
    • Implemented transaction handling for Ethereum Virtual Machine (EVM) calls.
    • Established governance parameters and query capabilities for the governance framework.
    • Added cross-chain oracle state management and migration record handling.
  • Bug Fixes

    • Updated Protobuf dependency version for improved compatibility.
  • Documentation

    • Enhanced reflection methods for better dynamic access to message fields.

Copy link

coderabbitai bot commented Oct 16, 2024

Walkthrough

The changes in this pull request include updates to a Makefile for Protobuf versioning and the installation of the statik tool. Additionally, several new Go files were introduced, defining various protocol buffer message types and services across multiple packages, such as authv1, basev1, erc20, evmv1, govv1, and transfer. These files establish structures and methods for handling requests and responses related to address conversion, gas price queries, ERC20 genesis states, EVM transactions, governance parameters, and migration records.

Changes

File Path Change Summary
Makefile - Updated Protobuf version from 0.13.0 to 0.14.0.
- Added installation command for statik.
api/fx/auth/v1/query.pulsar.go - Added ConvertAddressRequest and ConvertAddressResponse messages.
- Implemented ProtoMethods for marshaling and unmarshaling.
api/fx/base/v1/legacy.pulsar.go - Added GetGasPriceRequest and GetGasPriceResponse messages.
- Implemented reflection methods.
api/fx/erc20/v1/genesis.pulsar.go - Added GenesisState and Params structs.
- Implemented methods for managing token pairs and parameters.
api/fx/evm/v1/tx.pulsar.go - Added MsgCallContract and MsgCallContractResponse messages.
- Implemented serialization methods.
api/fx/gov/v1/params.pulsar.go - Added UpdateStore, SwitchParams, and CustomParams messages.
- Implemented methods for serialization and reflection.
api/fx/gov/v1/query.pulsar.go - Added query messages for governance parameters: QuerySwitchParamsRequest, QuerySwitchParamsResponse, QueryCustomParamsRequest, QueryCustomParamsResponse.
api/fx/gravity/crosschain/v1/genesis.pulsar.go - Added GenesisState struct with various methods for state management.
api/fx/ibc/applications/transfer/v1/call.pulsar.go - Added IbcCallEvmPacket message and IbcCallType enum.
- Implemented reflection methods.
api/fx/ibc/applications/transfer/v1/ibc_legacy.pulsar.go - Added MsgTransfer and Height message types.
- Implemented serialization and reflection methods.
api/fx/migrate/v1/genesis.pulsar.go - Added GenesisState struct for migration state management.
- Implemented methods for handling migration records.
api/fx/migrate/v1/migrate.pulsar.go - Added MigrateRecord message type with methods for serialization and reflection.

Poem

🐇 In the garden of code, we hop with delight,
New messages bloom, shining ever so bright.
From gas prices to tokens, our structures align,
With each little change, our project will shine!
So let’s dance through the bytes, with joy in our hearts,
For every new feature, a masterpiece starts! 🌼


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

@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: 16

🧹 Outside diff range and nitpick comments (9)
Makefile (1)

Line range hint 214-217: New statik installation target is a good addition.

The new target ensures that the statik tool is installed, which is used in the update-swagger-docs target. This is a good practice to make sure all necessary tools are available.

Consider pinning the statik version to ensure consistency across different environments:

 $(STATIK):
 	@echo "Installing statik..."
-	@go install github.com/rakyll/statik@latest
+	@go install github.com/rakyll/[email protected]  # Replace with the desired version
api/fx/migrate/v1/migrate.pulsar.go (1)

1-696: Consider excluding generated code from version control

Including generated code in the repository can lead to increased repository size and potential merge conflicts. It might be beneficial to exclude generated files from version control and generate them during the build process.

api/fx/evm/v1/tx.pulsar.go (2)

945-946: Improve the comment for the 'ContractAddress' field.

The current comment for ContractAddress can be made clearer:

// specify to call the contract address

Consider rephrasing it for better clarity and to follow Go documentation conventions.

Apply this diff to improve the comment:

-// specify to call the contract address
+// ContractAddress specifies the address of the contract to call.

1-1134: Consider excluding generated code from version control.

This file is generated code, as indicated by the comment on line 1:

// Code generated by protoc-gen-go-pulsar. DO NOT EDIT.

Including generated code in version control can lead to:

  • Merge conflicts when regenerated by multiple developers.
  • Increased repository size due to potentially large generated files.
  • Duplication of source of truth, since the actual source is the .proto files.

It's a common best practice to exclude generated code from version control and instead generate it as part of the build or CI process.

[best_practice]

api/fx/erc20/v1/genesis.pulsar.go (1)

1-2: Note on Reviewing Generated Code

This file is generated by protoc-gen-go-pulsar as indicated by the comment on line 1. Generally, generated code should not be manually modified, and code reviews should focus on the source .proto files or the code generation process if there are issues with the generated output.

api/fx/ibc/applications/transfer/v1/ibc_legacy.pulsar.go (2)

1515-1536: Clarify field comments in MsgTransfer struct

Several fields in the MsgTransfer struct have comments that could be improved for clarity:

  1. Router field (line 1531):

    Current comment:

    // the router is hook destination chain

    Suggested revision:

    -// the router is hook destination chain
    +// The router address on the destination chain for handling transfer hooks
  2. Fee field (line 1534):

    Current comment:

    // the tokens to be destination fee

    Suggested revision:

    -// the tokens to be destination fee
    +// The fee to be paid to the destination chain for processing the transfer
  3. Memo field (line 1536):

    Current comment:

    // optional memo

    Suggested revision:

    -// optional memo
    +// An optional memo to include with the transfer

Updating these comments will enhance readability and understanding of the code.


1644-1647: Enhance documentation for Height fields

The Height struct fields lack detailed descriptions. Providing clear comments will improve code maintainability:

  1. RevisionNumber field (line 1645):

    Current comment:

    // the revision that the client is currently on

    Suggested revision:

    -// the revision that the client is currently on
    +// RevisionNumber represents the revision number of the blockchain. It is used to differentiate between different chains or forks.
  2. RevisionHeight field (line 1646):

    Current comment:

    // the height within the given revision

    Suggested revision:

    -// the height within the given revision
    +// RevisionHeight represents the block height within the given revision.

Adding these details will help developers understand the purpose of each field.

api/fx/gov/v1/query.pulsar.go (1)

393-402: Redundant slowProtoReflect() Method

The slowProtoReflect() method may be unnecessary since ProtoReflect() is already implemented:

func (x *QuerySwitchParamsRequest) slowProtoReflect() protoreflect.Message {
	// Implementation details...
}

If slowProtoReflect() is not required, consider removing it to simplify the codebase.

api/fx/gov/v1/params.pulsar.go (1)

1917-1918: Incomplete comment for DepositRatio field

The comment for the DepositRatio field seems incomplete: "For EGF parameters, what percentage of deposit is required to enter the". Please complete the comment to provide full context.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b4a9d88 and 741dce3.

⛔ Files ignored due to path filters (21)
  • api/fx/auth/v1/query_grpc.pb.go is excluded by !**/*.pb.go
  • api/fx/base/v1/legacy_grpc.pb.go is excluded by !**/*.pb.go
  • api/fx/erc20/v1/query_grpc.pb.go is excluded by !**/*.pb.go
  • api/fx/erc20/v1/tx_grpc.pb.go is excluded by !**/*.pb.go
  • api/fx/evm/v1/tx_grpc.pb.go is excluded by !**/*.pb.go
  • api/fx/gov/v1/query_grpc.pb.go is excluded by !**/*.pb.go
  • api/fx/gov/v1/tx_grpc.pb.go is excluded by !**/*.pb.go
  • api/fx/gravity/crosschain/v1/query_grpc.pb.go is excluded by !**/*.pb.go
  • api/fx/gravity/crosschain/v1/tx_grpc.pb.go is excluded by !**/*.pb.go
  • api/fx/migrate/v1/query_grpc.pb.go is excluded by !**/*.pb.go
  • api/fx/migrate/v1/tx_grpc.pb.go is excluded by !**/*.pb.go
  • api/fx/other/legacy_grpc.pb.go is excluded by !**/*.pb.go
  • proto/buf.lock is excluded by !**/*.lock
  • types/legacy/evm_proposal_testnet.pb.go is excluded by !**/*.pb.go
  • types/legacy/gravity_legacy.pb.go is excluded by !**/*.pb.go
  • types/legacy/ibc_legacy.pb.go is excluded by !**/*.pb.go
  • x/crosschain/types/legacy.pb.go is excluded by !**/*.pb.go
  • x/crosschain/types/query.pb.go is excluded by !**/*.pb.go
  • x/crosschain/types/types.pb.go is excluded by !**/*.pb.go
  • x/gov/types/tx.pb.go is excluded by !**/*.pb.go
  • x/migrate/types/query.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (12)
  • Makefile (1 hunks)
  • api/fx/auth/v1/query.pulsar.go (1 hunks)
  • api/fx/base/v1/legacy.pulsar.go (1 hunks)
  • api/fx/erc20/v1/genesis.pulsar.go (1 hunks)
  • api/fx/evm/v1/tx.pulsar.go (1 hunks)
  • api/fx/gov/v1/params.pulsar.go (1 hunks)
  • api/fx/gov/v1/query.pulsar.go (1 hunks)
  • api/fx/gravity/crosschain/v1/genesis.pulsar.go (1 hunks)
  • api/fx/ibc/applications/transfer/v1/call.pulsar.go (1 hunks)
  • api/fx/ibc/applications/transfer/v1/ibc_legacy.pulsar.go (1 hunks)
  • api/fx/migrate/v1/genesis.pulsar.go (1 hunks)
  • api/fx/migrate/v1/migrate.pulsar.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (12)
Makefile (2)

Line range hint 1-365: Overall, the changes to the Makefile are minimal and beneficial.

The updates to the Protobuf version and the addition of the statik installation target improve the build process and dependency management. These changes don't introduce any significant risks or alterations to the overall functionality of the Makefile.

To ensure everything works as expected after these changes, it's recommended to:

  1. Run a full build and test cycle.
  2. Verify that the Protobuf generation process works correctly with the new version.
  3. Confirm that the Swagger documentation is generated successfully using the new statik installation.

193-193: Protobuf version update looks good.

The Protobuf version has been updated from 0.13.0 to 0.14.0. This minor version update is likely to introduce new features or bug fixes.

Please ensure that this update is compatible with the rest of the project. You can verify this by running the following commands:

api/fx/migrate/v1/genesis.pulsar.go (1)

1-3: Generated code notice

The file starts with a code generation notice from protoc-gen-go-pulsar, indicating that it is generated code and should not be edited manually.

api/fx/migrate/v1/migrate.pulsar.go (2)

560-609: LGTM: MigrateRecord struct definition is correct

The definition of MigrateRecord and its associated methods are correctly generated and adhere to protobuf standards.


1-696: Verify the integration of code generated by multiple tools

This file contains code generated by both protoc-gen-go-pulsar and protoc-gen-go. Please verify that combining code from multiple generators does not introduce conflicts, especially with type definitions and method implementations.

Run the following script to check for multiple definitions of MigrateRecord:

✅ Verification successful

✅ Verification Successful: No Conflicts Detected

The MigrateRecord struct is defined in separate packages (migratev1 and types), ensuring that combining code generated by protoc-gen-go-pulsar and protoc-gen-go does not introduce any conflicts with type definitions or method implementations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for all definitions of 'type MigrateRecord struct' in the Go codebase.

# Command: Search for the type definition of MigrateRecord
rg --type go "^type MigrateRecord struct"

# Expectation: Only one definition should be found.

Length of output: 165


Script:

#!/bin/bash
# Description: Extract and display the 'MigrateRecord' struct definitions from both files for comparison.

# Extract 'MigrateRecord' struct from migrate.pulsar.go
echo "Definition in api/fx/migrate/v1/migrate.pulsar.go:"
sed -n '/type MigrateRecord struct {/,/^}/p' api/fx/migrate/v1/migrate.pulsar.go
echo ""

# Extract 'MigrateRecord' struct from migrate.pb.go
echo "Definition in x/migrate/types/migrate.pb.go:"
sed -n '/type MigrateRecord struct {/,/^}/p' x/migrate/types/migrate.pb.go

Length of output: 1029


Script:

#!/bin/bash
# Description: Extract and display the package declarations from both files to verify if they are in the same package.

echo "Package declaration in api/fx/migrate/v1/migrate.pulsar.go:"
sed -n 's/^package\s\+\(\w\+\).*/\1/p' api/fx/migrate/v1/migrate.pulsar.go
echo ""

echo "Package declaration in x/migrate/types/migrate.pb.go:"
sed -n 's/^package\s\+\(\w\+\).*/\1/p' x/migrate/types/migrate.pb.go

Length of output: 420

api/fx/ibc/applications/transfer/v1/call.pulsar.go (1)

629-631: Consider verifying the field types in the IbcCallEvmPacket struct

The fields To, Data, and Value in the IbcCallEvmPacket struct are defined as string types with Protobuf tags indicating the bytes type:

To    string `protobuf:"bytes,1,opt,name=to,proto3" json:"to,omitempty"`
Data  string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
Value string `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"`

If these fields are intended to represent binary data, it may be more appropriate to use []byte instead of string in Go to safely handle arbitrary binary data. Using string for binary data can lead to issues with encoding, especially if the data contains invalid UTF-8 sequences.

Please confirm whether the Protobuf definitions for these fields specify the bytes type. If so, consider regenerating the Go code to correctly map these fields to []byte.

Run the following script to check the Protobuf definitions for these fields:

#!/bin/bash
# Description: Search the Protobuf definition files for the `IbcCallEvmPacket` message.

# Find the Protobuf message definition of `IbcCallEvmPacket`.
rg --type proto 'message IbcCallEvmPacket' -A 10

# Search for the field types within the `IbcCallEvmPacket` message.
rg --type proto -A 3 'message IbcCallEvmPacket' | rg '^\s+\w+\s+\w+'

This script will help you verify the field types specified in the Protobuf definitions.

api/fx/base/v1/legacy.pulsar.go (1)

1-1: Note: This file is auto-generated

This file is generated by protoc-gen-go-pulsar. Manual edits to this file may be overwritten. Please ensure that any changes are made in the source .proto files and then regenerate the code.

api/fx/auth/v1/query.pulsar.go (1)

1-1: Generated Code Should Not Be Manually Edited

The file is auto-generated by protoc-gen-go-pulsar as indicated by the header comment. Any changes should be made in the corresponding .proto files, not directly in this generated code.

api/fx/gov/v1/query.pulsar.go (3)

1-1: 🛠️ Refactor suggestion

Consider Excluding Generated Code from Version Control

The file begins with // Code generated by protoc-gen-go-pulsar. DO NOT EDIT., indicating it's auto-generated. Including generated code in version control can lead to large diffs and merge conflicts. It's generally a best practice to generate these files during the build process instead.

Would you like to adjust the build process to generate this code dynamically and exclude it from version control?


1663-1667: ⚠️ Potential issue

Inconsistent Code Generation Tools Detected

At line 1663, there's another header:

// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// 	protoc-gen-go v1.27.0
// 	protoc        (unknown)
// source: fx/gov/v1/query.proto

This suggests that both protoc-gen-go-pulsar and protoc-gen-go were used to generate this file. Mixing different code generators may introduce inconsistencies or unexpected behaviors.

Please confirm if both generators are intended. If not, consider using a single code generator for consistency.


1903-1977: Ensure Initialization of Proto Message Types

The init() function is defined multiple times to initialize message types:

func init() {
	file_fx_gov_v1_query_proto_init()
	// Additional initialization...
}

Ensure that all proto message types are properly initialized to prevent potential runtime issues.

api/fx/gravity/crosschain/v1/genesis.pulsar.go (1)

1950-2095: Validate the GenesisState struct for completeness

The GenesisState struct is crucial for the initialization and management of the cross-chain oracle system. Ensure that all necessary fields are included and correctly typed. The current definition appears comprehensive, but double-check for any missing parameters or recent updates in the protocol that might require additional fields.

Run the following script to compare the GenesisState struct with the latest Protobuf definition:

✅ Verification successful

GenesisState struct is complete and matches the Protobuf definition.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Compare the `GenesisState` struct fields with the Protobuf definition to ensure completeness.

# Test: List fields in the Go struct.
echo "Fields in Go struct:"
grep -A 20 'type GenesisState struct' api/fx/gravity/crosschain/v1/genesis.pulsar.go | grep -E '^\s+\w+'

# Test: List fields in the Protobuf file.
echo "Fields in Protobuf definition:"
grep -A 50 'message GenesisState' api/fx/gravity/crosschain/v1/genesis.proto | grep -E '^\s+\w+'

# Expected result: Both lists should match in field names and types.

Length of output: 2908


Script:

#!/bin/bash
# Description: Locate the `genesis.proto` file in the repository.

echo "Searching for genesis.proto files:"
fd 'genesis\.proto$'

Length of output: 212


Script:

#!/bin/bash
# Description: Compare the `GenesisState` struct fields with the Protobuf definition to ensure completeness.

# Test: List fields in the Go struct.
echo "Fields in Go struct:"
grep -A 20 'type GenesisState struct' api/fx/gravity/crosschain/v1/genesis.pulsar.go | grep -E '^\s+\w+'

# Test: List fields in the Protobuf file.
echo "Fields in Protobuf definition:"
grep -A 50 'message GenesisState' proto/fx/gravity/crosschain/v1/genesis.proto | grep -E '^\s+\w+'

# Expected result: Both lists should match in field names and types.

Length of output: 3766

api/fx/migrate/v1/genesis.pulsar.go Show resolved Hide resolved
api/fx/migrate/v1/genesis.pulsar.go Show resolved Hide resolved
api/fx/migrate/v1/genesis.pulsar.go Show resolved Hide resolved
api/fx/base/v1/legacy.pulsar.go Show resolved Hide resolved
api/fx/gov/v1/query.pulsar.go Show resolved Hide resolved
@fx0x55 fx0x55 merged commit 93edf6f into main Oct 16, 2024
13 checks passed
@fx0x55 fx0x55 deleted the fx0x55/autocli branch October 16, 2024 03:16
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.

2 participants