Skip to content

Commit

Permalink
feat!: Faster block times (3s) (#789)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Reecepbcups authored Aug 28, 2023
1 parent 899ed38 commit 1ec8af2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
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

0 comments on commit 1ec8af2

Please sign in to comment.