Skip to content

Conversation

@likhita-809
Copy link
Contributor

@likhita-809 likhita-809 commented Feb 20, 2024

Description

ref: #19290
Migrate x/authz to use environment bundler services


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

  • Refactor
    • Updated the initialization process for AuthzKeeper to enhance performance and reliability.
  • Tests
    • Improved test setup for better simulation and accuracy.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2024

Walkthrough

Walkthrough

The changes involve updating the initialization of the AuthzKeeper and the setup in related test files to use a new runtime.Environment instance instead of the previous runtime.NewKVStoreService. This shift indicates a move towards a more flexible or possibly a more feature-rich runtime environment handling within the application and its authorization keeper component.

Changes

File(s) Change Summary
simapp/app.go Modified app.AuthzKeeper initialization to use runtime.NewEnvironment instead of runtime.NewKVStoreService.
x/authz/keeper/genesis_test.go, x/authz/keeper/keeper_test.go Added creation of a new runtime.Environment in SetupTest function, passing it to NewKeeper instead of storeService.

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.

@likhita-809 likhita-809 marked this pull request as ready for review February 20, 2024 10:06
@likhita-809 likhita-809 requested review from a team, julienrbrt and tac0turtle February 20, 2024 10:06
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.yml

Commits Files that changed from the base of the PR and between b050ec2 and 9d89ce8.
Files selected for processing (14)
  • simapp/app.go (1 hunks)
  • x/authz/CHANGELOG.md (1 hunks)
  • x/authz/keeper/genesis.go (1 hunks)
  • x/authz/keeper/genesis_test.go (2 hunks)
  • x/authz/keeper/grpc_query.go (3 hunks)
  • x/authz/keeper/keeper.go (18 hunks)
  • x/authz/keeper/keeper_test.go (2 hunks)
  • x/authz/keeper/migrations.go (1 hunks)
  • x/authz/keeper/msg_server.go (1 hunks)
  • x/authz/migrations/v2/store.go (1 hunks)
  • x/authz/migrations/v2/store_test.go (3 hunks)
  • x/authz/module/abci_test.go (2 hunks)
  • x/authz/module/depinject.go (3 hunks)
  • x/authz/testutil/bank_helpers.go (1 hunks)
Additional comments: 37
x/authz/keeper/migrations.go (1)
  • 21-21: The update to use m.keeper.environment in the Migrate1to2 function aligns with the PR's objective of migrating to environment bundler services. Ensure that the environment object is correctly initialized and passed throughout the module to maintain consistency and functionality.
x/authz/testutil/bank_helpers.go (5)
  • 11-11: Renaming the context parameter from goCtx to ctx in the Send function improves consistency and readability.
  • 15-15: Renaming the context parameter from goCtx to ctx in the Burn function improves consistency and readability.
  • 19-19: Renaming the context parameter from goCtx to ctx in the MultiSend function improves consistency and readability.
  • 23-23: Renaming the context parameter from goCtx to ctx in the UpdateParams function improves consistency and readability.
  • 27-27: Renaming the context parameter from goCtx to ctx in the SetSendEnabled function improves consistency and readability.
x/authz/module/depinject.go (2)
  • 36-36: Replacing store.KVStoreService with appmodule.Environment in the ModuleInputs struct aligns with the PR's objective of enhancing the module's architecture. Ensure that the Environment object is correctly utilized throughout the module.
  • 47-47: The update in the ProvideModule function to use appmodule.Environment is consistent with the architectural changes. Verify the correct initialization and usage of the Environment object to ensure module functionality.
x/authz/keeper/genesis.go (1)
  • 13-13: The update to source the current time using k.environment.HeaderService.GetHeaderInfo(ctx).Time aligns with the PR's objective of utilizing environment bundler services. Ensure that the HeaderService is correctly initialized and accessible through the environment.
x/authz/CHANGELOG.md (3)
  • 40-40: The changelog entry detailing the receipt of appmodule.Environment on the Keeper to access different application services accurately reflects the significant architectural changes made in the PR.
  • 40-40: The update to the DequeueAndDeleteExpiredGrants method to include a limit argument for the number of grants to prune is accurately documented in the changelog, highlighting an important improvement.
  • 40-40: Moving AcceptResponse to sdk/types/authz and changing the Updated field type is correctly noted in the changelog, providing clarity on API changes.
x/authz/migrations/v2/store.go (2)
  • 20-21: Updating the MigrateStore function to take appmodule.Environment as a parameter aligns with the PR's objective of utilizing environment bundler services. Ensure that the Environment object is correctly utilized and that context handling is consistent.
  • 29-37: The change in the addExpiredGrantsIndex function to use appmodule.Environment and the update in context handling are consistent with the architectural enhancements. Verify the correct utilization of the Environment object and consistent context handling.
x/authz/keeper/genesis_test.go (1)
  • 50-50: Creating a new runtime.Environment object in the SetupTest function and passing it to the NewKeeper function aligns with the PR's objective of utilizing environment bundler services, even in test setups. Ensure that the Environment object is correctly initialized and passed.
x/authz/migrations/v2/store_test.go (1)
  • 108-108: Creating a new runtime.Environment object in the test setup and passing it to the v2.MigrateStore function aligns with the PR's objective of utilizing environment bundler services in test setups. Ensure that the Environment object is correctly initialized and passed.
x/authz/keeper/msg_server.go (1)
  • 120-123: Updating the PruneExpiredGrants function to use the EventService from the environment for event emission, with explicit error handling, aligns with the PR's objective of utilizing environment bundler services for event management. Ensure that the EventService is correctly accessed through the environment and that errors are appropriately handled.
x/authz/module/abci_test.go (1)
  • 35-35: Creating a new runtime.Environment object in the test setup and passing it to the NewKeeper function aligns with the PR's objective of utilizing environment bundler services in test setups. Ensure that the Environment object is correctly initialized and passed.
x/authz/keeper/grpc_query.go (3)
  • 61-61: The update to use runtime.KVStoreAdapter(k.environment.KVStoreService.OpenKVStore(ctx)) for accessing the KVStore service through the environment is a positive change, aligning with the PR's objective to integrate appmodule.Environment. This enhances modularity and maintainability by centralizing the interaction with the environment.
  • 103-103: Using runtime.KVStoreAdapter(k.environment.KVStoreService.OpenKVStore(ctx)) in the GranterGrants function is consistent with the overall goal of migrating to use the environment's services. This change ensures that the module's architecture is more cohesive and flexible.
  • 154-154: The modification in the GranteeGrants function to access the KVStore service via the environment (runtime.KVStoreAdapter(k.environment.KVStoreService.OpenKVStore(ctx))) is in line with the PR's architectural enhancements. It's a good practice to utilize the environment for such interactions, improving the module's integration with the Cosmos SDK's runtime environment.
x/authz/keeper/keeper.go (13)
  • 33-36: The integration of appmodule.Environment into the Keeper struct is a key architectural enhancement. This change allows the Keeper to interact more effectively with the Cosmos SDK's runtime environment, facilitating access to services like KVStore, logging, and event management through a unified interface.
  • 40-45: The NewKeeper function correctly initializes the Keeper with the appmodule.Environment, ensuring that all subsequent operations can leverage the environment's services. This is a crucial step in migrating the module to utilize environment bundler services.
  • 50-51: Accessing the logger via k.environment.Logger.With("module", fmt.Sprintf("x/%s", authz.ModuleName)) in the Logger method is a good practice. It ensures that logging is consistent and leverages the environment's centralized logging service.
  • 56-56: The getGrant method's adaptation to use the environment's KVStore service (k.environment.KVStoreService.OpenKVStore(ctx)) for accessing grants is in line with the PR's objectives. This change enhances the method's integration with the environment.
  • 88-88: The update method's use of the environment's KVStore service for setting grant data is a positive change, aligning with the architectural enhancements aimed at making the module more environment-aware.
  • 96-96: The DispatchActions method's modification to source the current time from the environment (k.environment.HeaderService.GetHeaderInfo(ctx).Time) is a notable improvement. It reflects a shift towards using the environment for time sourcing, which is a more flexible and cohesive approach.
  • 158-158: Converting the context to sdk.Context within DispatchActions (sdk.UnwrapSDKContext(ctx)) is a temporary measure. It's important to note the TODO comment about removing this conversion once the baseapp's MsgServiceRouter migrates to use context.Context. This highlights an area for future improvement and ensures backward compatibility in the meantime.
  • 167-174: Emitting events using the environment's event service in DispatchActions is a good practice. It demonstrates the method's integration with the environment and the shift towards a more modular and environment-aware design.
  • 187-187: The SaveGrant method's use of the environment's KVStore service for storing grants is consistent with the PR's goal of integrating appmodule.Environment. This change centralizes the interaction with the environment, enhancing modularity and maintainability.
  • 233-233: In the DeleteGrant method, accessing the KVStore service through the environment for deleting grants aligns with the architectural enhancements of the module. This is another example of the module's migration towards a more cohesive and flexible architecture.
  • 261-261: The GetAuthorizations method's adaptation to use the environment's KVStore service for retrieving authorizations is in line with the PR's objectives. This enhances the method's integration with the environment and its services.
  • 291-291: The GetAuthorization method's use of the environment for time sourcing (k.environment.HeaderService.GetHeaderInfo(ctx).Time) when checking for grant expiration is a positive change. It reflects a broader adoption of the environment across different aspects of the module.
  • 310-310: The IterateGrants method's use of the environment's KVStore service for iterating over grants demonstrates the module's shift towards a more environment-aware design. This is consistent with the PR's architectural enhancements.
x/authz/keeper/keeper_test.go (2)
  • 55-55: The introduction of runtime.NewEnvironment with storeService and log.NewNopLogger() as arguments is a significant change aligning with the PR's objectives. This encapsulates the environment setup within a single entity, enhancing modularity and maintainability. Ensure that the log.NewNopLogger() is appropriate for all test scenarios, as it might suppress valuable debugging information during test failures.
  • 78-78: The modification to pass the env object to authzkeeper.NewKeeper instead of storeService directly is a key part of integrating the environment bundler. This change centralizes the interaction with the environment, which is a positive step towards improving the module's architecture. However, ensure that all functionalities previously relying on storeService directly are fully compatible with the new env abstraction.
simapp/app.go (1)
  • 358-358: The modification to initialize AuthzKeeper using runtime.NewEnvironment instead of directly using runtime.NewKVStoreService aligns with the PR's objective of integrating the appmodule.Environment. This change enhances the modularity and maintainability of the x/authz module by centralizing the interaction with the environment. It's a positive step towards a more cohesive architecture within the Cosmos SDK, facilitating better interaction with the runtime environment. Ensure that corresponding updates are made wherever AuthzKeeper is utilized to maintain consistency across the module.

}

resp, err := authorization.Accept(sdkCtx, msg)
resp, err := authorization.Accept(ctx, msg)
Copy link
Contributor

@julienrbrt julienrbrt Feb 20, 2024

Choose a reason for hiding this comment

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

Now that we pass a context, we need to do like in the x/feegrant PR (break interface, or set environement in context). Otherwise, some authorization will fail at unwrapping the context: https://github.com/cosmos/cosmos-sdk//blob/833547f2aaa67382fbdbd171245760ffcf5765c1/x/staking/types/authz.go#L104

Copy link
Contributor

Choose a reason for hiding this comment

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

since we are using only time or height it might be safe. need to talk to @testinginprod

Copy link
Contributor

Choose a reason for hiding this comment

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

ill open an issue on this, we will solve before release but lets unblock this since its blocked on a team call

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

Commits Files that changed from the base of the PR and between 9d89ce8 and c5b146d.
Files selected for processing (1)
  • simapp/app.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • simapp/app.go

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

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between c5b146d and 45e75c4.
Files selected for processing (1)
  • x/authz/keeper/keeper.go (16 hunks)
Additional comments: 9
x/authz/keeper/keeper.go (9)
  • 33-36: The Keeper struct has been updated to include an appmodule.Environment field, replacing the previous direct usage of services like KVStoreService. This change centralizes the interaction with the Cosmos SDK's runtime environment, enhancing modularity and maintainability. Ensure that all instances and usages of the Keeper struct throughout the codebase are updated to accommodate this new field.
  • 50-51: The Logger method now accesses the logger from the appmodule.Environment, which is a positive change towards utilizing the environment's capabilities. This approach allows for more centralized logging management. Ensure that the logger obtained from the environment is correctly configured for the x/authz module.
  • 167-174: The DispatchActions method now handles events differently, utilizing the EventService from the appmodule.Environment. This change improves the flexibility and modularity of event management. However, ensure that the event names and attributes are consistent and meaningful for downstream consumers. Additionally, consider the performance implications of emitting events within a loop and verify that this does not introduce any significant overhead.
  • 183-193: > 📝 NOTE

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

The SaveGrant method has been updated to interact with the environment for event management, specifically using the EventService to emit events. This is a good practice as it leverages the environment's capabilities for a more cohesive architecture. However, ensure that the event structure and emitted information are comprehensive and useful for event consumers. Also, verify that the error handling for event emission is adequate.

  • 230-236: > 📝 NOTE

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

The DeleteGrant method's changes are consistent with the overall shift towards using the appmodule.Environment. The method now uses the KVStoreService and EventService from the environment. This enhances the method's integration with the broader Cosmos SDK environment. Ensure that the deletion logic is thoroughly tested, especially in scenarios involving concurrent access or failure cases.

  • 287-294: > 📝 NOTE

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

The GetAuthorizations and GetAuthorization methods have been updated to use the KVStoreService from the appmodule.Environment. This change aligns with the objective of centralizing environment interactions. However, it's important to ensure that the iteration and unmarshalling logic in GetAuthorizations is efficient and does not introduce unnecessary overhead, especially for large datasets.

  • 321-327: > 📝 NOTE

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

The IterateGrants and related methods (getGrantQueueItem, setGrantQueueItem) have been refactored to utilize the KVStoreService from the appmodule.Environment. This is a positive step towards a more environment-aware design. However, given the potential for significant I/O operations, as mentioned in the comment for IterateGrants, ensure that these methods are used judiciously and that appropriate gas costs are accounted for in transaction processing.

  • 381-388: > 📝 NOTE

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

The removeFromGrantQueue method now consumes gas for each iteration over the grant queue items, which is a good practice for accounting for the computational cost of operations. However, ensure that the gas cost per iteration (gasCostPerIteration) is calibrated correctly based on empirical data or benchmarks to prevent either overcharging or undercharging for the operation.

  • 406-408: The DequeueAndDeleteExpiredGrants method has been updated to use the KVStoreService from the appmodule.Environment for deleting expired grants. This method's changes are in line with the overall architectural shift. Ensure that the deletion logic, especially the iteration limit to avoid excessive processing time, is well-tested and that the method behaves correctly under various load conditions.

Copy link
Contributor

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

lgtm, ill open an issue on the interface stuff

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

Commits Files that changed from the base of the PR and between 45e75c4 and 06a380f.
Files selected for processing (1)
  • x/authz/keeper/msg_server.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/authz/keeper/msg_server.go

Copy link
Contributor

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

As per #19490 (comment), ACK.

@julienrbrt julienrbrt enabled auto-merge February 22, 2024 20:00
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.yml

Commits Files that changed from the base of the PR and between 06a380f and 433a6fc.
Files selected for processing (5)
  • simapp/app.go (1 hunks)
  • x/authz/keeper/genesis_test.go (2 hunks)
  • x/authz/keeper/keeper_test.go (2 hunks)
  • x/authz/migrations/v2/store_test.go (3 hunks)
  • x/authz/module/abci_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (5)
  • simapp/app.go
  • x/authz/keeper/genesis_test.go
  • x/authz/keeper/keeper_test.go
  • x/authz/migrations/v2/store_test.go
  • x/authz/module/abci_test.go

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

Commits Files that changed from the base of the PR and between 433a6fc and 83bd515.
Files selected for processing (1)
  • x/authz/keeper/keeper_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/authz/keeper/keeper_test.go

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