From c9d900be2c5aaaf5a8fa1da9b20d976af7d46d6a Mon Sep 17 00:00:00 2001 From: Nick DeLuca Date: Fri, 29 Mar 2024 11:05:26 -0700 Subject: [PATCH] Set the CDP Block Interval to 100 during v0.26.x upgrade (#1865) * set CDP block interval to 100 to only run interest synchronization for risky cdps every 100 blocks instead of every block * refactor and use constant for setting to improve clarity; update block interval to 50 instead of 100. This will decrease risk by running around every 6 minutes instead of 12 mintues for current mainnet block times. --- app/upgrades.go | 14 +++++++++++++- tests/e2e/e2e_upgrade_handler_test.go | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/upgrades.go b/app/upgrades.go index efc70cdf..90823ffa 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -27,6 +27,8 @@ import ( const ( UpgradeName_Mainnet = "v0.26.0" UpgradeName_Testnet = "v0.26.0-alpha.0" + + CDPLiquidationBlockInterval = int64(50) ) // RegisterUpgradeHandlers registers the upgrade handlers for the app. @@ -123,6 +125,16 @@ func upgradeHandler( // dedicated x/consensus module. baseapp.MigrateParams(ctx, baseAppLegacySS, &app.consensusParamsKeeper) - return app.mm.RunMigrations(ctx, app.configurator, fromVM) + // run migrations for all modules and return new consensus version map + versionMap, err := app.mm.RunMigrations(ctx, app.configurator, fromVM) + + // Set risky CDP's to sync interest and liquidate every 100 blocks instead + // of every block. This significantly improves performance as this cdp + // process is a signification porition of time spent during block execution. + cdpParams := app.cdpKeeper.GetParams(ctx) + cdpParams.LiquidationBlockInterval = CDPLiquidationBlockInterval + app.cdpKeeper.SetParams(ctx, cdpParams) + + return versionMap, err } } diff --git a/tests/e2e/e2e_upgrade_handler_test.go b/tests/e2e/e2e_upgrade_handler_test.go index d0ab3ae0..d0da1910 100644 --- a/tests/e2e/e2e_upgrade_handler_test.go +++ b/tests/e2e/e2e_upgrade_handler_test.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + cdptypes "github.com/kava-labs/kava/x/cdp/types" ) func (suite *IntegrationTestSuite) TestUpgradeParams_SDK() { @@ -98,6 +99,26 @@ func (suite *IntegrationTestSuite) TestUpgradeParams_Consensus() { suite.Require().Equal(expectedParams, *paramsAfter.Params, "x/consensus params after upgrade should be as expected") } +func (suite *IntegrationTestSuite) TestUpgradeParams_CDP_Interval() { + suite.SkipIfUpgradeDisabled() + + beforeUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight - 1) + afterUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight) + + grpcClient := suite.Kava.Grpc + + paramsBefore, err := grpcClient.Query.Cdp.Params(beforeUpgradeCtx, &cdptypes.QueryParamsRequest{}) + suite.Require().NoError(err) + paramsAfter, err := grpcClient.Query.Cdp.Params(afterUpgradeCtx, &cdptypes.QueryParamsRequest{}) + suite.Require().NoError(err) + + expectedParams := paramsBefore.Params + expectedParams.LiquidationBlockInterval = int64(50) + + suite.Require().Equal(expectedParams, paramsAfter.Params, + "expected cdp parameters to equal previous parameters with a liquidation block interval of 100") +} + func mustParseDuration(s string) *time.Duration { d, err := time.ParseDuration(s) if err != nil {