Skip to content

Commit

Permalink
Faster block times (3s) + test
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Aug 14, 2023
1 parent c38fbb4 commit 40c1b60
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 3 deletions.
20 changes: 19 additions & 1 deletion app/upgrades/v17/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
}
5 changes: 3 additions & 2 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 @@ -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
}
Expand Down
23 changes: 23 additions & 0 deletions interchaintest/chain_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand All @@ -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) {
Expand Down
32 changes: 32 additions & 0 deletions interchaintest/helpers/mint.go
Original file line number Diff line number Diff line change
@@ -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
}
32 changes: 32 additions & 0 deletions interchaintest/helpers/slashing.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 40c1b60

Please sign in to comment.