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): use account number as state prefix for account state #18664

Merged
merged 2 commits into from
Dec 11, 2023

Conversation

testinginprod
Copy link
Contributor

@testinginprod testinginprod commented Dec 8, 2023

Description

Before this PR account state was stored as:

  • account_module_store_key + account_address + state

After this PR account state is stored as:

  • account_module_store_key + account_number + state.

This gives some nice properties:

  • smaller state keys for accounts
  • constant size prefixes

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

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 account number field to enhance account identification and management.
  • Bug Fixes

    • Adjusted account-related functions to correctly handle the new account number field.
  • Documentation

    • Updated message definitions to reflect the addition of the account number field.
  • Refactor

    • Improved account context creation with additional account number parameter.
    • Enhanced account state storage with composite keys for better data organization.
  • Style

    • Standardized message interface naming for consistency across the codebase.

Copy link
Contributor

coderabbitai bot commented Dec 8, 2023

Walkthrough

Walkthrough

The overall change involves the introduction of an AccountNumber field to the GenesisAccount structure and its handling across various functions and methods. This includes updates to the Go source code and protobuf definitions, reflecting a shift towards using a numerical identifier for accounts. The changes affect how accounts are stored, accessed, and managed within the codebase, with updates to function signatures, method calls, and data structures to accommodate the new account number field.

Changes

File(s) Summary
api/cosmos/accounts/v1/genesis.pulsar.go
x/accounts/genesis.go
x/accounts/internal/implementation/context.go
x/accounts/internal/implementation/context_test.go
x/accounts/keeper.go
Introduced AccountNumber field to GenesisAccount and updated associated methods, function signatures, and data structures to handle the new field.
proto/cosmos/accounts/v1/genesis.proto Modified GenesisAccount message to include account_number field and updated field numbering.
store/root/store_test.go Added import for "cosmossdk.io/store/v2/pruning" and adjusted import order.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Note: For conversation with the bot, please use the review comments on code diffs or files.

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

@testinginprod testinginprod marked this pull request as ready for review December 8, 2023 16:57
@testinginprod testinginprod requested a review from a team as a code owner December 8, 2023 16:57
Copy link
Contributor

github-actions bot commented Dec 8, 2023

@testinginprod your pull request is missing a changelog!

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8fb6205 and 2468521.
Files ignored due to filter (1)
  • x/accounts/v1/genesis.pb.go
Files selected for processing (7)
  • api/cosmos/accounts/v1/genesis.pulsar.go (14 hunks)
  • proto/cosmos/accounts/v1/genesis.proto (1 hunks)
  • store/root/store_test.go (1 hunks)
  • x/accounts/genesis.go (3 hunks)
  • x/accounts/internal/implementation/context.go (3 hunks)
  • x/accounts/internal/implementation/context_test.go (5 hunks)
  • x/accounts/keeper.go (8 hunks)
Files skipped from review due to trivial changes (1)
  • store/root/store_test.go
Additional comments: 19
api/cosmos/accounts/v1/genesis.pulsar.go (5)
  • 557-622: The summary mentions renaming of _GenesisAccount_3_list to _GenesisAccount_4_list, but the provided code does not show any such renaming. It only shows the final state of the code with _GenesisAccount_4_list.

  • 702-707: The addition of the AccountNumber field to the GenesisAccount struct aligns with the PR objectives and the summary provided.

  • 1908-1911: The summary does not mention any changes to the KVPair struct, but the provided code includes this struct.

  • 699-712: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [624-1011]

The summary does not mention the fastReflection_GenesisAccount type, but the provided code includes this type and related methods.

  • 1912-1925: The summary does not mention the fastReflection_KVPair type, but the provided code includes this type and related methods.
proto/cosmos/accounts/v1/genesis.proto (1)
  • 18-24: The changes to the GenesisAccount message are consistent with the PR objectives and the provided summary. The addition of the account_number field and the update to the state field's number from 3 to 4 are correctly implemented.
x/accounts/genesis.go (3)
  • 20-30: The addition of AccountNumber to genState and its usage in the exportAccount method call is consistent with the PR's objective to use account numbers as prefixes for state keys.

  • 41-58: The changes to the exportAccount method, including the addition of AccountNumber to the GenesisAccount struct and the use of a prefixed pair range for the AccountsState.Walk method, align with the PR's objective to use account numbers as prefixes.

  • 89-100: The updates to the importAccount method, including setting the account number and using it in the AccountsState.Set method call, are consistent with the PR's objective to use account numbers as prefixes for state keys.

x/accounts/internal/implementation/context.go (1)
  • 66-66: Verify the length of AccountStatePrefix is intended to be 255 and that it aligns with the system's requirements for prefix lengths.

The new context from the shell commands shows that AccountStatePrefix is used in multiple places within the codebase:

  • It is used to initialize AccountsState in keeper.go.
  • It is used in a Get method call in context_test.go.
  • It is declared as a new prefix with a length of 255 in context.go.
  • It is used in the prefixstore.New call in context.go.

Given this usage, it seems that the length of 255 is intentional and consistently used across the system for the account state prefix. There is no indication that this length is incorrect or inconsistent with the system's requirements for prefix lengths.

Final review comment:

The length of `AccountStatePrefix` is confirmed to be intentionally set to 255 and is consistently used across the system. The changes align with the PR objectives and are correctly implemented.

x/accounts/internal/implementation/context_test.go (5)
  • 5-5: The addition of the encoding/binary package is appropriate for handling binary encoding operations as per the PR's objective to change the storage method.

  • 21-21: The update to the MakeAccountContext function call to use an integer for the account number is consistent with the PR's objective to use account numbers as prefixes.

  • 42-44: The test correctly verifies that the account state is stored with the new prefix format, which includes the account number in big-endian format.

  • 59-61: The update to the MakeAccountContext function call and the test for the module execution response are consistent with the PR's changes.

  • 70-72: The update to the MakeAccountContext function call and the test for the query module response are consistent with the PR's changes.

x/accounts/keeper.go (4)
  • 86-90: The AccountsState data structure has been updated to use composite keys of type collections.Pair[uint64, []byte] instead of simple []byte keys, aligning with the PR objective to use account numbers as prefixes. This change will affect how account state values are stored and accessed, ensuring a constant size for the prefixes and potentially improving the efficiency of state key storage.

  • 125-130: The comment above AccountsState explains its usage for genesis import and export, providing a mapping between account numbers and account state keys to their values. This is a helpful comment for maintainability, as it clarifies the purpose of the data structure within the system.

  • 158-158: The makeAccountContext function signature has been correctly updated to include the accountNumber uint64 parameter, which is used to create a context for an account. This change is consistent with the PR's objective to use account numbers in account state management.

  • 365-365: The variable msgInterfaceName has been renamed from "cosmos.accounts.Msg.v1" to "cosmos.accounts.v1.MsgInterface". This change reflects a modification in the naming convention or structure of message interfaces and should be verified across the codebase to ensure consistency.


The variable msgInterfaceName has been successfully renamed to "cosmos.accounts.v1.MsgInterface" and is consistent within the codebase.

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -194,8 +194,14 @@ func (k Keeper) Execute(
return nil, err
}

// get account number
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// get account number

Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -86,7 +86,7 @@ func NewKeeper(
AccountNumber: collections.NewSequence(sb, AccountNumberKey, "account_number"),
AccountsByType: collections.NewMap(sb, AccountTypeKeyPrefix, "accounts_by_type", collections.BytesKey, collections.StringValue),
AccountByNumber: collections.NewMap(sb, AccountByNumber, "account_by_number", collections.BytesKey, collections.Uint64Value),
AccountsState: collections.NewMap(sb, implementation.AccountStatePrefix, "accounts_state", collections.BytesKey, collections.BytesValue),
AccountsState: collections.NewMap(sb, implementation.AccountStatePrefix, "accounts_state", collections.PairKeyCodec(collections.Uint64Key, collections.BytesKey), collections.BytesValue),
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be good to add a godoc or inline comment mentioning the keys and value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@testinginprod testinginprod added this pull request to the merge queue Dec 11, 2023
Merged via the queue into main with commit 39865d8 Dec 11, 2023
59 of 62 checks passed
@testinginprod testinginprod deleted the tip/accounts/use_acc_num branch December 11, 2023 11:45
marcello33 added a commit to 0xPolygon/cosmos-sdk that referenced this pull request Dec 13, 2023
* feat: secp256k1 public key constant time (cosmos#18026)

Signed-off-by: bizk <[email protected]>

* chore: Fixed changelog duplicated items (cosmos#18628)

* adr: Un-Ordered Transaction Inclusion (cosmos#18553)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <[email protected]>

* docs: lint ADR-070 (cosmos#18634)

* fix(baseapp)!: postHandler should run regardless of result (cosmos#18627)

* docs: fix typos in adr-007-specialization-groups.md (cosmos#18635)

* chore: alphabetize labels (cosmos#18640)

* docs(x/circuit): add note on ante handler (cosmos#18637)

Co-authored-by: Aleksandr Bezobchuk <[email protected]>

* fix: telemetry metric label variable (cosmos#18643)

* chore: typos fix (cosmos#18642)

* refactor(store/v2): updates from integration (cosmos#18633)

* build(deps): Bump actions/setup-go from 4 to 5 (cosmos#18647)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* feat(store/v2): snapshot manager (cosmos#18458)

* chore(client/v2): fix typos in the README.md (cosmos#18657)

* fix(baseapp):  protocompat.go gogoproto.Merge does not work with custom types (cosmos#18654)

Co-authored-by: unknown unknown <unknown@unknown>

* chore: fix several minor typos (cosmos#18660)

* chore(tools/confix/cmd): fix typo in view.go (cosmos#18659)

* refactor(x/staking): check duplicate addresses in StakeAuthorization's params (cosmos#18655)

* feat(accounts): use gogoproto API instead of protov2.  (cosmos#18653)

Co-authored-by: unknown unknown <unknown@unknown>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix(store/commitment/iavl): honor tree.Remove error firstly (cosmos#18651)

* build(deps): Bump actions/stale from 8 to 9 (cosmos#18656)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(docs): fix typos & wording in docs (cosmos#18667)

* chore: fix several typos.   (cosmos#18666)

* feat(telemetry): enable `statsd` and `dogstatsd` telemetry sinks (cosmos#18646)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Co-authored-by: marbar3778 <[email protected]>
Co-authored-by: Marko <[email protected]>

* feat(store/v2): add SetInitialVersion in SC (cosmos#18665)

* feat(client/keys): support display discreetly for `keys add` (cosmos#18663)

Co-authored-by: Julien Robert <[email protected]>

* ci: add misspell action (cosmos#18671)

* chore: typos fix by misspell-fixer (cosmos#18683)

Co-authored-by: github-merge-queue <[email protected]>
Co-authored-by: Julien Robert <[email protected]>

* chore: add v0.50.2 changelog to main (cosmos#18682)

* build(deps): Bump github.com/jhump/protoreflect from 1.15.3 to 1.15.4 in /tests (cosmos#18678)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* refactor(bank): remove .String() calls  (cosmos#18175)

Co-authored-by: Facundo <[email protected]>

* ci: use codespell instead of misspell-fixer (cosmos#18686)

Co-authored-by: Marko <[email protected]>

* feat(gov): add proposal types and spam votes (cosmos#18532)

* feat(accounts): use account number as state prefix for account state (cosmos#18664)

Co-authored-by: unknown unknown <unknown@unknown>

* chore: typos fixes by cosmos-sdk bot (cosmos#18689)

Co-authored-by: github-merge-queue <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
Co-authored-by: marbar3778 <[email protected]>

* feat(client/keys): support display discreetly for keys mnemonic (cosmos#18688)

* refactor: remove panic usage in keeper methods (cosmos#18636)

* ci: rename pr name in misspell job (cosmos#18693)

Co-authored-by: Marko <[email protected]>

* build(deps): Bump github.com/pelletier/go-toml/v2 from 2.1.0 to 2.1.1 in /tools/confix (cosmos#18702)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* feat(client/keys): support display discreetly for keys export (cosmos#18684)

* feat(x/gov): better gov genesis validation (cosmos#18707)

---------

Signed-off-by: bizk <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Carlos Santiago Yanzon <[email protected]>
Co-authored-by: yihuang <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Co-authored-by: Facundo Medica <[email protected]>
Co-authored-by: Akaonetwo <[email protected]>
Co-authored-by: Marko <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
Co-authored-by: dreamweaverxyz <[email protected]>
Co-authored-by: Pioua <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: cool-developer <[email protected]>
Co-authored-by: leonarddt05 <[email protected]>
Co-authored-by: testinginprod <[email protected]>
Co-authored-by: unknown unknown <unknown@unknown>
Co-authored-by: Sukey <[email protected]>
Co-authored-by: axie <[email protected]>
Co-authored-by: Luke Ma <[email protected]>
Co-authored-by: Emmanuel T Odeke <[email protected]>
Co-authored-by: 0xn4de <[email protected]>
Co-authored-by: hattizai <[email protected]>
Co-authored-by: Devon Bear <[email protected]>
Co-authored-by: Marko <[email protected]>
Co-authored-by: Halimao <[email protected]>
Co-authored-by: Cosmos SDK <[email protected]>
Co-authored-by: github-merge-queue <[email protected]>
Co-authored-by: Facundo <[email protected]>
Co-authored-by: Likhita Polavarapu <[email protected]>
@testinginprod testinginprod mentioned this pull request Dec 19, 2023
44 tasks
@marcello33 marcello33 mentioned this pull request Jan 22, 2024
12 tasks
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.

5 participants