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(accounts): add genesis account initialization #20642

Merged
merged 6 commits into from
Jun 12, 2024

Conversation

testinginprod
Copy link
Contributor

@testinginprod testinginprod commented Jun 12, 2024

Description

This PR allows init messages of account to be put in genesis.


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 (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • 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.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

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

Summary by CodeRabbit

  • New Features

    • Introduced the ability to initialize accounts at genesis using MsgInit messages.
  • Bug Fixes

    • Improved error handling during account initialization.
  • Documentation

    • Updated x/accounts README to include instructions for creating accounts at genesis.
  • Refactor

    • Refactored account initialization logic to use a new function for better code organization.

Copy link
Contributor

@testinginprod your pull request is missing a changelog!

Copy link
Contributor

coderabbitai bot commented Jun 12, 2024

Warning

Rate limit exceeded

@testinginprod has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 51 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 2dc9a75 and 587d3d6.

Walkthrough

The recent updates introduce a new list type and methods for managing account initialization messages in the GenesisState struct. These changes enable the execution of account creation messages during the genesis process, improving the initialization logic. Additionally, test cases and documentation have been updated to reflect these enhancements.

Changes

File Path Change Summary
api/cosmos/accounts/v1/genesis.pulsar.go Introduced _GenesisState_3_list type and methods; added init_account_msgs field and associated methods in GenesisState.
x/accounts/genesis.go Added loop to execute account creation messages in the ImportState function.
x/accounts/genesis_test.go Updated TestGenesis to include initialization message for a genesis account and check its status.
x/accounts/keeper.go Added initFromMsg function to initialize an account using v1.MsgInit message.
x/accounts/msg_server.go Refactored Init method in msgServer to use initFromMsg for account initialization with improved error handling.
x/accounts/proto/cosmos/accounts/v1/genesis.proto Added init_account_msgs field to GenesisState message.
x/accounts/README.md Updated documentation to include details on creating accounts at genesis using MsgInit messages.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MsgServer
    participant Keeper
    participant GenesisState

    User ->> MsgServer: Init(request)
    MsgServer ->> Keeper: initFromMsg(ctx, request)
    Keeper ->> GenesisState: decode(init_account_msgs)
    GenesisState -->> Keeper: account data
    Keeper -->> MsgServer: resp, accAddr, error
    MsgServer -->> User: MsgInitResponse, error
Loading

Possibly related issues

  • Epic: x/accounts #17786: This PR addresses part of the epic for x/accounts, specifically the "Init Genesis" task by introducing the ability to initialize accounts at genesis using MsgInit messages.

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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 05ff7a7 and 18ed52e.

Files ignored due to path filters (3)
  • api/cosmos/circuit/v1/tx_grpc.pb.go is excluded by !**/*.pb.go
  • x/accounts/v1/genesis.pb.go is excluded by !**/*.pb.go
  • x/circuit/types/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (6)
  • api/cosmos/accounts/v1/genesis.pulsar.go (15 hunks)
  • x/accounts/genesis.go (1 hunks)
  • x/accounts/genesis_test.go (2 hunks)
  • x/accounts/keeper.go (2 hunks)
  • x/accounts/msg_server.go (2 hunks)
  • x/accounts/proto/cosmos/accounts/v1/genesis.proto (1 hunks)
Files skipped from review due to trivial changes (1)
  • x/accounts/genesis.go
Additional context used
Path-based instructions (4)
x/accounts/msg_server.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/accounts/genesis_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/keeper.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/accounts/v1/genesis.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (18)
x/accounts/proto/cosmos/accounts/v1/genesis.proto (2)

7-7: The import of cosmos/accounts/v1/tx.proto is appropriate given the context of initializing accounts via genesis messages, ensuring that all necessary types from tx.proto are available.


15-16: Adding init_account_msgs to GenesisState is crucial for enabling the initialization of accounts through genesis messages. This change aligns with the PR's objective to enhance the account initialization process during the genesis phase.

x/accounts/msg_server.go (1)

23-25: The error handling in initFromMsg is robust, using fmt.Errorf to wrap the original error provides clarity on the failure point which is good practice. However, ensure that the error message is clear and actionable.

x/accounts/genesis_test.go (2)

42-50: The test setup for initializing a genesis account using initMsg is well-implemented. It correctly appends the initialization message to state.InitAccountMsgs and checks the initialization status, which is crucial for validating the new functionality.


64-69: The test for querying the newly initialized genesis account and checking its state is a good practice. It ensures that the account initialization via genesis messages works as expected.

x/accounts/keeper.go (1)

160-175: The initFromMsg function is a key addition, facilitating the initialization of accounts from MsgInit messages. This function effectively decodes the message and delegates to the existing Init method, maintaining a clean separation of concerns and reusing existing logic.

api/cosmos/accounts/v1/genesis.pulsar.go (12)

66-115: The implementation of _GenesisState_3_list is consistent with protobuf list handling in Go. It properly manages list operations for MsgInit types, ensuring type safety and correct protobuf interactions.


121-129: The field descriptor for init_account_msgs is correctly defined and matches the protobuf field number and type. This ensures that the protobuf encoding and decoding will handle this field as expected.


209-214: The Range method correctly handles the new init_account_msgs list. It ensures that the list is only processed if it is not empty, which is a good practice for performance.


234-235: The Has method correctly checks for the presence of init_account_msgs based on its length. This is a standard approach in protobuf generated code to handle repeated fields.


256-257: The Clear method for init_account_msgs sets the slice to nil, which is the correct way to clear a repeated field in protobufs in Go.


283-288: The Get method correctly returns a list representation for init_account_msgs. It handles the case where the list is empty by returning an empty list, which is crucial for avoiding nil dereferences.


315-318: The Set method correctly assigns a new list to init_account_msgs. This method ensures that the entire list is replaced, which is appropriate for the setter behavior in protobufs.


345-350: The Mutable method implementation for init_account_msgs correctly initializes the list if it is nil and returns a mutable reference. This is essential for enabling modifications to the list after its creation.


371-373: The NewField method for init_account_msgs correctly creates a new, empty list. This is used in protobufs to initialize fields with their default values when needed.


452-457: The Size method in ProtoMethods correctly calculates the size of init_account_msgs for marshaling purposes. This includes handling each element in the list, which is necessary for correct protobuf serialization.


487-501: The Marshal method in ProtoMethods correctly handles the marshaling of init_account_msgs. It ensures that each message is encoded and added to the buffer in the correct order, which is crucial for maintaining the integrity of the data.


626-659: The Unmarshal method correctly handles the unmarshaling of init_account_msgs from a protobuf stream. It properly allocates new instances of MsgInit and fills them with data from the input buffer, ensuring data integrity and type safety.

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

can you please add docs and a short example on how to use this functionality?

unknown unknown added 2 commits June 12, 2024 15:11
# Conflicts:
#	x/accounts/genesis.go
#	x/accounts/genesis_test.go
"app_state": {
"accounts": {
"init_account_msgs": [
Copy link
Member

Choose a reason for hiding this comment

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

is this done manually?

Copy link
Member

Choose a reason for hiding this comment

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

ahh can we add a excerpt that offline generating messages is the way to do this if that is the intended

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

Outside diff range and nitpick comments (1)
x/accounts/README.md (1)

8-8: Consider revising the phrase "In order to" to a shorter alternative like "To" for conciseness.

Tools
LanguageTool

[style] ~8-~8: Consider a shorter alternative to avoid wordiness. (IN_ORDER_TO_PREMIUM)
Context: ...nesis ## Creating accounts on genesis In order to create accounts at genesis, the `x/acco...

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 18ed52e and 3185f5b.

Files selected for processing (1)
  • x/accounts/README.md (1 hunks)
Additional context used
Path-based instructions (1)
x/accounts/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

LanguageTool
x/accounts/README.md

[style] ~8-~8: Consider a shorter alternative to avoid wordiness. (IN_ORDER_TO_PREMIUM)
Context: ...nesis ## Creating accounts on genesis In order to create accounts at genesis, the `x/acco...

Markdownlint
x/accounts/README.md

12-12: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces


5-5: null (MD025, single-title, single-h1)
Multiple top-level headings in the same document


44-44: null (MD047, single-trailing-newline)
Files should end with a single newline character

Additional comments not posted (1)
x/accounts/README.md (1)

9-44: The documentation clearly explains the process of initializing accounts at genesis using MsgInit messages. The example provided is detailed and helps illustrate the setup in the genesis.json file.

Tools
Markdownlint

12-12: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces


44-44: null (MD047, single-trailing-newline)
Files should end with a single newline character

a list of genesis `MsgInit` messages that will be executed in the `x/accounts` genesis flow.

This follows the same initialization flow and rules that would happen if the chain is running.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the trailing space at the end of line 12.

Tools
Markdownlint

12-12: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces

The x/accounts module provides module and facilities for writing smart cosmos-sdk accounts.
The x/accounts module provides module and facilities for writing smart cosmos-sdk accounts.

# Genesis
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure there is only one top-level heading in the document to comply with best practices in Markdown formatting.

Tools
Markdownlint

5-5: null (MD025, single-title, single-h1)
Multiple top-level headings in the same document

}
```

The accounts module will run the lockup account initialization message.
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the file ends with a single newline character.

Tools
Markdownlint

44-44: null (MD047, single-trailing-newline)
Files should end with a single newline character

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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3185f5b and 2dc9a75.

Files ignored due to path filters (1)
  • x/accounts/v1/genesis.pb.go is excluded by !**/*.pb.go
Files selected for processing (4)
  • api/cosmos/accounts/v1/genesis.pulsar.go (21 hunks)
  • x/accounts/genesis.go (3 hunks)
  • x/accounts/genesis_test.go (3 hunks)
  • x/accounts/proto/cosmos/accounts/v1/genesis.proto (1 hunks)
Files not summarized due to errors (1)
  • api/cosmos/accounts/v1/genesis.pulsar.go: Error: Server error. Please try again later.
Files skipped from review as they are similar to previous changes (3)
  • x/accounts/genesis.go
  • x/accounts/genesis_test.go
  • x/accounts/proto/cosmos/accounts/v1/genesis.proto
Additional context used
Path-based instructions (1)
api/cosmos/accounts/v1/genesis.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (12)
api/cosmos/accounts/v1/genesis.pulsar.go (12)

17-64: Review the implementation of _GenesisState_1_list for handling GenesisAccount.

This custom list implementation for GenesisAccount appears to be correctly handling the protobuf message reflection, which is crucial for the dynamic handling of these objects in Go. The methods such as Len, Get, Set, Append, AppendMutable, Truncate, and NewElement are well-implemented for managing slices of GenesisAccount.


Line range hint 69-109: Review the implementation of _GenesisState_2_list for handling MsgInit.

The implementation for _GenesisState_2_list, which manages slices of MsgInit, is consistent with the protobuf handling seen in _GenesisState_1_list. The methods provided ensure that the list can be dynamically manipulated, which is essential for the initialization messages in the genesis state.


118-127: Check the initialization of field descriptors in init().

The initialization of field descriptors for GenesisState within the init() function is correctly set up. This setup is crucial for the correct serialization and deserialization of the GenesisState protobuf messages.


195-203: Review the Range method implementation in fastReflection_GenesisState.

The Range method implementation correctly iterates over the fields of GenesisState, handling both Accounts and InitAccountMsgs. This method is essential for protobuf's reflection-based operations, allowing for dynamic field handling based on their presence.


224-225: Check the Has and Clear methods for init_account_msgs.

The Has and Clear methods for the init_account_msgs field are implemented following protobuf standards, ensuring that these operations are safe and reflect the expected behavior for mutable protobuf fields.

Also applies to: 244-245


264-272: Review the Get method for init_account_msgs.

The Get method for init_account_msgs is correctly implemented to handle cases where the list might be empty, returning an appropriate empty list in such cases. This is a crucial aspect of robust message handling in protobuf.


296-301: Check the Set method for init_account_msgs.

The Set method properly handles the assignment of new values to the init_account_msgs field, ensuring that the list is directly manipulated based on the input. This method is crucial for maintaining the integrity of the data within GenesisState.


326-332: Review the Mutable method for init_account_msgs.

The Mutable method for init_account_msgs correctly ensures that a mutable reference is returned, allowing for modifications to the list of initialization messages. This method is essential for scenarios where the genesis state needs to be dynamically adjusted.


349-351: Check the NewField method for init_account_msgs.

The NewField method is correctly implemented to provide a new, empty list for init_account_msgs when needed. This is important for ensuring that fields can be dynamically initialized in protobuf without prior values.


428-433: Review the ProtoMethods size calculation for InitAccountMsgs.

The size calculation within the ProtoMethods for InitAccountMsgs is accurately implemented, ensuring that the size of each message is correctly computed and added to the total size. This is crucial for performance optimizations in serialization.


463-478: Check the marshaling logic for InitAccountMsgs.

The marshaling logic for InitAccountMsgs in the ProtoMethods is robust, handling the serialization of each message in the list correctly. This ensures that the data integrity is maintained during the serialization process.


Line range hint 545-608: Review the unmarshaling logic for InitAccountMsgs.

The unmarshaling logic for InitAccountMsgs is thoroughly implemented, ensuring that each message is correctly parsed and added to the list. This is essential for correctly reconstructing the GenesisState from its serialized form.

@tac0turtle tac0turtle added this pull request to the merge queue Jun 12, 2024
Merged via the queue into main with commit 40492cd Jun 12, 2024
63 of 65 checks passed
@tac0turtle tac0turtle deleted the tip/accounts/genesis_acc branch June 12, 2024 14:23
alpe added a commit that referenced this pull request Jun 13, 2024
* main:
  fix(x/staking): stop validators from rotating to the same key on the same block (#20649)
  perf: add cache to address codec (#20122)
  build(deps): Bump google.golang.org/protobuf from 1.34.1 to 1.34.2 (#20632)
  fix: remove recipient amount from map (#20625)
  fix(proto): remove conditional preventing proper generated file placement (#20650)
  (serverv2/cometbft) Read config from commands & handle `FlagNode` (#20621)
  fix(x/consensus): fix .proto file placement (#20646)
  fix(store): avoid nil error on not exhausted payload stream (#20644)
  fix (x/accounts): Fix genesis condition check (#20645)
  feat(accounts): add genesis account initialization (#20642)
  fix(x/gov): limit execution in gov (#20348)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants