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!: migrate x/group to store service #19410

Merged
merged 7 commits into from
Feb 13, 2024
Merged

feat!: migrate x/group to store service #19410

merged 7 commits into from
Feb 13, 2024

Conversation

facundomedica
Copy link
Member

@facundomedica facundomedica commented Feb 12, 2024

Description

Migrated x/group to store service to make it fully compatible with the upcoming server/v2

closes #19382


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 a new prefixstore package for handling key-value pairs efficiently.
  • Refactor
    • Enhanced initialization and usage of GroupKeeper for better performance.
    • Streamlined code in various modules for improved efficiency and readability.
    • Updated import paths and store initialization across multiple files to align with the new store service model.
  • Bug Fixes
    • Refined error handling and store operations in various functions to ensure robustness.
  • Documentation
    • Documented API breaking changes related to the migration to Store Service in the changelog.

Copy link
Contributor

coderabbitai bot commented Feb 12, 2024

Walkthrough

Walkthrough

These updates focus on improving the codebase by streamlining variable declarations, loop iterations, and store initialization. A significant change is the migration to a new Store Service, impacting various components like GroupKeeper initialization and ORM operations. This transition necessitates adjustments across the board, from import paths and function signatures to error handling and test setups, aiming to enhance efficiency and maintainability.

Changes

Files Summary of Changes
math/int_test.go Streamlined code through updated variable declarations and loop iterations.
simapp/app.go Initialized app.GroupKeeper with runtime.NewKVStoreService.
x/group/CHANGELOG.md Noted API breaking change for Store Service migration.
x/group/internal/orm/... (multiple files) Updated import paths, store parameter types, error handling, and store initialization.
x/group/internal/orm/prefixstore/prefixstore.go Introduced prefixstore package.
x/group/keeper/... (multiple files) Adjusted Keeper functions, grpc_query operations, and Tally function for storeService usage.
x/group/migrations/v2/... (multiple files) Updated import paths and store handling for migration operations.
x/group/module/depinject.go Replaced store.KVStoreKey with store.KVStoreService in GroupInputs.

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @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.
  • 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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@@ -453,7 +451,7 @@
return errorsmod.Wrap(err, "doTallyAndUpdate")
}

if err := k.proposalTable.Update(ctx.KVStore(k.key), proposal.Id, &proposal); err != nil {
if err := k.proposalTable.Update(k.storeService.OpenKVStore(ctx), proposal.Id, &proposal); err != nil {

Check failure

Code scanning / gosec

Implicit memory aliasing in for loop. Error

Implicit memory aliasing in for loop.
@@ -351,7 +349,7 @@

//nolint:gosec // "implicit memory aliasing in the for loop (because of the pointer on &v)"
for _, v := range votes {
err = k.voteTable.Delete(ctx.KVStore(k.key), &v)
err = k.voteTable.Delete(k.storeService.OpenKVStore(ctx), &v)

Check failure

Code scanning / gosec

Implicit memory aliasing in for loop. Error

Implicit memory aliasing in for loop.
@@ -310,7 +308,7 @@
if proposalInfo.Status == group.PROPOSAL_STATUS_SUBMITTED {
proposalInfo.Status = group.PROPOSAL_STATUS_ABORTED

if err := k.proposalTable.Update(ctx.KVStore(k.key), proposalInfo.Id, &proposalInfo); err != nil {
if err := k.proposalTable.Update(k.storeService.OpenKVStore(ctx), proposalInfo.Id, &proposalInfo); err != nil {

Check failure

Code scanning / gosec

Implicit memory aliasing in for loop. Error

Implicit memory aliasing in for loop.
@facundomedica facundomedica changed the title feat: migrate x/group to store service feat!: migrate x/group to store service Feb 12, 2024
@facundomedica facundomedica marked this pull request as ready for review February 13, 2024 08:36
@facundomedica facundomedica requested a review from a team as a code owner February 13, 2024 08:36
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: 39

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 313a989 and a96dee6.
Files selected for processing (38)
  • math/int_test.go (2 hunks)
  • simapp/app.go (1 hunks)
  • x/group/CHANGELOG.md (1 hunks)
  • x/group/internal/orm/auto_uint64.go (1 hunks)
  • x/group/internal/orm/auto_uint64_test.go (3 hunks)
  • x/group/internal/orm/genesis.go (1 hunks)
  • x/group/internal/orm/genesis_test.go (2 hunks)
  • x/group/internal/orm/index.go (7 hunks)
  • x/group/internal/orm/index_test.go (4 hunks)
  • x/group/internal/orm/indexer.go (5 hunks)
  • x/group/internal/orm/indexer_test.go (10 hunks)
  • x/group/internal/orm/iterator_test.go (2 hunks)
  • x/group/internal/orm/orm_scenario_test.go (9 hunks)
  • x/group/internal/orm/prefixstore/prefixstore.go (1 hunks)
  • x/group/internal/orm/primary_key.go (1 hunks)
  • x/group/internal/orm/primary_key_property_test.go (1 hunks)
  • x/group/internal/orm/primary_key_test.go (4 hunks)
  • x/group/internal/orm/sequence.go (3 hunks)
  • x/group/internal/orm/sequence_property_test.go (1 hunks)
  • x/group/internal/orm/sequence_test.go (2 hunks)
  • x/group/internal/orm/table.go (12 hunks)
  • x/group/internal/orm/table_test.go (4 hunks)
  • x/group/internal/orm/types.go (2 hunks)
  • x/group/internal/orm/types_test.go (2 hunks)
  • x/group/keeper/genesis.go (2 hunks)
  • x/group/keeper/genesis_test.go (3 hunks)
  • x/group/keeper/grpc_query.go (10 hunks)
  • x/group/keeper/grpc_query_test.go (3 hunks)
  • x/group/keeper/invariants.go (3 hunks)
  • x/group/keeper/invariants_test.go (2 hunks)
  • x/group/keeper/keeper.go (10 hunks)
  • x/group/keeper/keeper_test.go (3 hunks)
  • x/group/keeper/migrations.go (1 hunks)
  • x/group/keeper/msg_server.go (28 hunks)
  • x/group/keeper/tally.go (2 hunks)
  • x/group/migrations/v2/migrate.go (2 hunks)
  • x/group/migrations/v2/migrate_test.go (3 hunks)
  • x/group/module/depinject.go (3 hunks)
Additional comments: 111
x/group/keeper/migrations.go (1)
  • 23-23: Parameter m.keeper.storeService is correctly updated to align with the new store service migration. This change is consistent with the PR's objective to migrate to a new store service.
x/group/internal/orm/genesis.go (1)
  • 3-3: The import path update from "cosmossdk.io/store/types" to "cosmossdk.io/core/store" is correct and aligns with the new store service integration.
x/group/CHANGELOG.md (1)
  • 37-37: The changelog entry for the migration to Store Service is correctly added under the API Breaking Changes section, providing clear documentation of the change.
x/group/internal/orm/sequence_test.go (1)
  • 17-19: The update to use runtime.NewKVStoreService for store initialization in tests is correct and aligns with the migration to the new store service.
x/group/internal/orm/genesis_test.go (1)
  • 24-26: The update to use runtime.NewKVStoreService and testutil.DefaultContextWithDB for store and context setup in tests is correct and aligns with the migration to the new store service.
x/group/module/depinject.go (2)
  • 33-33: Replacing store.KVStoreKey with store.KVStoreService in the GroupInputs struct is correct and aligns with the migration to the new store service.
  • 49-49: The update in the ProvideModule function to use in.StoreService instead of a store key is correct and aligns with the migration to the new store service.
x/group/keeper/tally.go (1)
  • 25-25: Using storeService to open a KV store instead of directly accessing ctx.KVStore(k.key) is correct and aligns with the migration to the new store service.
x/group/internal/orm/sequence_property_test.go (1)
  • 16-21: The update to use testutil.DefaultContextWithDB and runtime.NewKVStoreService for context and store setup in tests is correct and aligns with the migration to the new store service.
x/group/internal/orm/types_test.go (2)
  • 13-13: Importing prefixstore from cosmossdk.io/x/group/internal/orm is correct and aligns with the migration to the new store service.
  • 24-28: The update to use prefixstore.New instead of prefix.NewStore and the adjustments in store operations within the test function are correct and align with the migration to the new store service.
x/group/keeper/genesis.go (1)
  • 20-20: Replacing usages of sdkCtx.KVStore(k.key) with store for various table imports and exports within the InitGenesis and ExportGenesis functions is correct and aligns with the migration to the new store service.
x/group/migrations/v2/migrate.go (3)
  • 7-7: Updating the import path for the store package is correct and aligns with the migration to the new store service.
  • 28-28: Changing the storeKey parameter to storeService of type store.KVStoreService is correct and aligns with the migration to the new store service.
  • 33-33: Updating the store initialization to use storeService.OpenKVStore(ctx) is correct and aligns with the migration to the new store service.
x/group/internal/orm/sequence.go (2)
  • 6-9: Refactoring the storage handling by introducing a new prefixstore package and updating method calls accordingly is correct and aligns with the migration to the new store service.
  • 28-38: Adjusting error handling in the NextVal method to panic on errors is a significant change. Ensure that this behavior is intentional and documented, as it could affect the application's stability.
x/group/keeper/invariants.go (2)
  • 10-10: Updating the usage of storetypes from "cosmossdk.io/store/types" to "cosmossdk.io/core/store" is correct and aligns with the migration to the new store service.
  • 29-29: Modifying the handling of store operations within the GroupTotalWeightInvariantHelper function by introducing storeService for interacting with the KVStore is correct and aligns with the migration to the new store service.
x/group/keeper/invariants_test.go (2)
  • 19-19: Introducing a new import for runtime is correct and aligns with the migration to the new store service.
  • 135-137: Utilizing runtime.NewKVStoreService to create a key-value store service in tests is correct and aligns with the migration to the new store service.
x/group/migrations/v2/migrate_test.go (3)
  • 38-38: Ensure runtime.NewKVStoreService(storeKey) is correctly initializing storeService with the intended store key. This is crucial for the migration logic to function properly.
  • 43-43: The function createGroupPolicies now correctly accepts corestore.KVStoreService as an argument, aligning with the migration objectives. Verify that all calls to this function have been updated accordingly.
  • 46-46: The v2.Migrate function's signature update to accept runtime.KVStoreService is in line with the migration plan. Ensure all invocations of Migrate are updated to pass the correct type.
x/group/internal/orm/auto_uint64_test.go (1)
  • 29-31: The store initialization with runtime.NewKVStoreService(key).OpenKVStore(testCtx.Ctx) correctly reflects the migration to the new store service. Ensure the test context is appropriately set up for all tests.
x/group/internal/orm/auto_uint64.go (1)
  • 6-6: The update to the import path for storetypes aligns with the migration to the new store service. Verify that all usages of storetypes in this file are compatible with the changes.
x/group/internal/orm/primary_key_property_test.go (1)
  • 19-152: The refactoring of TestPrimaryKeyTable using a closure for rapid.Check improves test encapsulation and readability. Ensure that the initialization of context, store, and table, as well as the model commands within the closure, are correctly implemented and maintain the intended test coverage.
x/group/internal/orm/types.go (1)
  • 119-124: The update to NewTypeSafeRowGetter to use prefixstore and handle errors during Get operations is a significant improvement. Ensure that the error handling is correctly implemented and that it aligns with the intended functionality.
x/group/internal/orm/prefixstore/prefixstore.go (1)
  • 1-223: The introduction of the prefixstore package and its adaptation to the cosmossdk.io/core/store.KVStore interface is correctly implemented. Ensure that the key prefixing logic, KVStore methods, and iterator functionality are thoroughly tested to confirm compatibility and correctness.
x/group/internal/orm/indexer.go (4)
  • 4-4: The import path for storetypes has been correctly updated to reflect the new store service structure.
  • 145-145: The use of store.Set in uniqueKeysAddFunc is correct and does not require error handling as it does not return an error.
  • 150-153: Error handling in checkUniqueIndexKey for store.Iterator is correctly implemented, ensuring robustness in index key uniqueness checks.
  • 179-179: The use of store.Set in multiKeyAddFunc is correct and does not require error handling as it does not return an error.
x/group/internal/orm/primary_key.go (1)
  • 6-6: The import path for storetypes has been correctly updated to "cosmossdk.io/core/store", aligning with the new store service structure.
x/group/internal/orm/primary_key_test.go (1)
  • 9-17: The introduction of new imports related to cosmos-sdk and cosmossdk.io is correctly done to support the updated test setup.
x/group/keeper/genesis_test.go (2)
  • 25-25: The introduction of the runtime import is correctly done to support the new store service initialization in the test setup.
  • 76-76: Modification of keeper.NewKeeper to pass storeService instead of key is correctly implemented, aligning with the new store service migration.
x/group/internal/orm/index.go (9)
  • 19-21: Update function signatures to use storetypes.KVStore aligns with the migration requirements.
  • 76-86: Correct use of storetypes.KVStore and prefixstore.New for store initialization and iterator handling.
  • 92-102: Correct use of storetypes.KVStore and prefixstore.New for store initialization and iterator handling in Get function.
  • 121-131: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [109-128]

Correct use of storetypes.KVStore and prefixstore.New for paginated store access. Proper handling of pageRequest.Key for pagination logic.

  • 149-160: Correct use of storetypes.KVStore and prefixstore.New for prefix scanning. Proper error handling and iterator usage.
  • 173-184: Correct use of storetypes.KVStore and prefixstore.New for reverse prefix scanning. Proper error handling and iterator usage.
  • 223-232: Correct use of storetypes.KVStore and prefixstore.New in onSet method. Proper handling of oldValue for update scenarios.
  • 231-232: Correct use of storetypes.KVStore and prefixstore.New in onDelete method. Ensures proper deletion logic.
  • 257-257: Correct use of storetypes.KVStore in indexIterator struct. Ensures compatibility with the new store service.
x/group/internal/orm/iterator_test.go (1)
  • 214-216: Correct update to test setup using storetypes.NewKVStoreKey, testutil.DefaultContextWithDB, and runtime.NewKVStoreService for KV store initialization. Aligns with the new store service integration.
x/group/internal/orm/table.go (7)
  • 128-138: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [78-135]

Correct implementation of Create, Update, and Set methods using storetypes.KVStore and prefixstore.New. Ensures compatibility with the new store service and proper error handling.

  • 159-169: Correct implementation of Delete method using storetypes.KVStore and prefixstore.New. Proper error handling and interceptor invocation.
  • 181-190: Correct use of storetypes.KVStore and prefixstore.New in Has method. Ensures proper key existence check.
  • 218-238: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [196-231]

Correct implementation of GetOne, PrefixScan, and ReversePrefixScan methods using storetypes.KVStore and prefixstore.New. Ensures compatibility with the new store service and proper iterator handling.

  • 245-270: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [267-281]

Correct approach in Export and Import methods using storetypes.KVStore. Proper handling of data export and import logic.

  • 311-316: Correct use of storetypes.KVStore and prefixstore.New in keys method for fetching all keys. Proper iterator handling and error management.
  • 328-328: Correct use of storetypes.KVStore in typeSafeIterator struct. Ensures compatibility with the new store service.
x/group/keeper/grpc_query_test.go (3)
  • 22-22: The import of the runtime package is correctly added to support the new store service functionality.
  • 46-46: Initialization of storeService using runtime.NewKVStoreService(key) is correctly implemented to align with the migration to the new store service.
  • 72-72: Correct use of storeService in groupkeeper.NewKeeper to replace previous sdkCtx.KVStore(k.key) and storetypes.StoreKey usages.
x/group/internal/orm/index_test.go (5)
  • 9-9: The addition of new imports for cosmossdk.io/core/store, cosmossdk.io/errors, and cosmossdk.io/store/types is appropriate for the updated test functionalities.
  • 16-17: The import of the runtime package and testutil is correctly added to support the new store service functionality in tests.
  • 107-109: Correct initialization of store using runtime.NewKVStoreService(key).OpenKVStore(testCtx.Ctx) for store operations in tests.
  • 137-137: Proper use of store as a parameter in method function calls within test cases, aligning with the new store service's requirements.
  • 308-310: Correct initialization of store using runtime.NewKVStoreService(key).OpenKVStore(testCtx.Ctx) for unique index tests.
x/group/keeper/grpc_query.go (13)
  • 36-36: Correct usage of storeService.OpenKVStore(ctx) in getGroupInfo function to access the store.
  • 59-59: Proper use of storeService.OpenKVStore(ctx) in getGroupPolicyInfo function for store operations.
  • 85-85: Correct implementation of storeService.OpenKVStore(ctx) in getGroupMembers function to retrieve group members.
  • 114-114: Appropriate use of storeService.OpenKVStore(ctx) in getGroupsByAdmin function for querying groups by admin.
  • 140-140: Proper usage of storeService.OpenKVStore(ctx) in getGroupPoliciesByGroup function for querying group policies by group.
  • 170-170: Correct implementation of storeService.OpenKVStore(ctx) in getGroupPoliciesByAdmin function for querying group policies by admin.
  • 211-211: Appropriate use of storeService.OpenKVStore(ctx) in getProposalsByGroupPolicy function for querying proposals by group policy.
  • 217-217: Correct usage of storeService.OpenKVStore(ctx) in getProposal function to retrieve proposal information.
  • 326-326: Proper implementation of storeService.OpenKVStore(ctx) in getVote function for retrieving vote information.
  • 331-331: Correct use of storeService.OpenKVStore(ctx) in getVotesByProposal function for querying votes by proposal.
  • 336-336: Appropriate implementation of storeService.OpenKVStore(ctx) in getVotesByVoter function for querying votes by voter.
  • 372-372: Correct usage of storeService.OpenKVStore(ctx) in Groups function for querying all groups.
  • 297-297: Proper use of storeService.OpenKVStore(ctx) in GroupsByMember function for querying groups by member.
x/group/internal/orm/orm_scenario_test.go (7)
  • 12-19: Imports cosmos-sdk/runtime and cosmos-sdk/testutil are added to replace deprecated context and store initialization methods with the new store service approach. This aligns with the PR objectives.
  • 30-32: The usage of testutil.DefaultContextWithDB and runtime.NewKVStoreService to open KV stores is correct and aligns with the new store service integration. This change ensures compatibility with server/v2.
  • 109-111: Repeating the pattern of using testutil.DefaultContextWithDB and runtime.NewKVStoreService for another test function. Consistency in test setup is maintained across the file.
  • 196-198: Again, consistent use of testutil.DefaultContextWithDB and runtime.NewKVStoreService for setting up the test context and store. This consistency is good for maintainability.
  • 294-296: The same pattern of using testutil.DefaultContextWithDB and runtime.NewKVStoreService is applied here, ensuring that all tests are updated to use the new store service.
  • 356-358: The consistent application of the new store service setup across all test functions in this file is noted. This ensures that all tests are aligned with the new store service integration.
  • 406-406: The function signature of assertIndex is updated to use corestore.KVStore instead of the previous store type. This change is necessary for compatibility with the new store service and follows best practices for type usage.
x/group/keeper/keeper.go (11)
  • 49-49: The storeService field is correctly added to the Keeper struct to replace the old store key with corestoretypes.KVStoreService. This change is necessary for the migration to the new store service.
  • 86-91: The NewKeeper function is correctly updated to accept corestoretypes.KVStoreService as a parameter and initialize the Keeper struct with it. This change aligns with the migration objectives.
  • 245-245: The GetGroupSequence function correctly uses k.storeService.OpenKVStore(ctx) to access the store, aligning with the new store service approach.
  • 250-250: The GetGroupPolicySeq function is updated to use the new store service for accessing the store, which is consistent with the migration to the new store service.
  • 256-256: In proposalsByVPEnd, the use of k.storeService.OpenKVStore(ctx) for store access is correct and aligns with the new store service integration.
  • 288-288: The pruneProposal function correctly uses the new store service to access and modify the store, which is in line with the migration objectives.
  • 311-311: The abortProposals function correctly updates proposals using the new store service. The existing comment about implicit memory aliasing is noted but not directly related to the migration changes.
  • 321-321: The proposalsByGroupPolicy function's use of the new store service for accessing the store is correct and aligns with the migration to the new store service.
  • 352-352: In pruneVotes, the deletion of votes using the new store service is correctly implemented. The existing comment about implicit memory aliasing is noted but not directly related to the migration changes.
  • 363-363: The votesByProposal function's use of the new store service for accessing the store is correct and aligns with the migration to the new store service.
  • 454-454: The TallyProposalsAtVPEnd function correctly updates proposals using the new store service. The existing comment about implicit memory aliasing is noted but not directly related to the migration changes.
x/group/internal/orm/indexer_test.go (11)
  • 11-18: Ensure the newly introduced imports are used effectively within the test cases, particularly corestore, prefixstore, and testutil. These changes are crucial for aligning the tests with the updated module structure.
  • 170-172: The store initialization using testutil.DefaultContextWithDB and runtime.NewKVStoreService followed by prefixstore.New is correctly updated to reflect the new store service integration. This pattern is consistent with the migration objectives.
  • 231-233: The use of store.Has within the TestIndexerOnDelete test case correctly checks for the existence of keys before deletion. This ensures the test accurately reflects the expected behavior of the Indexer on delete operations.
  • 244-246: The verification of key absence using store.Has after the OnDelete operation is executed correctly, ensuring the test validates the deletion logic within the Indexer.
  • 256-258: Initialization of the store for TestIndexerOnUpdate using testutil.DefaultContextWithDB and runtime.NewKVStoreService followed by prefixstore.New is consistent with the updated module structure and store service integration.
  • 345-345: The custom addFunc provided in the TestIndexerOnUpdate for simulating an error case on persisting new keys demonstrates a good testing practice by covering error handling scenarios.
  • 371-378: Assertions within TestIndexerOnUpdate for checking the presence and absence of keys after the update operation are correctly implemented, ensuring the test accurately reflects the expected behavior of the Indexer.
  • 413-416: Store initialization in TestUniqueKeyAddFunc using runtime.NewKVStoreService and testutil.DefaultContextWithDB is correctly updated to reflect the new store service integration, aligning with the migration objectives.
  • 423-426: The assertion for the existence of the expected entry after calling uniqueKeysAddFunc in TestUniqueKeyAddFunc correctly verifies the functionality of adding unique keys to the store.
  • 460-463: Initialization of the store in TestMultiKeyAddFunc using runtime.NewKVStoreService and testutil.DefaultContextWithDB is correctly implemented, reflecting the integration of the new store service.
  • 470-473: The assertion for the existence of the expected entry after calling multiKeyAddFunc in TestMultiKeyAddFunc correctly verifies the functionality of adding keys to the store, ensuring the test accurately reflects the expected behavior.
x/group/keeper/keeper_test.go (3)
  • 26-26: The introduction of the runtime package is correctly used for creating a new storeService instance, aligning with the migration to the new store service.
  • 53-53: The creation of storeService using runtime.NewKVStoreService is correctly implemented, reflecting the updated approach to store management in the keeper tests.
  • 79-79: The update to the keeper.NewKeeper call to include storeService as a parameter is correctly implemented, ensuring the keeper is initialized with the new store service.
math/int_test.go (2)
  • 692-692: Use shorthand variable declaration for ints to improve readability and align with Go idiomatic practices.
  • 702-702: Simplify loop iteration by removing unnecessary variable declaration. This change improves readability and is more idiomatic Go.
simapp/app.go (1)
  • 369-369: The initialization of app.GroupKeeper using runtime.NewKVStoreService correctly aligns with the objective of migrating to a new store service. Ensure that the groupConfig passed to groupkeeper.NewKeeper is properly configured and that all necessary parameters are correctly set for the new store service.
x/group/keeper/msg_server.go (1)
  • 139-139: The switch statement for error handling is correct, but ensure consistency in error handling patterns across the codebase for readability and maintainability.

@@ -62,22 +62,23 @@ func (k Keeper) CreateGroup(goCtx context.Context, msg *group.MsgCreateGroup) (*

// Create a new group in the groupTable.
ctx := sdk.UnwrapSDKContext(goCtx)
kvStore := k.storeService.OpenKVStore(goCtx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Introduce error handling for OpenKVStore to ensure robustness in case the store cannot be opened.

groupInfo := &group.GroupInfo{
Id: k.groupTable.Sequence().PeekNextVal(ctx.KVStore(k.key)),
Id: k.groupTable.Sequence().PeekNextVal(kvStore),
Copy link
Contributor

Choose a reason for hiding this comment

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

The Id field assignment using PeekNextVal without incrementing the sequence might lead to ID collisions or misuse. Consider using a method that both retrieves and increments the sequence value.

Admin: msg.Admin,
Metadata: msg.Metadata,
Version: 1,
TotalWeight: totalWeight.String(),
CreatedAt: ctx.HeaderInfo().Time,
}
groupID, err := k.groupTable.Create(ctx.KVStore(k.key), groupInfo)
groupID, err := k.groupTable.Create(kvStore, groupInfo)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure that Create method calls that modify state are followed by appropriate error handling to maintain data integrity in case of failures.

if err != nil {
return nil, errorsmod.Wrap(err, "could not create group")
}

// Create new group members in the groupMemberTable.
for i, m := range msg.Members {
err := k.groupMemberTable.Create(ctx.KVStore(k.key), &group.GroupMember{
err := k.groupMemberTable.Create(kvStore, &group.GroupMember{
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to previous comments, add error handling after Create method calls for robustness.

@@ -112,6 +113,7 @@
}

ctx := sdk.UnwrapSDKContext(goCtx)
kvStore := k.storeService.OpenKVStore(goCtx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing error handling for OpenKVStore here as well. This is crucial for ensuring the application does not proceed with an invalid store reference.

Comment on lines +84 to +86
if err := store.Delete(indexKey); err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Error handling in OnDelete function should not attempt to handle errors from store.Delete as it does not return an error. Remove the error handling logic.

- if err := store.Delete(indexKey); err != nil {
-     return err
- }
+ store.Delete(indexKey)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err := store.Delete(indexKey); err != nil {
return err
}
store.Delete(indexKey)

Comment on lines +110 to +112
if err := store.Delete(indexKey); err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Repeat of the previous comment regarding unnecessary error handling in OnUpdate function. store.Delete does not return an error.

- if err := store.Delete(indexKey); err != nil {
-     return err
- }
+ store.Delete(indexKey)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err := store.Delete(indexKey); err != nil {
return err
}
store.Delete(indexKey)

Comment on lines +28 to +30
key := storetypes.NewKVStoreKey("test")
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
store := runtime.NewKVStoreService(key).OpenKVStore(testCtx.Ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace direct storetypes.NewKVStoreKey and manual store initialization with runtime.NewKVStoreService to align with the new store service migration. Ensure testutil.DefaultContextWithDB is correctly used for context setup in TestPrimaryKeyTablePrefixScan.

- key := storetypes.NewKVStoreKey("test")
- testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
- store := runtime.NewKVStoreService(key).OpenKVStore(testCtx.Ctx)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
key := storetypes.NewKVStoreKey("test")
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
store := runtime.NewKVStoreService(key).OpenKVStore(testCtx.Ctx)

Comment on lines +215 to +217
key := storetypes.NewKVStoreKey("test")
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
store := runtime.NewKVStoreService(key).OpenKVStore(testCtx.Ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Repeat of the previous comment regarding store and context initialization in TestContains. Ensure consistency in the implementation across all test functions.

- key := storetypes.NewKVStoreKey("test")
- testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
- store := runtime.NewKVStoreService(key).OpenKVStore(testCtx.Ctx)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
key := storetypes.NewKVStoreKey("test")
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
store := runtime.NewKVStoreService(key).OpenKVStore(testCtx.Ctx)

@@ -49,6 +50,7 @@ var (

func (s *GenesisTestSuite) SetupTest() {
key := storetypes.NewKVStoreKey(group.StoreKey)
storeService := runtime.NewKVStoreService(key)
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace direct storetypes.NewKVStoreKey and manual store initialization with runtime.NewKVStoreService to align with the new store service migration. Ensure the correct setup for the genesis functionality tests.

- key := storetypes.NewKVStoreKey(group.StoreKey)
- storeService := runtime.NewKVStoreService(key)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
storeService := runtime.NewKVStoreService(key)

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm!

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.

looks good!

@julienrbrt julienrbrt linked an issue Feb 13, 2024 that may be closed by this pull request
@tac0turtle tac0turtle added this pull request to the merge queue Feb 13, 2024
Merged via the queue into main with commit c57dde2 Feb 13, 2024
61 of 63 checks passed
@tac0turtle tac0turtle deleted the facu/storesvc-group branch February 13, 2024 13:52
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.

Migrate x/group to use store service
4 participants