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(simdv2): allow non-comet server components #22351

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

mark-rushakoff
Copy link
Member

@mark-rushakoff mark-rushakoff commented Oct 23, 2024

This renames NewRootCmd to NewCometBFTRootCmd, to make it clear that it uses CometBFT for the consensus layer. Callers who want to use a different consensus-providing server component can instead call NewRootCmdWithConsensusComponent, passing in a callback to be evaluated with a client context in order to produce the component.

This pattern is working for Gordian-Cosmos integration.

I'm not especially tied to the new function names. I'm also open to more clear naming for "consensus component" which occurs a few times.

/cc @kocubinski as this may overlap or conflict with #22267.

Summary by CodeRabbit

  • New Features

    • Introduced a new command structure with the NewCometBFTRootCmd function for improved consensus component integration.
    • Added NewRootCmdWithConsensusComponent function for flexible command creation.
  • Bug Fixes

    • Updated command initialization across multiple components to ensure consistent behavior with the new consensus structure.
  • Tests

    • Modified test cases to utilize the new command structure, ensuring compatibility with recent changes.

This renames NewRootCmd to NewCometBFTRootCmd, to make it clear that it
uses CometBFT for the consensus layer. Callers who want to use a
different consensus-providing server component can instead call
NewRootCmdWithConsensusComponent, passing in a callback to be evaluated
with a client context in order to produce the component.

This pattern is working for Gordian-Cosmos integration.

I'm not especially tied to the new function names. I'm also open to more
clear naming for "consensus component" which occurs a few times.
Copy link
Contributor

coderabbitai bot commented Oct 23, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve significant modifications to the command structure within the simapp/v2/simdv2/cmd package. The initRootCmd function has been updated to replace the txConfig parameter with a new consensusComponent parameter. Additionally, the NewRootCmd function has been renamed to NewCometBFTRootCmd, and a new function NewRootCmdWithConsensusComponent has been introduced to enhance the command initialization process. These alterations reflect a transition towards a more modular approach in managing server components for consensus.

Changes

File Path Change Summary
simapp/v2/simdv2/cmd/commands.go - Updated initRootCmd function signature: removed txConfig, added consensusComponent.
- Maintained structure for newApp and error handling in appExport.
simapp/v2/simdv2/cmd/root_di.go - Renamed NewRootCmd to NewCometBFTRootCmd.
- Added NewRootCmdWithConsensusComponent function to facilitate command creation with a consensus component.
- Updated parameters for initRootCmd.
simapp/v2/simdv2/cmd/root_test.go - Replaced cmd.NewRootCmd[transaction.Tx]() with cmd.NewCometBFTRootCmd[transaction.Tx]() in TestInitCmd and TestHomeFlagRegistration functions.
simapp/v2/simdv2/cmd/testnet_test.go - Updated TestInitTestFilesCmd to use cmd.NewCometBFTRootCmd[transaction.Tx]() instead of cmd.NewRootCmd[transaction.Tx]().
simapp/v2/simdv2/main.go - Changed cmd.NewRootCmd[transaction.Tx]() to cmd.NewCometBFTRootCmd[transaction.Tx]() in the main function, preserving error handling and execution flow.

Possibly related PRs

Suggested labels

C:server/v2, C:server/v2 api, C:server/v2 cometbft

Suggested reviewers

  • kocubinski
  • julienrbrt
  • facundomedica
  • sontrinh16

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

🧹 Outside diff range and nitpick comments (5)
simapp/v2/simdv2/cmd/testnet_test.go (1)

Line range hint 19-24: Consider enhancing test coverage.

The current test only verifies successful command execution. Consider adding test cases for:

  • Error scenarios (e.g., invalid flags)
  • Verification of created files and their contents
  • Different configuration combinations

Would you like me to help generate additional test cases to improve coverage?

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

Line range hint 1-43: Enhance test coverage for the new functionality.

The current test file only covers the CometBFT-specific functionality. To ensure robust testing, consider adding:

  1. A new test function TestNewRootCmdWithConsensusComponent that verifies:
    • Custom consensus component initialization
    • Error cases for invalid component configurations
    • Component callback execution
  2. Integration tests demonstrating interoperability with non-CometBFT components

Example test structure:

func TestNewRootCmdWithConsensusComponent(t *testing.T) {
    tests := []struct {
        name string
        component func(client.Context) (server.Component, error)
        wantErr bool
    }{
        // Add test cases here
    }
    // ... test implementation
}

Would you like me to help create these additional test cases?


Based on the gathered information, I can now provide a final verification response.

The review comment's concern about additional test coverage is valid but needs refinement

The code shows that NewCometBFTRootCmd is actually a wrapper around NewRootCmdWithConsensusComponent (as seen in simapp/v2/simdv2/cmd/root_di.go). While the review correctly identifies the need for more test coverage, the specific suggestions need adjustment because:

  1. NewCometBFTRootCmd is already implemented to use NewRootCmdWithConsensusComponent internally, showing proper architectural separation
  2. The current test validates the basic initialization path, which is essential for both CometBFT and non-CometBFT scenarios
  3. The test file appropriately tests the command's core functionality (initialization and home flag registration)

Recommendations for additional test coverage:

  • Test initialization with different consensus component configurations using the existing NewRootCmdWithConsensusComponent
  • Add verification of the generated files and configurations after initialization
  • Test error scenarios when invalid consensus configurations are provided
🔗 Analysis chain

Line range hint 19-26: Additional test coverage needed for non-CometBFT components.

While this test covers the basic CometBFT initialization, we should add test cases for:

  1. Initialization with a custom consensus component using NewRootCmdWithConsensusComponent
  2. Verification of the initialization results beyond just checking for errors

Let me gather more context about the codebase structure and the new functionality to provide a more accurate verification.


Let me check the specific implementation details of the root command and consensus components to make a more informed verification.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any other test files that might cover the new functionality
fd -e go -x rg -l "NewRootCmdWithConsensusComponent.*_test"

Length of output: 61


Script:

#!/bin/bash
# Check for the existence and implementation of NewRootCmdWithConsensusComponent
ast-grep --pattern 'func NewRootCmdWithConsensusComponent'

# Look for any test files in the cmd directory
fd -e go ".*_test.go" cmd/

# Check for any consensus-related interfaces or types
rg -l "ConsensusComponent|consensus" --type go

Length of output: 6871


Script:

#!/bin/bash
# Check the implementation of root command in the same directory
rg -A 10 "NewCometBFTRootCmd" simapp/v2/simdv2/cmd/

# Check for any consensus-related command implementations
rg -A 10 "NewRootCmd.*Consensus" server/v2/

# Look for any test setup related to consensus components
rg -A 5 "TestRoot" --type go

Length of output: 6311

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

46-46: LGTM! Consider adding documentation.

The new consensusComponent parameter effectively supports the PR's goal of allowing non-CometBFT server components. Consider adding a godoc comment to document the purpose of this parameter and provide an example of how to use it with different consensus components.

 func initRootCmd[T transaction.Tx](
 	rootCmd *cobra.Command,
 	moduleManager *runtimev2.MM[T],
+	// consensusComponent allows specifying a custom consensus implementation
+	// Example: cometbft.New() or custom.ConsensusComponent()
 	consensusComponent serverv2.ServerComponent[T],
 ) {
simapp/v2/simdv2/cmd/root_di.go (1)

33-35: Consider refining the function documentation comments

The comments for NewCometBFTRootCmd could be more concise. As per the Uber Go Style Guide, avoid stating the obvious or duplicating information clear from the code. Consider combining or simplifying the comments to enhance readability.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bf12702 and 39778d7.

📒 Files selected for processing (5)
  • simapp/v2/simdv2/cmd/commands.go (2 hunks)
  • simapp/v2/simdv2/cmd/root_di.go (3 hunks)
  • simapp/v2/simdv2/cmd/root_test.go (2 hunks)
  • simapp/v2/simdv2/cmd/testnet_test.go (1 hunks)
  • simapp/v2/simdv2/main.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
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/root_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/testnet_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/main.go (1)

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

🔇 Additional comments (8)
simapp/v2/simdv2/main.go (1)

15-15: LGTM! Note: Breaking change.

The renaming from NewRootCmd to NewCometBFTRootCmd accurately reflects the use of CometBFT as the consensus layer. However, this is a breaking change that will require updates from existing users.

Let's verify if the documentation needs to be updated:

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

19-19: LGTM: Command rename aligns with PR objectives.

The change from NewRootCmd to NewCometBFTRootCmd correctly reflects the explicit use of CometBFT as the consensus layer.

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

Line range hint 32-43: LGTM! The home flag registration test is well-structured.

The test properly verifies the flag registration functionality, which is independent of the consensus component changes.

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

Line range hint 72-76: Verify component initialization order.

The component initialization looks correct, but let's verify that the order of components (consensus → gRPC → store → telemetry → REST) doesn't introduce any dependencies or startup timing issues.

Let's check for any ordering constraints in the codebase:

✅ Verification successful

Let me gather more specific information about component dependencies and initialization order.

This will help us verify if there are any specific ordering requirements during component initialization and startup.


Based on the code analysis, I can now provide the final response:

Component initialization order is correctly implemented

The verification shows that:

  • Components are started concurrently using errgroup, meaning there's no strict startup order dependency
  • Each component is initialized sequentially but independently through the Init method
  • The server implementation doesn't enforce any specific ordering constraints between components

The current order (consensus → gRPC → store → telemetry → REST) is suitable as:

  • Consensus component is primary and correctly placed first
  • Supporting services (gRPC, store, telemetry) follow
  • REST gateway is appropriately last as it may depend on other services
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any ordering requirements or dependencies between components
rg -A 5 "AddCommands|ServerComponent" --type go

Length of output: 9023


Script:

#!/bin/bash
# Check for component dependencies in Start and Init methods
ast-grep --pattern 'func ($x *Server[$_]) Start(context.Context) error {
  $$$
}'

# Check component initialization order requirements
rg -B 3 -A 3 "Start|Init" server/v2/server.go

Length of output: 2339

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

16-17: Necessary imports added correctly

The added imports serverv2 "cosmossdk.io/server/v2" and "cosmossdk.io/server/v2/cometbft" are appropriately included to support the new consensus component functionality.


36-44: Function implementation is well-structured

The NewCometBFTRootCmd function correctly utilizes generics and delegates to NewRootCmdWithConsensusComponent, allowing for flexibility in specifying the consensus component. The implementation aligns with Go best practices.


46-51: Function definition and documentation are appropriate

The NewRootCmdWithConsensusComponent function is properly defined with a clear purpose. The use of generics and the function signature facilitate the injection of different consensus components. The documentation provides adequate context for users.


104-105: Consensus component integration is correctly implemented

The instantiation of consensusComponent using makeConsensusComponent(clientCtx) and its subsequent use in initRootCmd effectively integrates the new consensus component into the command initialization process. Variable naming is clear and consistent.

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.

I don't think this is necessary.
Simapp demonstrate what is possible with the SDK and I don't think adding this adds any value to a chain, as the whole validator set needs to use the same consensus engine

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

😁

Copy link
Contributor

@hieuvubk hieuvubk left a comment

Choose a reason for hiding this comment

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

lgtm

@julienrbrt julienrbrt added this pull request to the merge queue Oct 24, 2024
Merged via the queue into main with commit 6e6255d Oct 24, 2024
79 of 80 checks passed
@julienrbrt julienrbrt deleted the mr/inject-server-component branch October 24, 2024 08:37
mergify bot pushed a commit that referenced this pull request Oct 24, 2024
julienrbrt pushed a commit that referenced this pull request Oct 24, 2024
alpe added a commit that referenced this pull request Oct 25, 2024
* main: (157 commits)
  feat(core): add ConfigMap type (#22361)
  test: migrate e2e/genutil to systemtest (#22325)
  feat(accounts): re-introduce bundler (#21562)
  feat(log): add slog-backed Logger type (#22347)
  fix(x/tx): add feePayer as signer (#22311)
  test: migrate e2e/baseapp to integration tests (#22357)
  test: add x/circuit system tests (#22331)
  test: migrate e2e/tx tests to systemtest (#22152)
  refactor(simdv2): allow non-comet server components (#22351)
  build(deps): Bump rtCamp/action-slack-notify from 2.3.1 to 2.3.2 (#22352)
  fix(server/v2): respect context cancellation in start command (#22346)
  chore(simdv2): allow overriding the --home flag (#22348)
  feat(server/v2): add SimulateWithState to AppManager (#22335)
  docs(x/accounts): improve comments (#22339)
  chore: remove unused local variables (#22340)
  test: x/accounts systemtests (#22320)
  chore(client): use command's configured output (#22334)
  perf(log): use sonic json lib  (#22233)
  build(deps): bump x/tx (#22327)
  fix(x/accounts/lockup): fix proto path (#22319)
  ...
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.

5 participants