8000 fix: add scalar for cosmos.Dec by beer-1 · Pull Request #391 · initia-labs/initia · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: add scalar for cosmos.Dec #391

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

Merged
merged 1 commit into from
Apr 17, 2025
Merged

fix: add scalar for cosmos.Dec #391

merged 1 commit into from
Apr 17, 2025

Conversation

beer-1
Copy link
Member
@beer-1 beer-1 commented Apr 16, 2025

Description

https://docs.cosmos.network/main/build/building-modules/protobuf-annotations#scalar
Add cosmos_scalar for protogen clients


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

@beer-1 beer-1 self-assigned this Apr 16, 2025
@beer-1 beer-1 requested a review from a team as a code owner April 16, 2025 07:41
Copy link
coderabbitai bot commented Apr 16, 2025
📝 Walkthrough

Walkthrough

This update enhances several protobuf schema files across various modules by adding or updating field options and imports. Specifically, it introduces cosmos_proto.scalar = "cosmos.Dec" and amino.dont_omitempty = true annotations to decimal-related fields, ensuring consistent scalar type mapping and serialization behavior within the Cosmos SDK and Amino encoding. Several files also import cosmos_proto/cosmos.proto or amino/amino.proto to support these new options. No structural changes to messages or fields were made; only metadata and serialization behaviors were modified.

Changes

File(s) Change Summary
proto/initia/distribution/v1/distribution.proto Imported cosmos_proto/cosmos.proto; added cosmos.Dec scalar and amino.dont_omitempty to relevant fields.
proto/initia/dynamicfee/v1/types.proto Imported cosmos_proto/cosmos.proto; added cosmos.Dec scalar to all decimal string fields in Params.
proto/initia/move/v1/tx.proto Added cosmos.Dec scalar and amino.dont_omitempty to reward_weight in MsgWhitelist.
proto/initia/move/v1/types.proto Imported cosmos_proto/cosmos.proto; added cosmos.Dec scalar to decimal fields in Params and RawParams.
proto/initia/mstaking/v1/staking.proto Imported amino/amino.proto; added cosmos.Dec scalar and amino.dont_omitempty to commission rate fields.
proto/initia/mstaking/v1/tx.proto Added gogoproto.nullable = true, cosmos.Dec scalar, and amino.dont_omitempty to commission_rate field.
proto/initia/reward/v1/query.proto Imported amino/amino.proto and cosmos_proto/cosmos.proto; updated annual_provisions field options.
proto/initia/reward/v1/types.proto Imported cosmos_proto/cosmos.proto; added cosmos.Dec scalar and amino.dont_omitempty to rate fields.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ProtobufMessage
    participant CosmosSDK
    participant AminoEncoder

    Client->>ProtobufMessage: Send/Receive message with decimal fields
    ProtobufMessage->>CosmosSDK: Map decimal fields as cosmos.Dec (via scalar option)
    ProtobufMessage->>AminoEncoder: Serialize fields (respect dont_omitempty = true)
    CosmosSDK-->>Client: Return processed message
    AminoEncoder-->>Client: Return encoded message
Loading

Poem

🐇
In fields of proto, decimals bloom,
With scalars set, they find their room.
No empty bytes shall slip away,
Amino keeps them all at bay.
Imports align, the types are clear—
Serialization brings good cheer!
Hop, hop, hooray, the code is neat—
These schema tweaks are quite a treat!

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

🪧 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 generate docstrings to generate docstrings for this 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

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@beer-1 beer-1 requested a review from Vritra4 April 16, 2025 07:41
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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fe0f39b and db7f5a7.

⛔ Files ignored due to path filters (8)
  • x/distribution/types/distribution.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/dynamic-fee/types/types.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/move/types/tx.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/move/types/types.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/mstaking/types/staking.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/mstaking/types/tx.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/reward/types/query.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/reward/types/types.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
📒 Files selected for processing (8)
  • proto/initia/distribution/v1/distribution.proto (3 hunks)
  • proto/initia/dynamicfee/v1/types.proto (2 hunks)
  • proto/initia/move/v1/tx.proto (1 hunks)
  • proto/initia/move/v1/types.proto (6 hunks)
  • proto/initia/mstaking/v1/staking.proto (3 hunks)
  • proto/initia/mstaking/v1/tx.proto (1 hunks)
  • proto/initia/reward/v1/query.proto (2 hunks)
  • proto/initia/reward/v1/types.proto (3 hunks)
🧰 Additional context used
🪛 Buf (1.47.2)
proto/initia/mstaking/v1/staking.proto

4-4: import "amino/amino.proto": file does not exist

(COMPILE)

proto/initia/reward/v1/query.proto

4-4: import "amino/amino.proto": file does not exist

(COMPILE)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Run test and upload codecov
  • GitHub Check: golangci-lint
  • GitHub Check: Analyze (go)
🔇 Additional comments (15)
proto/initia/mstaking/v1/staking.proto (4)

23-25: Best practice: Proper scalar and amino options for decimal fields

Adding (cosmos_proto.scalar) = "cosmos.Dec" and (amino.dont_omitempty) = true to decimal fields is a best practice for Cosmos SDK compatibility and Amino serialization. This ensures correct type mapping and prevents omission of zero values.


31-33: Best practice: Consistent scalar and amino options for max_rate

The same options for max_rate as for rate ensure uniform handling of decimal fields.


39-41: Best practice: Consistent scalar and amino options for max_change_rate

The same options for max_change_rate as for other commission fields ensure uniform handling of decimal fields.


346-348: Best practice: Consistent scalar and amino options for min_commission_rate

The same options for min_commission_rate as for other commission fields ensure uniform handling of decimal fields.

proto/initia/mstaking/v1/tx.proto (1)

96-98: Best practice: Proper scalar and amino options for commission_rate

Adding (cosmos_proto.scalar) = "cosmos.Dec" and (amino.dont_omitempty) = true to the commission_rate field is a best practice for Cosmos SDK compatibility and Amino serialization. This ensures correct type mapping and prevents omission of zero values.

proto/initia/distribution/v1/distribution.proto (2)

22-23: Best practice: Proper scalar and amino options for community_tax

Adding (cosmos_proto.scalar) = "cosmos.Dec" and (amino.dont_omitempty) = true to the community_tax field is a best practice for Cosmos SDK compatibility and Amino serialization.


40-41: Best practice: Proper scalar and amino options for weight

Adding (cosmos_proto.scalar) = "cosmos.Dec" and (amino.dont_omitempty) = true to the weight field is a best practice for Cosmos SDK compatibility and Amino serialization.

proto/initia/move/v1/tx.proto (1)

312-313: Best practice: Proper scalar and amino options for reward_weight

Adding (cosmos_proto.scalar) = "cosmos.Dec" and (amino.dont_omitempty) = true to the reward_weight field is a best practice for Cosmos SDK compatibility and Amino serialization.

proto/initia/reward/v1/query.proto (1)

51-52: Best practice: Proper scalar and amino options for annual_provisions

Adding (cosmos_proto.scalar) = "cosmos.Dec" and (amino.dont_omitempty) = true to the annual_provisions field is a best practice for Cosmos SDK compatibility and Amino serialization.

proto/initia/dynamicfee/v1/types.proto (2)

5-5: Import of cosmos_proto/cosmos.proto is correct and necessary.

This import is required for the new scalar annotations and is a standard practice in Cosmos SDK protobuf files.


17-17: Addition of (cosmos_proto.scalar) = "cosmos.Dec" is correct and improves type safety.

Annotating decimal fields with the scalar option ensures proper type mapping in generated code and aligns with Cosmos SDK conventions.

Also applies to: 25-25, 33-33, 41-41

proto/initia/reward/v1/types.proto (2)

5-5: Import of cosmos_proto/cosmos.proto is correct and required for scalar annotations.

This is a necessary addition for the new field options.


29-30: Scalar and Amino annotations for decimal fields are correct and improve serialization consistency.

These annotations ensure proper type mapping and serialization behavior for decimal fields, aligning with Cosmos SDK and Amino standards.

Also applies to: 40-41

proto/initia/move/v1/types.proto (2)

5-5: Import of cosmos_proto/cosmos.proto is correct and required for scalar annotations.

This import is necessary for the new field options.


23-23: Addition of (cosmos_proto.scalar) = "cosmos.Dec" is correct and improves type mapping.

These annotations ensure that decimal fields are properly mapped in generated code, following Cosmos SDK conventions.

Also applies to: 33-33, 55-55, 65-65

Copy link
codecov bot commented Apr 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 40.07%. Comparing base (92df11e) to head (db7f5a7).
Report is 5 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #391   +/-   ##
=======================================
  Coverage   40.07%   40.07%           
=======================================
  Files         294      294           
  Lines       27511    27511           
=======================================
  Hits        11025    11025           
  Misses      14785    14785           
  Partials     1701     1701           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@beer-1 beer-1 added consensus-breaking v1.1 Release v1.1 v1 Release v1 and removed v1.1 Release v1.1 labels Apr 17, 2025
@beer-1 beer-1 merged commit 31bc6d8 into main Apr 17, 2025
10 checks passed
@beer-1 beer-1 deleted the fix/proto-dec branch April 17, 2025 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0