From 5de4f6cc85f67a3b418ddc4f85366b1a0f5c5d63 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 23 May 2024 12:54:39 +0700 Subject: [PATCH] add deprecated cmt --- server/start.go | 26 ++++++++------------------ server/util.go | 8 ++++---- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/server/start.go b/server/start.go index eceababa18e1..db7ab63b7730 100644 --- a/server/start.go +++ b/server/start.go @@ -114,12 +114,6 @@ const ( KeyTriggerTestnetUpgrade = "trigger-testnet-upgrade" ) -// Keep Context type -type Context struct { - Viper *viper.Viper - Logger log.Logger -} - // StartCmdOptions defines options that can be customized in `StartCmdWithOptions`, type StartCmdOptions[T types.Application] struct { // DBOpener can be used to customize db opening, for example customize db options or support different db backends, @@ -706,12 +700,8 @@ you want to test the upgrade handler itself. RunE: func(cmd *cobra.Command, args []string) error { viper := client.GetViperFromCmd(cmd) logger := client.GetLoggerFromCmd(cmd) - serverCtx := &Context{ - Viper: viper, - Logger: logger, - } - _, err := GetPruningOptionsFromFlags(serverCtx.Viper) + _, err := GetPruningOptionsFromFlags(viper) if err != nil { return err } @@ -723,7 +713,7 @@ you want to test the upgrade handler itself. withCMT, _ := cmd.Flags().GetBool(flagWithComet) if !withCMT { - serverCtx.Logger.Info("starting ABCI without CometBFT") + logger.Info("starting ABCI without CometBFT") } newChainID := args[0] @@ -745,20 +735,20 @@ you want to test the upgrade handler itself. // Set testnet keys to be used by the application. // This is done to prevent changes to existing start API. - serverCtx.Viper.Set(KeyIsTestnet, true) - serverCtx.Viper.Set(KeyNewChainID, newChainID) - serverCtx.Viper.Set(KeyNewOpAddr, newOperatorAddress) + viper.Set(KeyIsTestnet, true) + viper.Set(KeyNewChainID, newChainID) + viper.Set(KeyNewOpAddr, newOperatorAddress) err = wrapCPUProfile(viper, logger, func() error { return opts.StartCommandHandler(viper, logger, clientCtx, testnetAppCreator, withCMT, opts) }) - serverCtx.Logger.Debug("received quit signal") + logger.Debug("received quit signal") graceDuration, _ := cmd.Flags().GetDuration(FlagShutdownGrace) if graceDuration > 0 { - serverCtx.Logger.Info("graceful shutdown start", FlagShutdownGrace, graceDuration) + logger.Info("graceful shutdown start", FlagShutdownGrace, graceDuration) <-time.After(graceDuration) - serverCtx.Logger.Info("graceful shutdown complete") + logger.Info("graceful shutdown complete") } return err diff --git a/server/util.go b/server/util.go index 5c8f9b455104..493d0a5daaa8 100644 --- a/server/util.go +++ b/server/util.go @@ -41,8 +41,8 @@ import ( genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) -// Keep Context type as LegacyContext -type LegacyContext struct { +// Deprecated: Do not use, we use viper to track all config +type Context struct { Viper *viper.Viper Logger log.Logger Config *cmtcfg.Config @@ -185,8 +185,8 @@ func CreateSDKLogger(v *viper.Viper, out io.Writer) (log.Logger, error) { // GetServerContextFromCmd returns a Context from a command or an empty Context // if it has not been set. -func GetServerContextFromCmd(cmd *cobra.Command) *LegacyContext { - serverCtx := &LegacyContext{} +func GetServerContextFromCmd(cmd *cobra.Command) *Context { + serverCtx := &Context{} if v := cmd.Context().Value(corectx.ViperContextKey{}); v != nil { viper := v.(*viper.Viper) serverCtx.Viper = viper