Skip to content

Commit

Permalink
fix(server/v2): improve server stop (backport #22455) (#22496)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Robert <julien@rbrt.fr>
  • Loading branch information
mergify[bot] and julienrbrt authored Nov 8, 2024
1 parent 9a7ca00 commit 0d068d1
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/v2/cometbft/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
cosmossdk.io/core v1.0.0-alpha.6
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5
cosmossdk.io/log v1.4.1
cosmossdk.io/server/v2 v2.0.0-20241029092041-78cfc68c83af // main
cosmossdk.io/server/v2 v2.0.0-20241108144957-78b5cd4dbd08 // main
cosmossdk.io/server/v2/appmanager v0.0.0-20241029092041-78cfc68c83af // main
cosmossdk.io/server/v2/stf v0.0.0-20241029092041-78cfc68c83af // main
cosmossdk.io/store/v2 v2.0.0-20241108140525-43e28b43ad7a // main
Expand Down
4 changes: 2 additions & 2 deletions server/v2/cometbft/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc=
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
cosmossdk.io/server/v2 v2.0.0-20241029092041-78cfc68c83af h1:3r/aOcDmQUn6aaoCl5PugqSOQVbnqKOQuDJncCjXwaQ=
cosmossdk.io/server/v2 v2.0.0-20241029092041-78cfc68c83af/go.mod h1:CwDB1XPrjXyK1nBtmOf5hW/JtNb4nqqhwFQ2bPittfo=
cosmossdk.io/server/v2 v2.0.0-20241108144957-78b5cd4dbd08 h1:hmTWRUEaRvaZhFhgC/Bd7z/6Rhn+It/3Fja3lECIOHQ=
cosmossdk.io/server/v2 v2.0.0-20241108144957-78b5cd4dbd08/go.mod h1:OecMMKlPdlFp2PxqV/capqhUhbIDaa5OiNkY1v5hi8c=
cosmossdk.io/server/v2/appmanager v0.0.0-20241029092041-78cfc68c83af h1:uDQXvGBH3kZW1UXFccMlNCgHf2L5QCGjNmw51q6atzI=
cosmossdk.io/server/v2/appmanager v0.0.0-20241029092041-78cfc68c83af/go.mod h1:mONOF8GRbxs5R04zMscuQQI1gx/XHTY7imKjcwLI5uo=
cosmossdk.io/server/v2/stf v0.0.0-20241029092041-78cfc68c83af h1:jefP4LTtln0XsXHeSqRENeAGyPQ9qSbGHMy6811FE/c=
Expand Down
6 changes: 4 additions & 2 deletions server/v2/cometbft/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ func New[T transaction.Tx](
// fallback to genesis chain-id
reader, err := os.Open(filepath.Join(home, "config", "genesis.json"))
if err != nil {
panic(err)
return nil, fmt.Errorf("failed to open genesis file: %w", err)
}
defer reader.Close()

chainID, err = genutiltypes.ParseChainIDFromGenesis(reader)
if err != nil {
panic(fmt.Errorf("failed to parse chain-id from genesis file: %w", err))
return nil, fmt.Errorf("failed to parse chain-id from genesis file: %w", err)
}
}

Expand Down Expand Up @@ -216,11 +216,13 @@ func (s *CometBFTServer[T]) Start(ctx context.Context) error {
return err
}

s.logger.Info("starting consensus server")
return s.Node.Start()
}

func (s *CometBFTServer[T]) Stop(context.Context) error {
if s.Node != nil && s.Node.IsRunning() {
s.logger.Info("stopping consensus server")
return s.Node.Stop()
}

Expand Down
9 changes: 9 additions & 0 deletions simapp/v2/app_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ func (app *SimApp[T]) Store() store.RootStore {
return app.store
}

// Close overwrites the base Close method to close the stores.
func (app *SimApp[T]) Close() error {
if err := app.store.Close(); err != nil {
return err
}

return app.App.Close()
}

func ProvideRootStoreConfig(config runtime.GlobalConfig) (*root.Config, error) {
return serverstore.UnmarshalConfig(config)
}
2 changes: 1 addition & 1 deletion simapp/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
cosmossdk.io/log v1.4.1
cosmossdk.io/math v1.3.0
cosmossdk.io/runtime/v2 v2.0.0-20241105073932-55f7cfcebae4 // main
cosmossdk.io/server/v2 v2.0.0-20241106171414-3014713d442f // main
cosmossdk.io/server/v2 v2.0.0-20241108144957-78b5cd4dbd08 // main
cosmossdk.io/server/v2/cometbft v0.0.0-00010101000000-000000000000
cosmossdk.io/store/v2 v2.0.0-20241108144957-78b5cd4dbd08 // main
cosmossdk.io/tools/confix v0.0.0-00010101000000-000000000000
Expand Down
4 changes: 2 additions & 2 deletions simapp/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ cosmossdk.io/runtime/v2 v2.0.0-20241105073932-55f7cfcebae4 h1:uo4LBzsp1bIZ3rBUyo
cosmossdk.io/runtime/v2 v2.0.0-20241105073932-55f7cfcebae4/go.mod h1:SCdBCUiZGKVFNUvglrCUontMZSoXAES5iMbRvPv8bsI=
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc=
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
cosmossdk.io/server/v2 v2.0.0-20241106171414-3014713d442f h1:iOwpowDlNam9Pu/vqLfR7lZBPsf0uIBo0GmAtlJBaA4=
cosmossdk.io/server/v2 v2.0.0-20241106171414-3014713d442f/go.mod h1:rwmmHi0GKaAjMXsWtcrIdZAWaw2oxOHdOkZ09of45H8=
cosmossdk.io/server/v2 v2.0.0-20241108144957-78b5cd4dbd08 h1:hmTWRUEaRvaZhFhgC/Bd7z/6Rhn+It/3Fja3lECIOHQ=
cosmossdk.io/server/v2 v2.0.0-20241108144957-78b5cd4dbd08/go.mod h1:OecMMKlPdlFp2PxqV/capqhUhbIDaa5OiNkY1v5hi8c=
cosmossdk.io/server/v2/appmanager v0.0.0-20241029092041-78cfc68c83af h1:uDQXvGBH3kZW1UXFccMlNCgHf2L5QCGjNmw51q6atzI=
cosmossdk.io/server/v2/appmanager v0.0.0-20241029092041-78cfc68c83af/go.mod h1:mONOF8GRbxs5R04zMscuQQI1gx/XHTY7imKjcwLI5uo=
cosmossdk.io/server/v2/stf v0.0.0-20241029092041-78cfc68c83af h1:jefP4LTtln0XsXHeSqRENeAGyPQ9qSbGHMy6811FE/c=
Expand Down
5 changes: 4 additions & 1 deletion simapp/v2/simdv2/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"errors"
"io"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -71,6 +72,7 @@ func InitRootCmd[T transaction.Tx](
return serverv2.AddCommands[T](
rootCmd,
logger,
io.NopCloser(nil),
deps.GlobalConfig,
initServerConfig(),
deps.Consensus,
Expand All @@ -92,7 +94,7 @@ func InitRootCmd[T transaction.Tx](
if err != nil {
return nil, err
}
restServer, err := rest.New[T](simApp.App.AppManager, logger, deps.GlobalConfig)
restServer, err := rest.New[T](logger, simApp.App.AppManager, deps.GlobalConfig)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -123,6 +125,7 @@ func InitRootCmd[T transaction.Tx](
return serverv2.AddCommands[T](
rootCmd,
logger,
simApp,
deps.GlobalConfig,
initServerConfig(),
deps.Consensus,
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,server:info,p2p:info,state:info"
cfg.LogLevel = "*:warn,p2p:info,state:info,server:info,telemetry:info,grpc:info,rest:info,grpc-gateway:info,comet:info,store:info"
// increase block timeout
cfg.Consensus.TimeoutCommit = 5 * time.Second
// overwrite default pprof listen address
Expand Down

0 comments on commit 0d068d1

Please sign in to comment.