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

feat(server): add custom start handler #19854

Merged
merged 1 commit into from
Mar 27, 2024
Merged

feat(server): add custom start handler #19854

merged 1 commit into from
Mar 27, 2024

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Mar 25, 2024

Description

Support custom starting app logic. This allows forks of the SDK only modifying the start command to only replace their start logic. Backport to v0.50 won't contain the api improvements (breakage) but will be additive only.

Use case:

Replace the need a forking the sdk for things like: release/v0.50.x...rollkit:cosmos-sdk:release/v0.50.x

How to use:

Set StartCommandHandler and AddFlags in StartCmdOptions when calling AddCommands.

Why method like startAPIServer, startGrpcServer or other private methods in start.go are not simply public to make creating StartCommandHandler less verbose?

Because we do not to provide any api guarantee for those functions. If you are re-implementing SDK's start command, you should know what you are doing and can reimplement those functions yourself.


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

  • New Features
    • Added customizability to the server's start command for enhanced flexibility.
  • Changes
    • Streamlined server module operations by enabling callback into the application struct post-setup.
    • Simplified function calls in the building apps documentation by removing specific parameters.
    • Refactored server startup logic to improve code efficiency and error handling.
  • Bug Fixes
    • Ensured consistency in the PreBlock function by adjusting its return type.
  • Refactor
    • Removed outdated concepts such as basic manager and ModuleInitFlags to clean up the codebase.
    • Updated command addition functions to support new start command customization options.
    • Adjusted command initialization in the simulation application for clarity and efficiency.
  • Documentation
    • Updated building apps documentation to reflect changes in function call parameters.

Copy link
Contributor

coderabbitai bot commented Mar 25, 2024

Warning

Rate Limit Exceeded

@julienrbrt has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 38 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 00b2b9d and 50b4e95.

Walkthrough

The recent updates across various components of the cosmos-sdk focus on simplifying and enhancing customization and consistency. Key changes include the introduction of customizable start command handlers, the removal of the basic manager concept and ModuleInitFlags, and the streamlining of function calls and parameters across the server module and application testnet setup. These adjustments aim to improve developer experience and reduce complexity in application configuration and command handling.

Changes

File(s) Summary
CHANGELOG.md, server/types/app.go - Customizable start command in server module.
- Simplified PreBlock return type.
- Enhanced callback capability in PostSetup.
- Removed basic manager and ModuleInitFlags.
- Removed unnecessary imports and parameters related to cobra, codec, and codectypes.
docs/build/.../05-app-testnet.md - Simplified function calls by removing createMerlinAppAndExport and addModuleInitFlags.
server/start.go, server/util.go - Introduced StartCommandHandler for custom command handling.
- Refactored start functions and AddCommands to use StartCmdOptions.
- Adjusted function signatures and logic for efficiency and better error handling.
simapp/simd/cmd/commands.go, simapp/simd/cmd/root.go, simapp/simd/cmd/root_di.go - Streamlined initRootCmd and NewRootCmd function calls.

Related issues

  • Issue [Epic]: Server/v2 #18282
    Refactors the Cosmos SDK server to be modular, allowing for the composition of servers with existing modules or creating new ones without forking the SDK. The changes in this PR align with the objective of cleaning up and minimizing existing interfaces to facilitate integration of new consensus engines and ensure modularity in server components.

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

@@ -324,7 +324,7 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo
}

// AddCommands add server commands
func AddCommands[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T], addStartFlags types.ModuleInitFlags) {
Copy link
Member Author

Choose a reason for hiding this comment

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

We had two ways to do the same things for flags: Using StartCmdOptions and setting AddFlags and then calling StartCmdWithOptions. Or use AddCommands with custom flags on the start command. This concatenates the possibilities in one.
Note, the backport to v0.50 won't contain that breaking change ( AddCommandsWithStartCmdOptions will do what AddCommands does for v0.51)

@julienrbrt julienrbrt added the backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release label Mar 25, 2024
@julienrbrt julienrbrt marked this pull request as ready for review March 25, 2024 14:29
@julienrbrt julienrbrt requested a review from a team as a code owner March 25, 2024 14:29
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: 7

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 00b2b9d and de52a81.
Files selected for processing (8)
  • CHANGELOG.md (2 hunks)
  • docs/build/building-apps/05-app-testnet.md (1 hunks)
  • server/start.go (12 hunks)
  • server/types/app.go (2 hunks)
  • server/util.go (3 hunks)
  • simapp/simd/cmd/commands.go (3 hunks)
  • simapp/simd/cmd/root.go (1 hunks)
  • simapp/simd/cmd/root_di.go (1 hunks)
Additional comments: 12
server/types/app.go (1)
  • 8-13: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]

The removal of ModuleInitFlags and the cobra import aligns with the PR's objectives to simplify the server module's API and reduce dependencies. This change should help in enhancing customization and reducing the need for forking the SDK.

simapp/simd/cmd/root_di.go (1)
  • 90-90: The modification of the initRootCmd call to pass fewer arguments contributes to simplifying the codebase and aligns with the PR's objectives of enhancing maintainability and readability.
simapp/simd/cmd/root.go (1)
  • 113-113: The modification of the initRootCmd call to pass different arguments contributes to simplifying the codebase and aligns with the PR's objectives of enhancing maintainability and readability.
simapp/simd/cmd/commands.go (1)
  • 50-50: The modification of function calls to use server.StartCmdOptions instead of types.ModuleInitFlags contributes to simplifying the codebase and aligns with the PR's objectives of enhancing maintainability and readability.
server/util.go (2)
  • 327-327: The addition of opts StartCmdOptions[T] to the AddCommands function enhances customization and aligns with the PR's objectives of simplifying the codebase and reducing the need for forking.
  • 353-357: The introduction of the AddCommandsWithStartCmdOptions function, while marked as deprecated, aims to streamline adding server commands with StartCmdOptions. It's important to clarify the deprecation notice to guide developers towards using the preferred AddCommands method directly.
server/start.go (6)
  • 127-128: The addition of StartCommandHandler in StartCmdOptions struct enables customization of the start command handler. This is a key feature for allowing developers to inject custom logic at the application start, aligning with the PR's objectives to enhance flexibility without needing to fork the SDK.
  • 144-146: The default assignment of start to StartCommandHandler if none is provided ensures backward compatibility and a sensible default behavior. This approach is thoughtful, as it maintains the existing functionality for users who do not need custom start logic.
  • 196-196: The invocation of opts.StartCommandHandler within the RunE function of the start command is correctly implemented. It allows for the execution of either the default or a custom start handler based on the configuration provided in opts. This is a crucial integration point for the new feature.
  • 615-615: The removal of the home parameter from the testnetify function and the enhanced error handling within it are positive changes. They contribute to simplifying the function's interface and improving its robustness. Ensure that all invocations of testnetify have been updated accordingly.
  • 642-644: The default assignment of start to StartCommandHandler in the InPlaceTestnetCreator function mirrors the approach taken in StartCmdWithOptions. This consistency in handling default behavior across different commands is commendable.
  • 710-710: The use of opts.StartCommandHandler within the InPlaceTestnetCreator command ensures that the custom start logic can also be applied to testnet creation. This integration extends the flexibility of the new feature to different aspects of the SDK's functionality.

docs/build/building-apps/05-app-testnet.md Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
server/start.go Show resolved Hide resolved
server/start.go Show resolved Hide resolved
CHANGELOG.md 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 de52a81 and 91d6336.
Files selected for processing (1)
  • UPGRADING.md (1 hunks)
Additional comments: 2
UPGRADING.md (2)
  • 34-39: The code snippet provided for simplifying the start command is clear and correctly demonstrates the change from a function call to struct initialization. This change should streamline the process for developers and make the codebase more maintainable.
  • 31-43: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-1206]

While the document is technically accurate and provides clear upgrade instructions, it's recommended to perform a thorough grammar and spell check outside of code blocks and technical terms. This will enhance the readability and professionalism of the document. Consider using a professional text editor or grammar checking tool to identify and correct these issues.

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.

lgtm

@julienrbrt julienrbrt added this pull request to the merge queue Mar 27, 2024
Merged via the queue into main with commit def211d Mar 27, 2024
59 of 62 checks passed
@julienrbrt julienrbrt deleted the julien/custom-start branch March 27, 2024 07:16
mergify bot pushed a commit that referenced this pull request Mar 27, 2024
(cherry picked from commit def211d)

# Conflicts:
#	CHANGELOG.md
#	UPGRADING.md
#	docs/docs/build/building-apps/05-app-testnet.md
#	server/start.go
#	server/util.go
#	simapp/simd/cmd/commands.go
#	simapp/simd/cmd/root.go
#	simapp/simd/cmd/root_v2.go
meetrick pushed a commit to meetrick/cosmos-sdk that referenced this pull request Mar 28, 2024
julienrbrt added a commit that referenced this pull request Mar 28, 2024
Co-authored-by: Julien Robert <julien@rbrt.fr>
@coderabbitai coderabbitai bot mentioned this pull request Mar 28, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants