From 1ec8af23959f84dd2f85e20b0e7523137259318c Mon Sep 17 00:00:00 2001 From: Reece Williams <31943163+Reecepbcups@users.noreply.github.com> Date: Mon, 28 Aug 2023 09:18:04 -0500 Subject: [PATCH] feat!: Faster block times (3s) (#789) * Faster block times (3s) + test * Fix query pointer ref * Pull out Param types (since no `params` are shown in the queries anymore * Change uint64 to string * Move 3s block time check to go test * Forced faster block times config --- app/upgrades/v17/upgrade_test.go | 22 ++++++++++++++++++++++ app/upgrades/v17/upgrades.go | 18 ++++++++++++++++++ cmd/junod/cmd/root.go | 15 +++++++++++---- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/app/upgrades/v17/upgrade_test.go b/app/upgrades/v17/upgrade_test.go index e02c2e4b8..dded4c49a 100644 --- a/app/upgrades/v17/upgrade_test.go +++ b/app/upgrades/v17/upgrade_test.go @@ -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)) } diff --git a/app/upgrades/v17/upgrades.go b/app/upgrades/v17/upgrades.go index 0650180e3..bdeece740 100644 --- a/app/upgrades/v17/upgrades.go +++ b/app/upgrades/v17/upgrades.go @@ -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 diff --git a/cmd/junod/cmd/root.go b/cmd/junod/cmd/root.go index ccb66a6a8..9e71d0e27 100644 --- a/cmd/junod/cmd/root.go +++ b/cmd/junod/cmd/root.go @@ -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" @@ -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) }, @@ -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 }