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

server/v2 start commands and helpers #19720

Closed
julienrbrt opened this issue Mar 11, 2024 · 3 comments · Fixed by #20505
Closed

server/v2 start commands and helpers #19720

julienrbrt opened this issue Mar 11, 2024 · 3 comments · Fixed by #20505
Assignees
Labels
C:server/v2 Issues related to server/v2

Comments

@julienrbrt
Copy link
Member

Currently, the SDK provides helpers functions for applications to use for starting the app and cometbft:

  • func AddCommands[T types.Application](rootCmd *cobra.Command, appCreator types.AppCreator[T], addStartFlags types.ModuleInitFlags) {

That function is then used by the app developer, who does not need to care about wiring a start command.

We should provide a start command for the comet server (equivalent of https://github.com/cosmos/cosmos-sdk/blob/defab1a1a1520cd6dd0d80768d345560d7c99663/server/start.go) and add a helper in server/v2 to combine all server commands (equivalent server.AddCommands).

Additionally, the SDK provides another helper for config management:

func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate string, customAppConfig interface{}, cmtConfig *cmtcfg.Config) error {

  • Abstract the config creation (equivalent server.InterceptConfigsPreRunHandler). This helper should create the config when it doesn't exist and provide a viper with all the config values.
@julienrbrt julienrbrt added the C:server/v2 Issues related to server/v2 label Mar 11, 2024
@github-project-automation github-project-automation bot moved this to 👀 To Do in Cosmos-SDK Mar 11, 2024
@julienrbrt julienrbrt mentioned this issue Mar 11, 2024
6 tasks
@hieuvubk hieuvubk self-assigned this May 3, 2024
@kocubinski
Copy link
Member

kocubinski commented May 3, 2024

One challenge with this work is maintaining compatibility in command handlers when a server command context is created in server v2 vs v1. See usages of server.GetServerContextFromCmd (30 usages in the SDK).

This fn expects server v1 Context to be set under v1 ServerContextKey and will err/panic unless we treat this condition carefully. We talked briefly on Thursday an proposed that we do roughly the following:

  1. Audit usages of GetServerContextFromCmd in the SDK to determine which of the context fields are actually used from this struc. We suspect many usages are expecting a viper instance.
  2. Transition from one contextKey defined in server/v1 to many defined in core, e.g. ViperContextKey for the viper object. This separates server v1 / v2 concerns from anywhere but server packages.
    2a) Consider if the cmtconfig.Config struct is really needed in this context, which fields are we actually using? It should be avoided in server v2.
  3. Refactor all server v1 code and GetServerContextFromCmd usages to suit.

All this work is done in server v1 in preparation for implementing server v2 command handler which will use the same context keys. Once completed the v2 command handlers should be pretty simple.

@hieuvubk
Copy link
Contributor

hieuvubk commented May 5, 2024

serverContext.Config is mainly used in genutil's cmds.
In case we want to completely remove it from server/v2, what if we get the config directly from viper since config.toml was added to both viper config and serverContext. It can simplify serverCtx of both v1 & v2.
The disadvantage of this method is that we have to access the entry of the toml file instead of calling through an object struct.
Also, Looked through config.toml & app.toml to see if using viper.Get() would duplicate keys but no.
cc @tac0turtle @kocubinski @julienrbrt

@julienrbrt
Copy link
Member Author

serverContext.Config is mainly used in genutil's cmds. In case we want to completely remove it from server/v2, what if we get the config directly from viper since config.toml was added to both viper config and serverContext. It can simplify serverCtx of both v1 & v2. The disadvantage of this method is that we have to access the entry of the toml file instead of calling through an object struct. Also, Looked through config.toml & app.toml to see if using viper.Get() would duplicate keys but no. cc @tac0turtle @kocubinski @julienrbrt

Yes, this is what I was trying to convey last meeting. Just viper + logger should be sufficient. We only need to have context keys in core (for logger and viper).

@tac0turtle tac0turtle moved this from 📋 Backlog to 🤸‍♂️ In Progress in Cosmos-SDK Jun 3, 2024
@github-project-automation github-project-automation bot moved this from 🤸‍♂️ In Progress to 🥳 Done in Cosmos-SDK Jun 19, 2024
@tac0turtle tac0turtle removed this from Cosmos-SDK Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:server/v2 Issues related to server/v2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants