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

feat!: Faster block times (3s) #789

Merged
merged 7 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 22 additions & 0 deletions app/upgrades/v17/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ func TestKeeperTestSuite(t *testing.T) {
func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup()

preUpgradeChecks(s)

upgradeHeight := int64(5)
s.ConfirmUpgradeSucceeded(v17.UpgradeName, upgradeHeight)

postUpgradeChecks(s)
}

func preUpgradeChecks(s *UpgradeTestSuite) {
mp := s.App.AppKeepers.MintKeeper.GetParams(s.Ctx)
s.Require().Equal(mp.BlocksPerYear, uint64(6311520))

sp := s.App.AppKeepers.SlashingKeeper.GetParams(s.Ctx)
s.Require().Equal(sp.SignedBlocksWindow, int64(100))
}

func postUpgradeChecks(s *UpgradeTestSuite) {
// Ensure the mint params have doubled
mp := s.App.AppKeepers.MintKeeper.GetParams(s.Ctx)
s.Require().Equal(mp.BlocksPerYear, uint64(6311520*2))

// Ensure the slashing params have doubled
sp := s.App.AppKeepers.SlashingKeeper.GetParams(s.Ctx)
s.Require().Equal(sp.SignedBlocksWindow, int64(100*2))
}
18 changes: 18 additions & 0 deletions app/upgrades/v17/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ func CreateV17UpgradeHandler(
}
logger.Info(fmt.Sprintf("post migrate version map: %v", versionMap))

// x/Mint
// Double blocks per year (from 6 seconds to 3 = 2x blocks per year)
mintParams := keepers.MintKeeper.GetParams(ctx)
mintParams.BlocksPerYear *= 2
if err = keepers.MintKeeper.SetParams(ctx, mintParams); err != nil {
return nil, err
}
logger.Info(fmt.Sprintf("updated minted blocks per year logic to %v", mintParams))

// x/Slashing
// Double slashing window due to double blocks per year
slashingParams := keepers.SlashingKeeper.GetParams(ctx)
slashingParams.SignedBlocksWindow *= 2
if err := keepers.SlashingKeeper.SetParams(ctx, slashingParams); err != nil {
return nil, err
}
logger.Info(fmt.Sprintf("updated slashing params to %v", slashingParams))

// x/drip
if err := keepers.DripKeeper.SetParams(ctx, driptypes.DefaultParams()); err != nil {
return nil, err
Expand Down
15 changes: 11 additions & 4 deletions cmd/junod/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"
"path/filepath"
"time"

wasm "github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
Expand Down Expand Up @@ -89,8 +90,14 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
return err
}

// 2 seconds + 1 second tendermint = 3 second blocks
timeoutCommit := 2 * time.Second

customAppTemplate, customAppConfig := initAppConfig()
customTMConfig := initTendermintConfig()
customTMConfig := initTendermintConfig(timeoutCommit)

// Force faster block times
os.Setenv("JUNOD_CONSENSUS_TIMEOUT_COMMIT", cast.ToString(timeoutCommit))

return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig)
},
Expand All @@ -103,15 +110,15 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {

// initTendermintConfig helps to override default Tendermint Config values.
// return tmcfg.DefaultConfig if no custom configuration is required for the application.
func initTendermintConfig() *tmcfg.Config {
func initTendermintConfig(timeoutCommit time.Duration) *tmcfg.Config {
cfg := tmcfg.DefaultConfig()

// these values put a higher strain on node memory
// cfg.P2P.MaxNumInboundPeers = 100
// cfg.P2P.MaxNumOutboundPeers = 40

// 2 seconds + 1 second tendermint = 3 second blocks (v15 upgrade)
// cfg.Consensus.TimeoutCommit = 2 * time.Second
// While this is set, it only applies to new configs.
cfg.Consensus.TimeoutCommit = timeoutCommit

return cfg
}
Expand Down