Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 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
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. Overwrites the existing value on start-up. Default is set to 4s.
p0mvn marked this conversation as resolved.
Show resolved Hide resolved

### 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
68 changes: 65 additions & 3 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 @@ -301,6 +301,22 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
return err
}

serverCtx := server.GetServerContextFromCmd(cmd)

// configure the viper instance to parse home flags
if err := serverCtx.Viper.BindPFlags(cmd.Flags()); err != nil {
return err
}
if err := serverCtx.Viper.BindPFlags(cmd.PersistentFlags()); err != nil {
return err
}

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

initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags())
if err != nil {
return err
Expand Down Expand Up @@ -389,7 +405,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
}
})
}
return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, tmcfg.DefaultConfig())
return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, cometConfig)
ValarDragon marked this conversation as resolved.
Show resolved Hide resolved
},
SilenceUsage: true,
}
Expand All @@ -401,6 +417,52 @@ 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(flags.FlagHome)
configParentDirPath := filepath.Join(rootDir, "config")
configFilePath := filepath.Join(configParentDirPath, "config.toml")

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

_, err := os.Stat(configFilePath)
if err != nil {
if !os.IsNotExist(err) {
return nil, fmt.Errorf("failed to read in %s: %w", configFilePath, err)
}
ValarDragon marked this conversation as resolved.
Show resolved Hide resolved

// If does not exist, write 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
ValarDragon marked this conversation as resolved.
Show resolved Hide resolved
} 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.
serverCtx.Config.Consensus.TimeoutCommit = 4 * time.Second

// It will be re-read in server.InterceptConfigsPreRunHandler
tmcfg.WriteConfigFile(configFilePath, serverCtx.Config)

tmcConfig = serverCtx.Config
}
return tmcConfig, nil
}
ValarDragon marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down