From e49ecfe4edeb83870d4810c59b221eae7e834901 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 16 Sep 2024 12:19:25 +0200 Subject: [PATCH] fix(server/v2/store): fix store server flags (#21745) --- server/v2/store/commands.go | 2 +- server/v2/store/flags.go | 17 +++++++++++++---- server/v2/store/server.go | 10 +++++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/server/v2/store/commands.go b/server/v2/store/commands.go index 5de696a8d307..7c50995f923e 100644 --- a/server/v2/store/commands.go +++ b/server/v2/store/commands.go @@ -91,7 +91,7 @@ func createRootStore(cmd *cobra.Command, v *viper.Viper, logger log.Logger) (sto } dbType = db.DBType(dbStr) } else { - dbType = db.DBType(v.GetString("store.app-db-backend")) + dbType = db.DBType(v.GetString(FlagAppDBBackend)) } scRawDb, err := db.NewDB(dbType, "application", filepath.Join(rootDir, "data"), nil) if err != nil { diff --git a/server/v2/store/flags.go b/server/v2/store/flags.go index 19b917a9d9ee..817a53c1b244 100644 --- a/server/v2/store/flags.go +++ b/server/v2/store/flags.go @@ -1,7 +1,16 @@ package store -const ( - FlagAppDBBackend = "app-db-backend" - FlagKeepRecent = "keep-recent" - FlagInterval = "interval" +import "fmt" + +// start flags are prefixed with the server name +// as the config in prefixed with the server name +// this allows viper to properly bind the flags +func prefix(f string) string { + return fmt.Sprintf("%s.%s", ServerName, f) +} + +var ( + FlagAppDBBackend = prefix("app-db-backend") + FlagKeepRecent = prefix("keep-recent") + FlagInterval = prefix("interval") ) diff --git a/server/v2/store/server.go b/server/v2/store/server.go index e16a09137a4b..a5f464c964a5 100644 --- a/server/v2/store/server.go +++ b/server/v2/store/server.go @@ -11,6 +11,14 @@ import ( serverv2 "cosmossdk.io/server/v2" ) +var ( + _ serverv2.ServerComponent[transaction.Tx] = (*StoreComponent[transaction.Tx])(nil) + _ serverv2.HasConfig = (*StoreComponent[transaction.Tx])(nil) + _ serverv2.HasCLICommands = (*StoreComponent[transaction.Tx])(nil) +) + +const ServerName = "store" + // StoreComponent manages store config // and contains prune & snapshot commands type StoreComponent[T transaction.Tx] struct { @@ -35,7 +43,7 @@ func (s *StoreComponent[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logg } func (s *StoreComponent[T]) Name() string { - return "store" + return ServerName } func (s *StoreComponent[T]) Start(ctx context.Context) error {