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(runtime): Audit runtime changes #21309

Merged
merged 14 commits into from
Aug 27, 2024
Merged

refactor(runtime): Audit runtime changes #21309

merged 14 commits into from
Aug 27, 2024

Conversation

sontrinh16
Copy link
Member

@sontrinh16 sontrinh16 commented Aug 15, 2024

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

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

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced new services for branch management, header handling, and comet integration.
    • Added LastCommitID method to the Store interface for retrieving the latest commit ID.
  • Bug Fixes

    • Improved error handling in the coreKVStore methods to panic on invalid inputs instead of returning errors.
  • Documentation

    • Enhanced comments for several functions to improve clarity and understanding.
    • Updated error messages for better specificity in certain methods.
    • Added detailed documentation for migration functions to assist developers.
  • Chores

    • Organized CHANGELOG.md to document recent updates and changes.

Copy link
Contributor

coderabbitai bot commented Aug 15, 2024

Walkthrough

Walkthrough

The recent changes to the Cosmos SDK primarily enhance the functionality and documentation of the runtime module. Key updates include new service implementations, adjustments in message handling, improvements in error management, and clarified documentation. These enhancements reflect ongoing development efforts within the SDK.

Changes

File Change Summary
CHANGELOG.md Added entries for core.branch.Service, core/header.Service, core/comet.Service.
core/appmodule/v2/handlers.go Updated PostMsgRouter interface to use PostMsgHandler; added HasPostMsgHandlers interface.
runtime/environment.go, runtime/router.go Minor comments updated for clarity; no functional changes.
runtime/store.go Changed error handling in coreKVStore methods to panic on nil inputs.
runtime/v2/app.go Removed GetLogger method from App struct.
runtime/v2/builder.go Clarified error message in Build method regarding store options unmarshalling.
runtime/v2/manager.go Updated type assertions, enhanced documentation for RunMigrations, and improved error messages.
runtime/v2/migrations.go Minor comment correction in newMigrationRegistrar function.
runtime/v2/store.go Updated comment for StateAt method; added LastCommitID method to interface.
runtime/v2/types.go Changed ValidateProtoAnnotations to a private function.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@julienrbrt julienrbrt mentioned this pull request Aug 15, 2024
28 tasks
@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Aug 16, 2024
@sontrinh16 sontrinh16 marked this pull request as ready for review August 19, 2024 05:42
@sontrinh16 sontrinh16 requested a review from a team as a code owner August 19, 2024 05:42
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (2)
core/appmodule/v2/handlers.go (1)

50-51: No Implementations of HasPostMsgHandlers Found

The HasPostMsgHandlers interface is defined, but no types currently implement it. Ensure that relevant types implement this interface and register their handlers as intended.

  • File: core/appmodule/v2/handlers.go
  • Lines: 50-51
Analysis chain

Review the Addition of HasPostMsgHandlers Interface.

The new HasPostMsgHandlers interface requires implementing types to register post-message handlers. Ensure that all relevant types implement this interface and register their handlers appropriately.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all relevant types implement the `HasPostMsgHandlers` interface.

# Test: Search for the interface implementation. Expect: Relevant types implementing the interface.
rg --type go -A 5 'HasPostMsgHandlers'

Length of output: 322


Script:

#!/bin/bash
# Search for types implementing the `RegisterPostMsgHandlers` method to identify implementations of the `HasPostMsgHandlers` interface.
rg --type go 'RegisterPostMsgHandlers'

Length of output: 115

runtime/store.go (1)

91-91: Ensure Proper Handling of Nil Keys in Delete Method

The Delete method in coreKVStore does not perform a nil check before invoking store.kvStore.Delete(key). The immediate caller, kvStoreAdapter, also lacks such validation. This could lead to unintended panics if a nil key is passed. Please verify that this behavior aligns with the intended error handling strategy.

  • File: runtime/store.go
  • Method: coreKVStore.Delete
Analysis chain

Review Change to Panic on Nil Key in Delete Method.

The Delete method now panics on a nil key instead of returning an error. Ensure that this change is intentional and that any potential issues are mitigated through proper input validation.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the change to panic on nil key in `Delete` method.

# Test: Search for the `Delete` method usage. Expect: Proper input validation before calling.
rg --type go -A 5 'Delete' runtime/store.go

Length of output: 436


Script:

#!/bin/bash
# Search for all usages of the `Delete` method in the codebase to check for input validation.
rg --type go 'Delete(' -A 3

Length of output: 94


Script:

#!/bin/bash
# Corrected search for all usages of the `Delete` method in the codebase to check for input validation.
rg --type go 'Delete\(' -A 3

Length of output: 65748

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cd92990 and 3930f15.

Files selected for processing (11)
  • CHANGELOG.md (1 hunks)
  • core/appmodule/v2/handlers.go (1 hunks)
  • runtime/environment.go (3 hunks)
  • runtime/router.go (4 hunks)
  • runtime/store.go (1 hunks)
  • runtime/v2/app.go (1 hunks)
  • runtime/v2/builder.go (1 hunks)
  • runtime/v2/manager.go (4 hunks)
  • runtime/v2/migrations.go (1 hunks)
  • runtime/v2/store.go (2 hunks)
  • runtime/v2/types.go (1 hunks)
Files skipped from review due to trivial changes (5)
  • runtime/environment.go
  • runtime/router.go
  • runtime/v2/builder.go
  • runtime/v2/migrations.go
  • runtime/v2/types.go
Additional context used
Path-based instructions (6)
core/appmodule/v2/handlers.go (1)

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

runtime/v2/store.go (1)

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

runtime/v2/app.go (1)

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

runtime/store.go (1)

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

runtime/v2/manager.go (1)

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

CHANGELOG.md (1)

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

Additional comments not posted (13)
core/appmodule/v2/handlers.go (1)

47-48: Ensure Consistency in Handler Naming.

The change from PreMsgHandler to PostMsgHandler in the RegisterGlobal method of the PostMsgRouter interface is consistent with the interface's purpose. Ensure that all implementations and usages of this interface are updated accordingly to prevent runtime errors.

runtime/v2/store.go (2)

26-26: Comment Update for Clarity.

The comment for the StateAt method now specifies that it must error when the "version" does not exist, which improves clarity. Ensure that the implementation adheres to this requirement.


55-55: Review the Addition of LastCommitID Method.

The new LastCommitID method provides the latest commit ID. Ensure that this method is implemented correctly in all relevant store types and is used where necessary.

runtime/store.go (3)

80-80: Review Change to Panic on Nil Key in Has Method.

The Has method now panics on a nil key instead of returning an error. Ensure that this change is intentional and that any potential issues are mitigated through proper input validation.


85-85: Review Change to Panic on Nil Key or Value in Set Method.

The Set method now panics on a nil key or value instead of returning an error. Ensure that this change is intentional and that any potential issues are mitigated through proper input validation.


75-75: Review Change to Panic on Nil Key in Get Method.

The Get method now panics on a nil key instead of returning an error. Ensure that this change is intentional and that any potential issues are mitigated through proper input validation.

runtime/v2/manager.go (4)

359-407: Enhanced Documentation for RunMigrations.

The documentation for RunMigrations has been significantly enhanced, providing clear guidance on its usage and behavior. Ensure that the documentation is accurate and aligns with the function's implementation.


446-446: Clarify Error Message in RunMigrations.

The error message now specifies that a validator InitGenesis update cannot be set by a new module. This clarification helps prevent confusion during migrations. Ensure that the error handling logic is implemented correctly.


485-486: Variable Name Change in validateConfig.

The variable hasBlock has been renamed to hasPreBlock for improved clarity. Ensure that this change is reflected throughout the function and that the logic remains correct.


219-219: Review Type Assertion Change in ExportGenesisForModules.

The type assertion has been updated from appmodulev2.HasGenesis to appmodulev2.HasABCIGenesis. Ensure that this change aligns with the intended functionality and that all relevant modules implement the correct interface.

Verification successful

Type Assertion Change Verified Successfully

The change from HasGenesis to HasABCIGenesis in the ExportGenesisForModules function aligns with the intended functionality. Multiple modules implement the HasABCIGenesis interface, supporting the shift towards handling more complex genesis operations. No issues were found with this update.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the type assertion change in `ExportGenesisForModules`.

# Test: Search for modules implementing `HasABCIGenesis`. Expect: Relevant modules implementing the interface.
rg --type go -A 5 'HasABCIGenesis'

Length of output: 8220

CHANGELOG.md (3)

78-78: Entry for core.branch.Service looks good.

The entry is clear, concise, and correctly formatted.


79-79: Entry for core/header.Service looks good.

The entry is clear, concise, and correctly formatted.


80-80: Entry for core/comet.Service looks good.

The entry is clear, concise, and correctly formatted.

core/appmodule/v2/handlers.go Outdated Show resolved Hide resolved
runtime/v2/manager.go Show resolved Hide resolved
runtime/v2/manager.go Outdated 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.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3930f15 and 2e44826.

Files selected for processing (1)
  • runtime/v2/manager.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • runtime/v2/manager.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.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2e44826 and 3644ba1.

Files selected for processing (1)
  • runtime/v2/manager.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • runtime/v2/manager.go

//
// Example:
//
// app.UpgradeKeeper.SetUpgradeHandler("my-plan", func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
Copy link
Member

Choose a reason for hiding this comment

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

not accurate

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.

ACK

@julienrbrt
Copy link
Member

Can be partially backported, we can remove runtime/v2 in the backport.

@julienrbrt
Copy link
Member

julienrbrt commented Aug 27, 2024

@sontrinh16 could you fix the conflicts? done for you

@julienrbrt julienrbrt added this pull request to the merge queue Aug 27, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3644ba1 and 5f8a9be.

Files selected for processing (4)
  • runtime/router.go (2 hunks)
  • runtime/v2/app.go (1 hunks)
  • runtime/v2/builder.go (1 hunks)
  • runtime/v2/manager.go (3 hunks)
Files skipped from review due to trivial changes (2)
  • runtime/router.go
  • runtime/v2/builder.go
Additional context used
Path-based instructions (2)
runtime/v2/app.go (1)

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

runtime/v2/manager.go (1)

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

Additional comments not posted (4)
runtime/v2/app.go (1)

Line range hint 1-1: Verify the impact of removing GetLogger method.

The removal of the GetLogger method indicates a change in how logging is handled. Ensure that all code relying on this method is updated accordingly.

Run the following script to verify the usage of the GetLogger method:

runtime/v2/manager.go (3)

360-407: LGTM!

The comprehensive documentation enhances the understanding of the migration process for developers.

The code changes are approved.


494-495: LGTM!

The variable renaming improves code readability without altering the underlying logic.

The code changes are approved.


220-220: Verify the impact of the type assertion change.

The type assertion change from appmodulev2.HasGenesis to appmodulev2.HasABCIGenesis indicates a shift in the expected interface for certain modules. Ensure that all modules implement the correct interface.

Run the following script to verify the implementation of the HasABCIGenesis interface:

Verification successful

Verification Successful: Modules Implement the HasABCIGenesis Interface

The type assertion change to appmodulev2.HasABCIGenesis is consistent with the codebase. The interface is implemented by relevant modules, ensuring compatibility with the updated assertion.

  • Modules like x/staking/module.go and x/genutil/module.go implement the HasABCIGenesis interface.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all modules implement the `HasABCIGenesis` interface.

# Test: Search for the interface implementation. Expect: All relevant modules implement the interface.
rg --type go $'HasABCIGenesis'

Length of output: 2171

Merged via the queue into main with commit f0c0e81 Aug 27, 2024
75 checks passed
@julienrbrt julienrbrt deleted the son/runtime_audit branch August 27, 2024 12:56
mergify bot pushed a commit that referenced this pull request Aug 27, 2024
Co-authored-by: Julien Robert <julien@rbrt.fr>
(cherry picked from commit f0c0e81)

# Conflicts:
#	runtime/v2/app.go
#	runtime/v2/builder.go
#	runtime/v2/manager.go
#	runtime/v2/migrations.go
#	runtime/v2/store.go
#	runtime/v2/types.go
julienrbrt added a commit that referenced this pull request Aug 27, 2024
Co-authored-by: son trinh <trinhleson2000@gmail.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants