diff --git a/app/upgrades/v17/upgrades.go b/app/upgrades/v17/upgrades.go index 154b65029..498f0b1a9 100644 --- a/app/upgrades/v17/upgrades.go +++ b/app/upgrades/v17/upgrades.go @@ -14,7 +14,7 @@ import ( func CreateV17UpgradeHandler( mm *module.Manager, cfg module.Configurator, - _ *keepers.AppKeepers, + keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { logger := ctx.Logger().With("upgrade", UpgradeName) @@ -30,6 +30,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)) + return versionMap, err } } diff --git a/cmd/junod/cmd/root.go b/cmd/junod/cmd/root.go index ccb66a6a8..bb33eae45 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" @@ -110,8 +111,8 @@ func initTendermintConfig() *tmcfg.Config { // cfg.P2P.MaxNumInboundPeers = 100 // cfg.P2P.MaxNumOutboundPeers = 40 - // 2 seconds + 1 second tendermint = 3 second blocks (v15 upgrade) - // cfg.Consensus.TimeoutCommit = 2 * time.Second + // 2 seconds + 1 second tendermint = 3 second blocks + cfg.Consensus.TimeoutCommit = 2 * time.Second return cfg } diff --git a/interchaintest/chain_upgrade_test.go b/interchaintest/chain_upgrade_test.go index 663ca8ea6..ee0e005a9 100644 --- a/interchaintest/chain_upgrade_test.go +++ b/interchaintest/chain_upgrade_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + helpers "github.com/CosmosContracts/juno/tests/interchaintest/helpers" cosmosproto "github.com/cosmos/gogoproto/proto" "github.com/docker/docker/client" "github.com/strangelove-ventures/interchaintest/v7" @@ -39,6 +40,7 @@ func CosmosChainUpgradeTest(t *testing.T, chainName, initialVersion, upgradeBran t.Log(chainName, initialVersion, upgradeBranchVersion, upgradeRepo, upgradeName) numVals, numNodes := 4, 4 + // TODO: use PR 788's impl of 'CreateChain' to modify the x/mint genesis to match mainnet. chains := CreateThisBranchChain(t, numVals, numNodes) chain := chains[0].(*cosmos.CosmosChain) @@ -61,8 +63,29 @@ func CosmosChainUpgradeTest(t *testing.T, chainName, initialVersion, upgradeBran ValidatorVoting(t, ctx, chain, proposalID, height, haltHeight) + preUpgradeChecks(t, ctx, chain) + UpgradeNodes(t, ctx, chain, client, haltHeight, upgradeRepo, upgradeBranchVersion) + postUpgradeChecks(t, ctx, chain) + +} + +func preUpgradeChecks(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain) { + mp := helpers.GetMintParams(t, ctx, chain) + // mainnet it is 5048093, but we are just ensuring the upgrade applies correctly from default. + require.Equal(t, mp.BlocksPerYear, uint64(6311520)) + + sp := helpers.GetSlashingParams(t, ctx, chain) + require.Equal(t, sp.SignedBlocksWindow, uint64(100)) +} + +func postUpgradeChecks(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain) { + mp := helpers.GetMintParams(t, ctx, chain) + require.Equal(t, mp.BlocksPerYear, uint64(6311520*2)) // double default + + sp := helpers.GetSlashingParams(t, ctx, chain) + require.Equal(t, sp.SignedBlocksWindow, uint64(100*2)) } func UpgradeNodes(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, client *client.Client, haltHeight uint64, upgradeRepo, upgradeBranchVersion string) { diff --git a/interchaintest/helpers/mint.go b/interchaintest/helpers/mint.go new file mode 100644 index 000000000..8d763ac9f --- /dev/null +++ b/interchaintest/helpers/mint.go @@ -0,0 +1,32 @@ +package helpers + +import ( + "context" + "encoding/json" + "testing" + + minttypes "github.com/CosmosContracts/juno/v17/x/mint/types" + "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" + "github.com/stretchr/testify/require" +) + +func GetMintParams(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain) minttypes.Params { + cmd := []string{ + "junod", "query", "mint", "params", + "--node", chain.GetRPCAddress(), + "--chain-id", chain.Config().ChainID, + "--output", "json", + } + stdout, _, err := chain.Exec(ctx, cmd, nil) + require.NoError(t, err) + + debugOutput(t, string(stdout)) + + results := minttypes.QueryParamsResponse{} + err = json.Unmarshal(stdout, &results) + require.NoError(t, err) + + t.Log(results) + + return results.Params +} diff --git a/interchaintest/helpers/slashing.go b/interchaintest/helpers/slashing.go new file mode 100644 index 000000000..e6daf7e18 --- /dev/null +++ b/interchaintest/helpers/slashing.go @@ -0,0 +1,32 @@ +package helpers + +import ( + "context" + "encoding/json" + "testing" + + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" + "github.com/stretchr/testify/require" +) + +func GetSlashingParams(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain) slashingtypes.Params { + cmd := []string{ + "junod", "query", "slashing", "params", + "--node", chain.GetRPCAddress(), + "--chain-id", chain.Config().ChainID, + "--output", "json", + } + stdout, _, err := chain.Exec(ctx, cmd, nil) + require.NoError(t, err) + + debugOutput(t, string(stdout)) + + results := slashingtypes.QueryParamsResponse{} + err = json.Unmarshal(stdout, &results) + require.NoError(t, err) + + t.Log(results) + + return results.Params +}