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

refactor(x/upgrade): migrate upgrade to env var #19443

Merged
merged 6 commits into from
Feb 15, 2024
Merged

Conversation

tac0turtle
Copy link
Member

@tac0turtle tac0turtle commented Feb 15, 2024

Description

ref #19290

migrate upgrade module to use env variabel


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
    • Enhanced the upgrade module to utilize appmodule.Environment for improved integration.
    • Optimized the Keeper structure for better context management and environmental interactions.
  • Chores
    • Aligned test cases with the updated Keeper structure and environmental parameters.
  • Documentation
    • Updated CHANGELOG to facilitate transparent tracking of modifications and enhancements.

Copy link
Contributor

coderabbitai bot commented Feb 15, 2024

Walkthrough

Walkthrough

The recent updates to the upgrade module bring significant architectural changes aimed at simplifying integration and enhancing modularity by introducing appmodule.Environment. This change centralizes service access through a unified environment object, replacing individual service injections. The update also modernizes context handling by transitioning to context.Context from sdk.Context, promoting standardization and improved codebase interoperability.

Changes

Files Change Summary
x/upgrade/CHANGELOG.md Introduces appmodule.Environment for module creation; NewKeeper now utilizes KVStoreService instead of StoreKey; methods in Keeper transition to context.Context.
x/upgrade/depinject.go Replaces store.KVStoreService with appmodule.Environment in ModuleInputs; updates parameter for keeper.NewKeeper.
x/upgrade/keeper/abci.go,
x/upgrade/keeper/abci_test.go,
x/upgrade/keeper/grpc_query_test.go,
x/upgrade/keeper/keeper.go,
x/upgrade/keeper/keeper_test.go,
x/upgrade/keeper/migrations.go
Renames package to keeper; adjusts PreBlocker method signature; updates NewKeeper and method implementations to use appmodule.Environment; modifies context and block height handling.
x/upgrade/module.go Modifies PreBlock method to directly call PreBlocker on keeper.

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.

@tac0turtle tac0turtle changed the title refactor(upgrade): migrate upgrade to env var refactor(x/upgrade): migrate upgrade to env var Feb 15, 2024
@tac0turtle tac0turtle marked this pull request as ready for review February 15, 2024 09:57
@tac0turtle tac0turtle requested a review from a team as a code owner February 15, 2024 09:57
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.

changes are needed in app.go

x/upgrade/CHANGELOG.md Outdated Show resolved Hide resolved
x/upgrade/depinject.go Outdated Show resolved Hide resolved
x/upgrade/keeper/abci.go Outdated Show resolved Hide resolved
x/upgrade/keeper/keeper.go Show resolved Hide resolved
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: 2

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between e46d526 and 0d5a00e.
Files selected for processing (9)
  • x/upgrade/CHANGELOG.md (2 hunks)
  • x/upgrade/depinject.go (3 hunks)
  • x/upgrade/keeper/abci.go (3 hunks)
  • x/upgrade/keeper/abci_test.go (7 hunks)
  • x/upgrade/keeper/grpc_query_test.go (2 hunks)
  • x/upgrade/keeper/keeper.go (16 hunks)
  • x/upgrade/keeper/keeper_test.go (3 hunks)
  • x/upgrade/keeper/migrations.go (2 hunks)
  • x/upgrade/module.go (1 hunks)
Additional comments: 36
x/upgrade/depinject.go (1)
  • 39-39: LGTM! The integration of appmodule.Environment in ModuleInputs aligns with the PR's objectives for enhanced configuration flexibility.
x/upgrade/keeper/migrations.go (2)
  • 32-32: LGTM! Accessing KVStoreService through environment in Migrate1to2 aligns with the refactor objectives.
  • 69-69: LGTM! Using environment to access KVStoreService in migrateAppVersion is consistent with the PR's goals.
x/upgrade/CHANGELOG.md (1)
  • 34-34: LGTM! The documentation accurately reflects the integration of appmodule.Environment and its implications.
x/upgrade/keeper/abci.go (1)
  • 28-28: LGTM! Using k.environment.HeaderService.GetHeaderInfo(ctx).Height for block height access aligns with the refactor objectives.
x/upgrade/module.go (1)
  • 155-155: LGTM! Simplifying the PreBlock method call to use PreBlocker directly on the keeper field enhances readability and maintainability.
x/upgrade/keeper/grpc_query_test.go (2)
  • 41-41: LGTM! Initializing env with runtime.NewEnvironment and log.NewNopLogger() aligns with the refactor objectives.
  • 49-49: LGTM! Updating the keeper.NewKeeper call to include env as the first argument is consistent with the PR's goals.
x/upgrade/keeper/keeper_test.go (4)
  • 49-49: LGTM! Initializing env with runtime.NewEnvironment and log.NewNopLogger() in SetupTest aligns with the refactor objectives.
  • 72-72: LGTM! Updating the keeper.NewKeeper call in SetupTest to include env as the first argument is consistent with the PR's goals.
  • 256-257: LGTM! Initializing env with runtime.NewEnvironment and log.NewNopLogger() in TestIsSkipHeight aligns with the refactor objectives.
  • 257-257: LGTM! Updating the keeper.NewKeeper call in TestIsSkipHeight to include env as the first argument is consistent with the PR's goals.
x/upgrade/keeper/keeper.go (19)
  • 34-36: The addition of the environment field in the Keeper struct aligns with the objective of utilizing environment variables for configuration flexibility.
  • 51-55: The NewKeeper function correctly accepts an appmodule.Environment parameter and initializes the environment field in the Keeper struct.
  • 91-91: The use of runtime.KVStoreAdapter to adapt the KVStoreService from the environment for setting module version maps is appropriate and follows the intended design changes.
  • 118-118: Accessing the key-value store service through the environment for getting the module version map is correctly implemented.
  • 140-140: The method GetModuleVersions correctly utilizes the environment to access the key-value store service for fetching module versions.
  • 165-165: The method getModuleVersion properly uses the environment to access the key-value store service for retrieving a specific module version.
  • 195-195: In ScheduleUpgrade, the use of environment.HeaderService.GetHeaderInfo to get the current block height for validation is correctly implemented.
  • 208-208: Utilizing the environment to open a key-value store in ScheduleUpgrade for storing the upgrade plan is correctly done.
  • 241-241: The method SetUpgradedClient correctly uses the environment to access the key-value store for setting the upgraded client.
  • 248-248: The method GetUpgradedClient properly uses the environment to access the key-value store for retrieving the upgraded client.
  • 264-264: The method SetUpgradedConsensusState correctly uses the environment to access the key-value store for setting the upgraded consensus state.
  • 271-271: The method GetUpgradedConsensusState properly uses the environment to access the key-value store for retrieving the upgraded consensus state.
  • 286-286: The method GetLastCompletedUpgrade correctly uses the environment to access the key-value store for retrieving the last completed upgrade information.
  • 321-321: The method GetDoneHeight properly uses the environment to access the key-value store for retrieving the height at which a given upgrade was executed.
  • 342-342: The method ClearIBCState correctly uses the environment to access the key-value store for clearing any planned IBC state.
  • 368-368: The method ClearUpgradePlan correctly uses the environment to access the key-value store for clearing any scheduled upgrade plan.
  • 374-374: The method Logger correctly utilizes the environment to obtain a module-specific logger.
  • 380-380: The method GetUpgradePlan properly uses the environment to access the key-value store for retrieving the currently scheduled upgrade plan.
  • 400-400: The method setDone correctly uses the environment to access the key-value store for marking an upgrade as done.
x/upgrade/keeper/abci_test.go (5)
  • 117-117: The introduction of the env parameter in the setupTest function correctly reflects the changes made to the keeper structure, ensuring the test setup aligns with the new design.
  • 132-132: The NewKeeper function call within the setupTest function correctly includes the env parameter, aligning with the modifications made to the keeper structure.
  • 464-464: The introduction of the env parameter in the TestDowngradeVerification function correctly reflects the changes made to the keeper structure, ensuring the test setup aligns with the new design.
  • 473-473: The NewKeeper function call within the TestDowngradeVerification function correctly includes the env parameter, aligning with the modifications made to the keeper structure.
  • 522-522: The NewKeeper function call within the TestDowngradeVerification function, for the downgrade scenario, correctly includes the env parameter, aligning with the modifications made to the keeper structure.

x/upgrade/depinject.go Outdated Show resolved Hide resolved
x/upgrade/keeper/abci.go Show resolved Hide resolved
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 0d5a00e and 060032d.
Files selected for processing (1)
  • x/upgrade/depinject.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/upgrade/depinject.go

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! but simapp/app.go should still be updated with the new api.

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.

same as julien's comment, otherwise lgtm

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 060032d and 8dec44a.
Files selected for processing (1)
  • simapp/app.go (1 hunks)
Files not reviewed due to errors (1)
  • (no review received)

@tac0turtle tac0turtle added this pull request to the merge queue Feb 15, 2024
Merged via the queue into main with commit 509eec6 Feb 15, 2024
60 of 62 checks passed
@tac0turtle tac0turtle deleted the marko/upgrade_env branch February 15, 2024 16:30
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