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

feat: implement allowed denoms #13

Merged
merged 2 commits into from
May 13, 2024
Merged

feat: implement allowed denoms #13

merged 2 commits into from
May 13, 2024

Conversation

johnletey
Copy link
Member

@johnletey johnletey commented May 13, 2024

Per the request of the Initia team, integrators of the x/forwarding module now have fine-tuned control over which denoms are automatically forwarded. Note that clearing a forwarding account to a fallback address will transfer all of the balance, regardless of allowed denoms.

Summary by CodeRabbit

  • New Features

    • Introduced the ability to fine-tune control over which denominations are forwarded.
    • Added new RPC methods for querying and setting allowed denominations.
    • Provided enhanced authority management functionalities.
  • Documentation

    • Updated API documentation to reflect new features and functionalities.
  • Bug Fixes

    • Implemented error handling for invalid authority and denominations input.
  • Refactor

    • Enhanced internal logic for denomination and authority handling to improve performance and reliability.
  • Chores

    • Updated scripts and configurations to support new authority account functionalities and denomination settings.

@johnletey johnletey self-assigned this May 13, 2024
Copy link

coderabbitai bot commented May 13, 2024

Walkthrough

The recent update enhances control over denominations in a blockchain environment, focusing on forwarding functionalities. Changes include adding an authority field for permissions management and mechanisms for specifying and querying allowed denominations, ensuring secure transactions across modules and scripts.

Changes

File Path Change Summary
.../module.proto, .../genesis.proto, .../query.proto, .../tx.proto Added authority and allowed_denoms fields; new RPC methods for setting and querying allowed denominations.
.../module.go, .../keeper.go, .../keeper/msg_server.go, .../keeper/query_server.go, .../keeper/state.go Integration of authority and denomination control in forwarding logic; added methods for setting and querying allowed denominations.
.../types/codec.go, .../types/genesis.go, .../types/keys.go, .../types/errors.go Registration of new message types and error handling for denominations; added default genesis state and validation functions.
local.sh, simapp/app.yaml Script updates to handle authority setup; configuration changes to include the authority account.
e2e/forwarding_test.go Added end-to-end tests for denomination forwarding functionalities.

🐰✨
In the land of code, where the bits align,
A rabbit hopped, leaving changes behind.
Fields of authority, denoms allowed,
Secure the transactions, making the blockchain proud.
Hop, hop, hop, on the digital ground,
With every commit, new solutions are found. 🌟🌿


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.

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

Out of diff range and nitpick comments (2)
local.sh (1)

Line range hint 1-1: Add a shebang to specify the shell interpreter explicitly.

+ #!/bin/bash
api/noble/forwarding/v1/genesis.pulsar.go (1)

16-16: Ensure that the _GenesisState_1_list type is properly documented for clarity.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 02a34f8 and 4153678.
Files ignored due to path filters (6)
  • api/noble/forwarding/v1/query_grpc.pb.go is excluded by !**/*.pb.go
  • api/noble/forwarding/v1/tx_grpc.pb.go is excluded by !**/*.pb.go
  • x/forwarding/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/forwarding/types/query.pb.go is excluded by !**/*.pb.go
  • x/forwarding/types/query.pb.gw.go is excluded by !**/*.pb.gw.go
  • x/forwarding/types/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (22)
  • .changelog/unreleased/features/13-allowed-denoms.md (1 hunks)
  • api/noble/forwarding/module/v1/module.pulsar.go (14 hunks)
  • api/noble/forwarding/v1/genesis.pulsar.go (35 hunks)
  • api/noble/forwarding/v1/query.pulsar.go (33 hunks)
  • api/noble/forwarding/v1/tx.pulsar.go (5 hunks)
  • e2e/forwarding_test.go (9 hunks)
  • local.sh (1 hunks)
  • proto/noble/forwarding/module/v1/module.proto (1 hunks)
  • proto/noble/forwarding/v1/genesis.proto (1 hunks)
  • proto/noble/forwarding/v1/query.proto (2 hunks)
  • proto/noble/forwarding/v1/tx.proto (2 hunks)
  • simapp/app.yaml (1 hunks)
  • x/forwarding/genesis.go (2 hunks)
  • x/forwarding/keeper/keeper.go (5 hunks)
  • x/forwarding/keeper/msg_server.go (2 hunks)
  • x/forwarding/keeper/query_server.go (1 hunks)
  • x/forwarding/keeper/state.go (1 hunks)
  • x/forwarding/module.go (3 hunks)
  • x/forwarding/types/codec.go (1 hunks)
  • x/forwarding/types/errors.go (1 hunks)
  • x/forwarding/types/genesis.go (2 hunks)
  • x/forwarding/types/keys.go (1 hunks)
Files not summarized due to errors (3)
  • api/noble/forwarding/v1/genesis.pulsar.go: Error: Message exceeds token limit
  • api/noble/forwarding/v1/query.pulsar.go: Error: Message exceeds token limit
  • api/noble/forwarding/v1/tx.pulsar.go: Error: Message exceeds token limit
Files skipped from review due to trivial changes (3)
  • .changelog/unreleased/features/13-allowed-denoms.md
  • simapp/app.yaml
  • x/forwarding/types/keys.go
Additional Context Used
ShellCheck (1)
local.sh (1)

[error] 1-1: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.

Additional comments not posted (31)
x/forwarding/types/errors.go (1)

6-7: The error definitions are clear and appropriately registered.

proto/noble/forwarding/module/v1/module.proto (1)

11-12: The addition of the authority field is well-documented and correctly positioned.

x/forwarding/genesis.go (2)

12-14: Ensure that the initialization of allowed denominations is covered by unit tests.


31-31: The export of genesis state correctly includes the new AllowedDenoms field.

x/forwarding/types/codec.go (1)

24-24: The registration of MsgSetAllowedDenoms is correctly implemented for both legacy and new codec systems.

x/forwarding/types/genesis.go (1)

13-15: The default genesis state is correctly initialized with a sensible default for AllowedDenoms.

local.sh (1)

18-19: The commands for setting up the authority account are correctly implemented.

proto/noble/forwarding/v1/tx.proto (2)

18-18: The addition of the SetAllowedDenoms RPC method is correctly implemented.


54-65: The MsgSetAllowedDenoms message is well-defined with clear structure and appropriate protobuf options.

x/forwarding/keeper/query_server.go (1)

15-23: The implementation of the Denoms function is correct and adheres to best practices.

x/forwarding/keeper/state.go (1)

12-21: The implementation of the GetAllowedDenoms function is correct and adheres to best practices.

proto/noble/forwarding/v1/query.proto (2)

15-18: The RPC method Denoms is correctly defined with appropriate annotations for HTTP GET requests.


40-42: The message QueryDenomsResponse is correctly defined with a repeated field for allowed denominations.

x/forwarding/keeper/msg_server.go (1)

121-140: The implementation of the SetAllowedDenoms function is correct, with robust checks for authority and validation of denominations.

x/forwarding/keeper/keeper.go (1)

95-104: The IsAllowedDenom method is correctly implemented with checks for both wildcard and specific denominations.

x/forwarding/module.go (2)

157-165: The CLI command set-allowed-denoms is correctly defined with appropriate positional arguments for setting allowed denominations.


237-248: The ProvideModule function correctly checks for the authority configuration and initializes the Keeper with appropriate dependencies.

e2e/forwarding_test.go (1)

305-364: The TestAllowedDenoms function is correctly implemented, thoroughly testing the setting and querying of allowed denominations.

api/noble/forwarding/module/v1/module.pulsar.go (3)

17-24: The addition and initialization of fd_Module_authority are correctly implemented.


92-97: The modifications to the Range method to handle the authority field are correctly implemented.


Line range hint 113-132: The modifications to the Has, Clear, Get, Set, Mutable, NewField, and ProtoMethods methods to handle the authority field are correctly implemented.

Also applies to: 149-173, 194-210, 280-319, 369-400

api/noble/forwarding/v1/genesis.pulsar.go (10)

Line range hint 310-319: The field descriptors for the GenesisState are correctly initialized. Ensure that these fields are used consistently throughout the codebase.

Verification successful

Field Descriptors Usage Limited to Declaration File

The verification process focused on the consistent usage of the field descriptors fd_GenesisState_allowed_denoms, fd_GenesisState_num_of_accounts, fd_GenesisState_num_of_forwards, and fd_GenesisState_total_forwarded across the codebase. The results indicate that these descriptors are used consistently within their declaration file (api/noble/forwarding/v1/genesis.pulsar.go) but do not appear to be referenced in any other parts of the codebase.

This suggests that the scope of these field descriptors is limited to the specific functionalities implemented in api/noble/forwarding/v1/genesis.pulsar.go. If this encapsulation is intentional, no further action is needed. However, if these fields are expected to be used more broadly across the codebase, this might require additional integration efforts.

  • File: api/noble/forwarding/v1/genesis.pulsar.go
    • All field descriptors are declared, initialized, and used within this file.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify consistent usage of new field descriptors across the codebase.

# Test: Search for the usage of new field descriptors. Expect: Consistent usage across files.
rg --type go $'fd_GenesisState_allowed_denoms|fd_GenesisState_num_of_accounts|fd_GenesisState_num_of_forwards|fd_GenesisState_total_forwarded'

Length of output: 1436



Script:

#!/bin/bash
# Description: Expand search to include indirect or differently formatted references to field descriptors.

# Test: Search for any form of reference to the field descriptors, including possible variations in formatting.
rg --type go --glob '!api/noble/forwarding/v1/genesis.pulsar.go' 'GenesisState.*allowed_denoms|GenesisState.*num_of_accounts|GenesisState.*num_of_forwards|GenesisState.*total_forwarded'

Length of output: 187


390-409: The Range method implementation for fastReflection_GenesisState handles the new fields correctly. Good use of early return to simplify logic.


429-429: The Has method correctly checks for the presence of the allowed_denoms field. This is crucial for conditional logic based on field presence.


453-454: The Clear method for allowed_denoms correctly sets the field to nil. This is a standard approach for clearing slice fields in protobuf-generated code.


477-482: The Get method for allowed_denoms is implemented correctly, ensuring that it returns an empty list if not set, which aligns with protobuf's handling of repeated fields.


521-524: The Set method for allowed_denoms correctly updates the field from the provided list value. This is key for ensuring data integrity when modifying the genesis state.


557-562: The Mutable method for allowed_denoms correctly initializes the field if it is nil and returns a mutable reference. This is essential for safely modifying repeated fields in protobuf messages.


594-596: The NewField method for allowed_denoms correctly creates a new, empty list, which is important for initializing fields with default values.


Line range hint 675-906: The ProtoMethods implementation handles the sizing and marshaling of the allowed_denoms field efficiently, using protobuf's sizing and encoding utilities. Ensure that the marshaling respects the order of elements if Deterministic option is set.

Verification successful

The code snippet provided in the review clearly demonstrates that the Deterministic option is respected in the marshaling process for various map fields (TotalForwarded, NumOfForwards, NumOfAccounts). When this option is set, the keys of these maps are sorted before marshaling, ensuring deterministic order. This aligns with the requirements mentioned in the review comment.

Given this, the verification can be concluded successfully:

  • The Deterministic option is indeed respected in the marshaling process as required.
  • The code snippet provided shows the implementation of this behavior explicitly.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the marshaling order respects the `Deterministic` option.

# Test: Check the marshaling implementation for determinism. Expect: Deterministic order when the option is set.
rg --type go $'Deterministic.*MaRsHaLmAp'

Length of output: 42


957-988: The unmarshaling logic for allowed_denoms correctly handles the wire format and appends each string to the slice, ensuring robust error handling and boundary checks.

api/noble/forwarding/v1/tx.pulsar.go Show resolved Hide resolved
proto/noble/forwarding/v1/genesis.proto Show resolved Hide resolved
x/forwarding/types/genesis.go Show resolved Hide resolved
x/forwarding/types/genesis.go Show resolved Hide resolved
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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 4153678 and 63da50d.
Files selected for processing (1)
  • x/forwarding/types/genesis.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/forwarding/types/genesis.go

Copy link

@beer-1 beer-1 left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for the update!

@johnletey johnletey merged commit f5983be into main May 13, 2024
10 checks passed
@johnletey johnletey deleted the allowed-denoms branch May 13, 2024 16:31
@johnletey johnletey added this to the v2.0.0 milestone May 30, 2024
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