Skip to content

Commit

Permalink
refactor: auto-set timeout-commit to 4s for faster block times (backp…
Browse files Browse the repository at this point in the history
…ort #7180) (#7183)

* refactor: auto-set timeout-commit to 4s for faster block times (backport #7180)

* lint

---------

Co-authored-by: Roman <[email protected]>
  • Loading branch information
mergify[bot] and p0mvn authored Dec 23, 2023
1 parent 041361a commit d321508
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 5 deletions.
18 changes: 15 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "cmd/osmosisd/main.go",
"args": [
"init",
"test",
],
},

{
// Note: Osmosisd must already be running
// Binary must be built with debug flags.
Expand Down Expand Up @@ -33,11 +45,11 @@
"buildFlags": "-tags e2e",
"env": {
"OSMOSIS_E2E": "True",
"OSMOSIS_E2E_SKIP_IBC": "true",
"OSMOSIS_E2E_SKIP_UPGRADE": "true",
"OSMOSIS_E2E_SKIP_IBC": "false",
"OSMOSIS_E2E_SKIP_UPGRADE": "false",
"OSMOSIS_E2E_SKIP_CLEANUP": "true",
"OSMOSIS_E2E_SKIP_STATE_SYNC": "true",
"OSMOSIS_E2E_UPGRADE_VERSION": "v18",
"OSMOSIS_E2E_UPGRADE_VERSION": "v21",
"OSMOSIS_E2E_DEBUG_LOG": "false",
},
"preLaunchTask": "e2e-setup"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Config

* [#7180](https://github.com/osmosis-labs/osmosis/pull/7180) Change `consensus.timeout-commit` from 5s to 4s in `config.toml`. Overwrites the existing value on start-up. Default is set to 4s.

### API

* [#6991](https://github.com/osmosis-labs/osmosis/pull/6991) Fix: total liquidity poolmanager grpc gateway query
Expand Down
4 changes: 4 additions & 0 deletions cmd/osmosisd/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
config.Mempool.Size = 10000
config.StateSync.TrustPeriod = 112 * time.Hour

// The original default is 5s and is set in Cosmos SDK.
// We lower it to 4s for faster block times.
config.Consensus.TimeoutCommit = 4 * time.Second

config.SetRoot(clientCtx.HomeDir)

chainID, _ := cmd.Flags().GetString(flags.FlagChainID)
Expand Down
80 changes: 78 additions & 2 deletions cmd/osmosisd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"
"regexp"
"strings"
"time"

rosettaCmd "cosmossdk.io/tools/rosetta/cmd"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -32,6 +33,7 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
Expand Down Expand Up @@ -59,8 +61,6 @@ import (

"github.com/joho/godotenv"

"github.com/cosmos/cosmos-sdk/client/config"

osmosis "github.com/osmosis-labs/osmosis/v21/app"
)

Expand Down Expand Up @@ -401,6 +401,60 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
return rootCmd, encodingConfig
}

// overwrites config.toml values if it exists, otherwise it writes the default config.toml
func overwriteConfigTomlValues(serverCtx *server.Context) (*tmcfg.Config, error) {
// Get paths to config.toml and config parent directory
rootDir := serverCtx.Viper.GetString(tmcli.HomeFlag)

configParentDirPath := filepath.Join(rootDir, "config")
configFilePath := filepath.Join(configParentDirPath, "config.toml")

// Initialize default config
tmcConfig := tmcfg.DefaultConfig()

_, err := os.Stat(configFilePath)
if err != nil {
// something besides a does not exist error
if !os.IsNotExist(err) {
return nil, fmt.Errorf("failed to read in %s: %w", configFilePath, err)
}

// It does not exist, so we update the default config.toml to update
// We modify the default config.toml to have faster block times
// It will be written by server.InterceptConfigsPreRunHandler
tmcConfig.Consensus.TimeoutCommit = 4 * time.Second
} else {
// config.toml exists

serverCtx.Viper.SetConfigType("toml")
serverCtx.Viper.SetConfigName("config")
serverCtx.Viper.AddConfigPath(configParentDirPath)

// We read it in and modify the consensus timeout commit
// and write it back.
if err := serverCtx.Viper.ReadInConfig(); err != nil {
return nil, fmt.Errorf("failed to read in %s: %w", configFilePath, err)
}

// The original default is 5s and is set in Cosmos SDK.
// We lower it to 4s for faster block times.
if serverCtx.Config.Consensus.TimeoutCommit == 5*time.Second {
serverCtx.Config.Consensus.TimeoutCommit = 4 * time.Second
}
tmcConfig = serverCtx.Config

defer func() {
if err := recover(); err != nil {
fmt.Printf("failed to write to %s: %s\n", configFilePath, err)
}
}()
// It will be re-read in server.InterceptConfigsPreRunHandler
// this may panic for permissions issues. So we catch the panic.
tmcfg.WriteConfigFile(configFilePath, serverCtx.Config)
}
return tmcConfig, nil
}

func getHomeEnvironment() string {
envPath := filepath.Join(osmosis.DefaultNodeHome, ".env")

Expand Down Expand Up @@ -572,6 +626,28 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {

server.AddCommands(rootCmd, osmosis.DefaultNodeHome, newApp, createOsmosisAppAndExport, addModuleInitFlags)

for i, cmd := range rootCmd.Commands() {
if cmd.Name() == "start" {
startRunE := cmd.RunE

// Instrument start command pre run hook with custom logic
cmd.RunE = func(cmd *cobra.Command, args []string) error {
serverCtx := server.GetServerContextFromCmd(cmd)

// overwrite config.toml values
_, err := overwriteConfigTomlValues(serverCtx)
if err != nil {
return err
}

return startRunE(cmd, args)
}

rootCmd.Commands()[i] = cmd
break
}
}

// add keybase, auxiliary RPC, query, and tx child commands
rootCmd.AddCommand(
rpc.StatusCommand(),
Expand Down

0 comments on commit d321508

Please sign in to comment.