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): use AppI.GetStore() to fetch an initialized RootStore #22205

Merged
merged 10 commits into from
Oct 10, 2024

Conversation

kocubinski
Copy link
Member

@kocubinski kocubinski commented Oct 9, 2024

Description

Alternative to: #22204


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

  • Refactor

    • Simplified store management by removing the singleton store builder pattern.
    • Streamlined command initialization processes for improved readability and efficiency.
    • Enhanced the application interface for easier store access.
  • General Cleanup

    • Removed unused variables and import statements for a cleaner codebase.
    • Improved error messaging for better clarity during configuration unmarshalling.

Copy link
Contributor

coderabbitai bot commented Oct 9, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve a significant refactoring of store management and command initialization processes within the application. Key modifications include the removal of the singleton store builder pattern, updates to directly access the store from the application interface, streamlined command initialization functions, enhancements to the AppI interface, and general code cleanup.

Changes

File Path Change Summary
runtime/v2/module.go, runtime/v2/store.go Removed singleton store builder pattern, including related variables and functions. Added storeBuilder variable in DefaultServiceBindings.
server/v2/cometbft/server.go, server/v2/store/server.go, server/v2/types.go Updated initialization logic to directly obtain the store. Removed storeBuilder parameter from various functions and updated method signatures. Added GetStore() method to AppI interface.
simapp/v2/app_di.go, simapp/v2/app_test.go, simapp/v2/simdv2/cmd/commands.go, simapp/v2/simdv2/cmd/root_di.go, simapp/v2/simdv2/cmd/testnet.go Streamlined command initialization by removing storeBuilder from function signatures and updated related function calls. Cleaned up variable declarations.

Possibly related PRs

Suggested reviewers

  • hieuvubk
  • julienrbrt
  • 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.

@github-actions github-actions bot added C:server/v2 Issues related to server/v2 C:server/v2 cometbft labels 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.

This one looks great 🙏

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 and nitpick comments (5)
server/v2/types.go (1)

21-21: LGTM: New method added to AppI interface.

The new GetStore() method is a good addition to the AppI interface, providing access to the root store. This aligns well with the PR objectives.

Consider adding a comment to document the purpose of this method, for example:

// GetStore returns the initialized RootStore for the application.
GetStore() store.RootStore
simapp/v2/app_di.go (2)

Line range hint 86-156: LGTM: Improved documentation for customization options

The added comments provide clear guidance on how to customize various aspects of the application, such as account types and address codecs. This improvement in documentation will be beneficial for developers working with the codebase.

Consider adding a brief comment at the beginning of this section to indicate that these are advanced configuration options. For example:

// ADVANCED CONFIGURATION
//
// The following section provides options for customizing various aspects of the application.
// Most users won't need to modify these settings.

This would help set expectations for users reading through the configuration options.


Line range hint 170-173: LGTM: Improved store initialization with error handling

The use of storeBuilder.Build for store initialization and the addition of error handling are good improvements. This change enhances the robustness of the application initialization process.

Consider using a more descriptive error message when panicking. For example:

if err != nil {
    panic(fmt.Errorf("failed to build store: %w", err))
}

This would provide more context in case of a panic, making it easier to diagnose issues.

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

Line range hint 90-101: LGTM! Consider updating the function documentation.

The removal of the sb root.Builder parameter simplifies the function signature and is consistent with the overall changes. The core functionality remains intact.

Consider updating the function's documentation to reflect the removal of the sb parameter:

- // NewTestnetCmd creates a root testnet command with subcommands to run an in-process testnet or initialize
- // validator configuration files for running a multi-validator testnet in a separate process
+ // NewTestnetCmd creates a root testnet command with subcommands to initialize
+ // validator configuration files for running a multi-validator testnet in a separate process

Line range hint 1-524: Overall refactoring looks good. Consistent removal of root.Builder dependency.

The changes in this file are part of a larger refactoring effort to remove the dependency on root.Builder. The modifications are consistent across all affected functions, and the core logic remains intact. This refactoring simplifies the code and potentially reduces coupling.

Consider updating any related documentation or README files to reflect these changes, especially if they mention the usage of root.Builder in the context of testnet initialization.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c39ec6f and 53d003f.

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

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

server/v2/cometbft/server.go (1)

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

server/v2/store/server.go (1)

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

server/v2/types.go (1)

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

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

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

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

🔇 Additional comments (15)
server/v2/types.go (1)

11-11: LGTM: New import added correctly.

The new import for the store package is correctly formatted and necessary for the interface changes.

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

73-73: LGTM! Verify initRootCmd implementation.

The removal of the storeBuilder parameter from the initRootCmd function call aligns with the PR objectives of refactoring to use AppI.GetStore(). This change simplifies the function call and potentially improves code maintainability.

To ensure consistency, please verify that the initRootCmd function implementation has been updated to match this new signature. Run the following script to check the function definition:

✅ Verification successful

initRootCmd signature verified and matches the changes.

The initRootCmd function in simapp/v2/simdv2/cmd/commands.go has been updated to include the txConfig parameter, aligning with the changes in root_di.go. This ensures consistency and maintains the integrity of the command initialization.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the initRootCmd function signature

# Test: Search for the initRootCmd function definition
rg --type go -A 5 $'func initRootCmd'

Length of output: 671

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

Line range hint 1-231: Overall changes and testing recommendation

The changes in this file are consistent with the PR objective of refactoring to use AppI.GetStore(). The storeBuilder parameter has been removed from multiple function calls, and the import for the root package has been removed. These changes suggest a significant shift in how the store is initialized and accessed throughout the application.

While the changes look good, I recommend:

  1. Thoroughly testing the affected functionality, especially the command initialization and execution processes.
  2. Updating any documentation that might reference the old storeBuilder pattern.
  3. Verifying that all parts of the codebase that previously relied on the storeBuilder have been appropriately updated.
#!/bin/bash
# Description: Check for any remaining uses of storeBuilder in the codebase
# Expected: No occurrences of storeBuilder in function signatures or calls

rg --type go 'storeBuilder'

84-85: Verify changes in serverstore.New function

The storeBuilder parameter has been removed from the serverstore.New[T]() function call. This change is consistent with the PR objective of removing the singleton store builder pattern. However, we should verify that:

  1. The serverstore.New function has been updated to handle this change.
  2. The store initialization is now handled correctly within the function or elsewhere in the application.
#!/bin/bash
# Description: Check the implementation of serverstore.New function
# Expected: The function should no longer accept a storeBuilder parameter

rg --type go -A 10 'func New\[T'

55-55: Verify changes in NewTestnetCmd function

The storeBuilder parameter has been removed from the NewTestnetCmd function call. This change aligns with the PR objective of refactoring to use AppI.GetStore(). However, we should verify that the NewTestnetCmd function has been updated accordingly to handle this change.

✅ Verification successful

NewTestnetCmd function correctly updated

The NewTestnetCmd function signatures in both simapp/v2/simdv2/cmd/testnet.go and simapp/simd/cmd/testnet.go no longer include the storeBuilder parameter, aligning with the removal in the function call.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the implementation of NewTestnetCmd function
# Expected: The function should no longer use storeBuilder

rg --type go -A 10 'func NewTestnetCmd'

Length of output: 3464


Script:

#!/bin/bash
# Description: Check the implementation of NewTestnetCmd function using ast-grep
# Expected: The function should no longer use storeBuilder

ast-grep --lang go --pattern 'func NewTestnetCmd' .

Length of output: 398


Script:

#!/bin/bash
# Description: Search for functions starting with NewTestnet in the Go codebase
# Expected: Identify if the function has been renamed or moved

rg --type go 'func NewTestnet\w*' .

Length of output: 231

simapp/v2/app_di.go (1)

86-86: LGTM: Explicit declaration of storeBuilder

The explicit declaration of storeBuilder improves code clarity and aligns with the Uber Golang style guide. This change makes the variable's scope and purpose more evident.

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

Line range hint 105-146: LGTM! Changes are consistent and maintain functionality.

The removal of the sb root.Builder parameter from the function signature and the initTestnetFiles call is consistent with the overall refactoring. The function's core logic and the command's description remain intact and accurate.


Line range hint 345-351: LGTM! Verify compatibility with updated store.New[T]() function.

The removal of the sb root.Builder parameter and the update to store.New[T]() are consistent with the overall refactoring. The function's core logic remains intact.

Ensure that the store.New[T]() function is compatible with this change by checking its implementation:

✅ Verification successful

Compatibility Verified! The store.New[T]() function no longer requires any parameters, aligning with the recent changes. No issues found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the signature of store.New[T]() function
# Expected: The function should not require any parameters

rg --type go 'func New\[T' -A 3

Length of output: 1401

server/v2/store/server.go (3)

30-31: Simplified New function by removing the builder parameter

The New function has been refactored to remove the unnecessary builder parameter, which simplifies the server initialization and aligns with the refactoring goals.


34-35: Updated Init method to use app.GetStore()

The Init method now initializes s.backend directly using app.GetStore(). The parameters that are not used are appropriately named with underscores, following Go conventions.


83-83: Improved error message clarity in UnmarshalConfig

The error message now specifies "failed to unmarshal store config," providing clearer context for debugging purposes.

runtime/v2/module.go (3)

232-232: Update Comment to Include New Service

The addition of // - store/v2/root.Builder in the comment correctly reflects the inclusion of the storeBuilder in the default service bindings.


248-248: Initialize storeBuilder for Dependency Injection

Initializing storeBuilder with root.NewBuilder() properly sets up the store builder for use in dependency injection.


255-255: Supply storeBuilder in Dependency Injection

Including storeBuilder in the depinject.Supply() call ensures that the store builder is supplied to the dependency injection container, making it available where needed.

server/v2/cometbft/server.go (1)

104-104: Ensure all references to s.storeBuilder are removed

Since storeBuilder has been removed from CometBFTServer, please verify that there are no remaining references to s.storeBuilder in the codebase to prevent compilation errors.

Run the following script to confirm that s.storeBuilder is no longer used:

✅ Verification successful

Verification Successful: No references to s.storeBuilder remain in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for 's.storeBuilder' in Go files to ensure it's no longer referenced.

# Test: Search for occurrences of 's.storeBuilder'. Expect: No matches.
rg 's\.storeBuilder' --type go

Length of output: 32


Script:

#!/bin/bash
# Description: Comprehensive search for 's.storeBuilder' in Go files to ensure it's fully removed.

# Search recursively with case-insensitive matching and include hidden directories
rg -i 's\.storeBuilder' --type go --hidden

Length of output: 105

}

func (s *Server[T]) Init(app serverv2.AppI[T], _ map[string]any, _ log.Logger) error {
s.backend = app.GetStore()
Copy link
Member

Choose a reason for hiding this comment

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

init should still set the config.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Oct 10, 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

🧹 Outside diff range and nitpick comments (1)
server/v2/server_test.go (1)

52-54: Add a comment explaining the GetStore method's behavior.

While returning nil is a valid mock implementation, it would be helpful to add a comment explaining why this method returns nil and any potential implications for test scenarios.

Consider adding a comment like this:

// GetStore returns nil as a mock implementation.
// Note: This may need to be updated if tests require a non-nil RootStore.
func (*mockApp[T]) GetStore() storev2.RootStore {
	return nil
}
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f8d15bf and 441141a.

📒 Files selected for processing (2)
  • server/v2/server_test.go (2 hunks)
  • simapp/v2/simdv2/cmd/root_di.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • simapp/v2/simdv2/cmd/root_di.go
🧰 Additional context used
📓 Path-based instructions (1)
server/v2/server_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"

🔇 Additional comments (2)
server/v2/server_test.go (2)

72-74: LGTM: Simplified store server initialization.

The removal of mockStoreBuilder and direct use of store.New[transaction.Tx]() simplifies the test setup. This change aligns well with the refactoring in the main code and makes the test more straightforward.


Line range hint 1-124: Overall assessment: Changes improve code clarity and align with refactoring goals.

The modifications in this file, particularly the addition of the GetStore method to mockApp and the simplification of the storeServer initialization, align well with the PR objectives of refactoring store management. These changes improve code clarity and simplify the test setup without introducing any apparent issues.

The test coverage appears sufficient for the changes associated with this PR. However, ensure that these modifications are consistent with changes in other files and that they adequately test the new AppI.GetStore() functionality in the main code.

@kocubinski kocubinski added this pull request to the merge queue Oct 10, 2024
Merged via the queue into main with commit dd2369d Oct 10, 2024
70 of 72 checks passed
@kocubinski kocubinski deleted the kocu/appI-getStore branch October 10, 2024 14:33
mergify bot pushed a commit that referenced this pull request Oct 10, 2024
…tStore (#22205)

(cherry picked from commit dd2369d)

# Conflicts:
#	runtime/v2/module.go
#	runtime/v2/store.go
#	server/v2/server_test.go
#	server/v2/store/server.go
#	server/v2/types.go
julienrbrt pushed a commit that referenced this pull request Oct 10, 2024
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 C:server/v2 cometbft C:server/v2 Issues related to server/v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants