From f21df917a0a5a4624855784bff8db3adc8e33b4e Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 11 Oct 2024 21:38:27 +0200 Subject: [PATCH] updates --- server/v2/server.go | 2 +- server/v2/server_test.go | 6 +++++- server/v2/util.go | 27 +++++++++++++++++---------- simapp/v2/simdv2/cmd/config.go | 2 +- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/server/v2/server.go b/server/v2/server.go index 5f535841c25a..486f5c0ceecb 100644 --- a/server/v2/server.go +++ b/server/v2/server.go @@ -56,7 +56,7 @@ type CLIConfig struct { } const ( - serverName = "serverv2" + serverName = "server" ) var _ ServerComponent[transaction.Tx] = (*Server[transaction.Tx])(nil) diff --git a/server/v2/server_test.go b/server/v2/server_test.go index 92856a3fe05c..c35dea1fc627 100644 --- a/server/v2/server_test.go +++ b/server/v2/server_test.go @@ -65,6 +65,10 @@ func TestServer(t *testing.T) { cfg := v.AllSettings() logger := log.NewLogger(os.Stdout) + + ctx, err := serverv2.SetServerContext(context.Background(), v, logger) + require.NoError(t, err) + grpcServer := grpc.New[transaction.Tx]() err = grpcServer.Init(&mockApp[transaction.Tx]{}, cfg, logger) require.NoError(t, err) @@ -96,7 +100,7 @@ func TestServer(t *testing.T) { require.Equal(t, v.GetString(grpcServer.Name()+".address"), grpc.DefaultConfig().Address) // start empty - ctx, cancelFn := context.WithCancel(context.TODO()) + ctx, cancelFn := context.WithCancel(ctx) go func() { // wait 5sec and cancel context <-time.After(5 * time.Second) diff --git a/server/v2/util.go b/server/v2/util.go index 5b24e77a9d11..d02ea30125e5 100644 --- a/server/v2/util.go +++ b/server/v2/util.go @@ -13,20 +13,27 @@ import ( "cosmossdk.io/log" ) +// SetServerContext sets the logger and viper in the context. +// The server manager expects the logger and viper to be set in the context. +func SetServerContext(ctx context.Context, viper *viper.Viper, logger log.Logger) (context.Context, error) { + if ctx == nil { + ctx = context.Background() + } + + ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger) + ctx = context.WithValue(ctx, corectx.ViperContextKey, viper) + return ctx, nil +} + // SetCmdServerContext sets a command's Context value to the provided argument. +// The server manager expects the logger and viper to be set in the context. // If the context has not been set, set the given context as the default. func SetCmdServerContext(cmd *cobra.Command, viper *viper.Viper, logger log.Logger) error { - var cmdCtx context.Context - if cmd.Context() == nil { - cmdCtx = context.Background() - } else { - cmdCtx = cmd.Context() + ctx, err := SetServerContext(cmd.Context(), viper, logger) + if err != nil { + return err } - - cmdCtx = context.WithValue(cmdCtx, corectx.LoggerContextKey, logger) - cmdCtx = context.WithValue(cmdCtx, corectx.ViperContextKey, viper) - cmd.SetContext(cmdCtx) - + cmd.SetContext(ctx) return nil } diff --git a/simapp/v2/simdv2/cmd/config.go b/simapp/v2/simdv2/cmd/config.go index 2d72c11a1ff2..16cb19db93e7 100644 --- a/simapp/v2/simdv2/cmd/config.go +++ b/simapp/v2/simdv2/cmd/config.go @@ -79,7 +79,7 @@ func initCometConfig() cometbft.CfgOption { cfg := cmtcfg.DefaultConfig() // display only warn logs by default except for p2p and state - cfg.LogLevel = "*:warn,serverv2:info,p2p:info,state:info" + cfg.LogLevel = "*:warn,server:info,p2p:info,state:info" // increase block timeout cfg.Consensus.TimeoutCommit = 5 * time.Second // overwrite default pprof listen address