Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Oct 11, 2024
1 parent 3c7720a commit f21df91
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion server/v2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type CLIConfig struct {
}

const (
serverName = "serverv2"
serverName = "server"
)

var _ ServerComponent[transaction.Tx] = (*Server[transaction.Tx])(nil)
Expand Down
6 changes: 5 additions & 1 deletion server/v2/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 17 additions & 10 deletions server/v2/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion simapp/v2/simdv2/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f21df91

Please sign in to comment.