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/v2): rm singleton storebuilder scope #22204

Closed
wants to merge 2 commits into from

Conversation

kocubinski
Copy link
Member

@kocubinski kocubinski commented Oct 9, 2024

Description

A singleton was not a great idea.


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

    • Enhanced flexibility and modularity in store management.
  • Refactor

    • Removed singleton store builder implementation to simplify store management.
    • Updated functions and parameters to support a more modular approach.

Copy link
Contributor

coderabbitai bot commented Oct 9, 2024

📝 Walkthrough

Walkthrough

The pull request introduces a significant refactoring of the store management logic in the application. Key changes include the removal of the singleton store builder pattern, updates to the NewSimApp function to accept a storeBuilder parameter, and modifications across various files to reflect a more modular approach to store management. This refactoring enhances flexibility in how the application manages its store.

Changes

File Path Change Summary
runtime/v2/store.go Removed singleton store builder implementation, including related variables and functions.
simapp/v2/app_di.go Updated NewSimApp to require a storeBuilder parameter; modified AppConfig to remove singleton builder.
simapp/v2/app_test.go Adjusted NewTestApp to pass root.NewBuilder(); updated import statements for modular store management.
simapp/v2/simdv2/cmd/commands.go Replaced newApp with appCreator, now including storeBuilder parameter; updated appExport function.
simapp/v2/simdv2/cmd/root_di.go Updated initialization of storeBuilder to use root.NewBuilder(), supplied to depinject.Supply.

Possibly related PRs

Suggested labels

C:Store, C:server/v2, C:server/v2 cometbft, backport/v0.52.x

Suggested reviewers

  • hieuvubk
  • julienrbrt
  • cool-develope
  • tac0turtle

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

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

🧹 Outside diff range and nitpick comments (3)
simapp/v2/app_test.go (2)

43-43: Approve change, but suggest additional test coverage

The modification to use root.NewBuilder() in the NewSimApp call aligns with the PR's goal of removing the singleton storebuilder pattern. This change enhances flexibility in store management for tests.

However, to ensure robustness:

Consider adding a specific test case that verifies the behavior of the new storebuilder implementation. This would increase confidence in the refactoring and improve overall test coverage.


Line range hint 1-165: Enhance test coverage for refactored storebuilder behavior

While the existing tests cover basic app initialization and state export, they don't explicitly verify the new non-singleton storebuilder behavior introduced by this refactoring.

To improve test coverage and ensure the refactoring achieves its goals:

  1. Add a test case that creates multiple SimApp instances and verifies they have independent stores.
  2. Include a test that checks the behavior of the new root.NewBuilder() implementation, ensuring it properly initializes and manages the store.

These additions would provide more comprehensive coverage of the changes introduced in this PR.

simapp/v2/app_di.go (1)

94-94: LGTM: storeBuilder correctly supplied to dependency injection.

The addition of storeBuilder to the depinject.Supply call within the appConfig declaration ensures that the new parameter is properly supplied to the dependency injection configuration. This change is consistent with the removal of the singleton storebuilder scope and allows for more flexible store management.

Consider adding a blank line after the storeBuilder entry for better readability:

 storeBuilder,
+
 // ADVANCED CONFIGURATION
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 864e9f1 and 390d97f.

📒 Files selected for processing (5)
  • runtime/v2/store.go (0 hunks)
  • simapp/v2/app_di.go (1 hunks)
  • simapp/v2/app_test.go (2 hunks)
  • simapp/v2/simdv2/cmd/commands.go (2 hunks)
  • simapp/v2/simdv2/cmd/root_di.go (1 hunks)
💤 Files with no reviewable changes (1)
  • runtime/v2/store.go
🧰 Additional context used
📓 Path-based instructions (4)
simapp/v2/app_di.go (1)

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

simapp/v2/app_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

simapp/v2/simdv2/cmd/commands.go (1)

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

simapp/v2/simdv2/cmd/root_di.go (1)

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

🔇 Additional comments (6)
simapp/v2/simdv2/cmd/root_di.go (2)

35-35: Approved: Explicit initialization of storeBuilder

The change from a zero-value initialization to an explicit initialization with root.NewBuilder() is a positive improvement. This aligns with the PR objective of removing the singleton pattern and enhances code clarity. It also adheres to the Uber Golang style guide by avoiding global state.


42-42: Approved: Supply storeBuilder to dependency injection

The modification to include storeBuilder in the depinject.Supply call is consistent with its initialization. This change ensures that the storeBuilder is properly supplied to the dependency injection system, which is crucial for the refactoring away from the singleton pattern. The code structure remains clean and adheres to the Golang style guidelines.

simapp/v2/app_test.go (1)

24-24: LGTM: Import changes align with refactoring goals

The addition of "cosmossdk.io/store/v2/root" and removal of "cosmossdk.io/runtime/v2" align with the PR's objective of refactoring the storebuilder scope. The import statement follows the Uber Go Style Guide for grouping and ordering.

simapp/v2/app_di.go (1)

84-86: LGTM: Variable declarations adjusted appropriately.

The modifications to the variable declarations for app, appBuilder, and err are appropriate adjustments to accommodate the new storeBuilder parameter. These changes maintain the overall structure and purpose of the function.

simapp/v2/simdv2/cmd/commands.go (2)

69-72: Introduction of appCreator Function Enhances Modularity

The new appCreator function encapsulates the app creation logic, improving code modularity and readability. Passing the storeBuilder ensures consistent store configuration throughout the application.


77-77: Consistent Application Initialization in Command Setup

Using appCreator in serverv2.AddCommands ensures consistent application initialization across commands, enhancing maintainability and reducing potential initialization discrepancies.

@@ -79,19 +78,20 @@ func AppConfig() depinject.Config {
func NewSimApp[T transaction.Tx](
logger log.Logger,
viper *viper.Viper,
storeBuilder root.Builder,
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Action Required: NewSimApp calls missing storeBuilder parameter.

Several instances of NewSimApp function calls are missing the new storeBuilder parameter, which may lead to inconsistent store configurations across the application. Please update the following files to include the storeBuilder parameter:

  • tests/integration/store/rootmulti/rollback_test.go
  • tests/e2e/genutil/export_test.go
  • simapp/sim_test.go
  • simapp/test_helpers.go
  • simapp/simd/cmd/commands.go
  • simapp/app_di.go
  • simapp/app.go
🔗 Analysis chain

LGTM: Addition of storeBuilder parameter enhances flexibility.

The addition of the storeBuilder parameter to the NewSimApp function signature aligns with the PR objective of removing the singleton storebuilder scope. This change allows for more flexibility in how the store is built and passed to the application.

To ensure this change is consistently applied, please run the following script to check for any occurrences of NewSimApp that might need updating:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all occurrences of NewSimApp function calls in the codebase
# Expect: All occurrences should have the new storeBuilder parameter

rg --type go -A 5 'NewSimApp\s*\('

Length of output: 7126

julienrbrt
julienrbrt previously approved these changes Oct 9, 2024
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 as quick fix for unblocking Strangelove, but as said on Slack, I would rather see a better client/server split again.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Oct 9, 2024
@julienrbrt
Copy link
Member

Adding backport label as it touches simapp

Copy link
Member

Choose a reason for hiding this comment

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

Here storeBuilder is injected and supplied. We should remove the inject one.

@julienrbrt
Copy link
Member

I think we can close this one, as #22205 got 3 approvals in this one none.

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.

3 participants