Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Apr 22, 2024
1 parent 309745d commit 700fb8d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 12 deletions.
41 changes: 30 additions & 11 deletions x/emissions/migrations/v3/migrate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package v3

import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/zeta-chain/zetacore/x/emissions/exported"
"github.com/zeta-chain/zetacore/x/emissions/types"
Expand All @@ -12,14 +11,6 @@ type EmissionsKeeper interface {
SetParams(ctx sdk.Context, params types.Params) error
}

// ObserverSlashAmount is the amount of tokens to be slashed from observer in case of incorrect vote
// by default it is set to 0.1 ZETA
var observerSlashAmountDefaultValue = sdkmath.NewInt(100000000000000000)

// BallotMaturityBlocks is amount of blocks needed for ballot to mature
// by default is set to 100
var ballotMaturityBlocksDefaultValue = 100

// Migrate migrates the x/emissions module state from the consensus version 2 to
// version 3. Specifically, it takes the parameters that are currently stored
// and managed by the x/params modules and stores them directly into the x/emissions
Expand All @@ -32,8 +23,36 @@ func MigrateStore(
var currParams types.Params
legacySubspace.GetParamSet(ctx, &currParams)

currParams.ObserverSlashAmount = observerSlashAmountDefaultValue
currParams.BallotMaturityBlocks = int64(ballotMaturityBlocksDefaultValue)
defaultParams := types.NewParams()

// ensure params are set with default values if not present in legacy params
if currParams.AvgBlockTime == "" {
currParams.AvgBlockTime = defaultParams.AvgBlockTime
}
if currParams.MaxBondFactor == "" {
currParams.MaxBondFactor = defaultParams.MaxBondFactor
}
if currParams.MinBondFactor == "" {
currParams.MinBondFactor = defaultParams.MinBondFactor
}
if currParams.TargetBondRatio == "" {
currParams.TargetBondRatio = defaultParams.TargetBondRatio
}
if currParams.ValidatorEmissionPercentage == "" {
currParams.ValidatorEmissionPercentage = defaultParams.ValidatorEmissionPercentage
}
if currParams.ObserverEmissionPercentage == "" {
currParams.ObserverEmissionPercentage = defaultParams.ObserverEmissionPercentage
}
if currParams.TssSignerEmissionPercentage == "" {
currParams.TssSignerEmissionPercentage = defaultParams.TssSignerEmissionPercentage
}
if currParams.DurationFactorConstant == "" {
currParams.DurationFactorConstant = defaultParams.DurationFactorConstant
}

currParams.ObserverSlashAmount = types.ObserverSlashAmount
currParams.BallotMaturityBlocks = int64(types.BallotMaturityBlocks)
err := currParams.Validate()
if err != nil {
return err
Expand Down
19 changes: 18 additions & 1 deletion x/emissions/migrations/v3/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ func TestMigrate(t *testing.T) {
require.Equal(t, legacyParams, params)
})

t.Run("should migrate if legacy params missing", func(t *testing.T) {
k, ctx, _, _ := keepertest.EmissionsKeeper(t)

legacyParams := types.Params{}
legacySubspace := newMockSubspace(legacyParams)

require.NoError(t, v3.MigrateStore(ctx, k, legacySubspace))

params, found := k.GetParams(ctx)
require.True(t, found)
legacyParams = types.DefaultParams()
legacyParams.ObserverSlashAmount = sdkmath.NewInt(100000000000000000)
legacyParams.BallotMaturityBlocks = 100
require.Equal(t, legacyParams, params)
})

t.Run("should fail to migrate for invalid params", func(t *testing.T) {
k, ctx, _, _ := keepertest.EmissionsKeeper(t)

Expand All @@ -67,6 +83,7 @@ func TestMigrate(t *testing.T) {
}
legacySubspace := newMockSubspace(legacyParams)

require.Error(t, v3.MigrateStore(ctx, k, legacySubspace))
err := v3.MigrateStore(ctx, k, legacySubspace)
require.ErrorContains(t, err, "min bond factor cannot be lower that 0.75")
})
}
8 changes: 8 additions & 0 deletions x/emissions/types/keys.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
Expand Down Expand Up @@ -55,4 +56,11 @@ var (
UndistributedObserverRewardsPoolAddress = authtypes.NewModuleAddress(UndistributedObserverRewardsPool)
UndistributedTssRewardsPoolAddress = authtypes.NewModuleAddress(UndistributedTssRewardsPool)
BlockReward = sdk.MustNewDecFromStr("9620949074074074074.074070733466756687")
// ObserverSlashAmount is the amount of tokens to be slashed from observer in case of incorrect vote
// by default it is set to 0.1 ZETA
ObserverSlashAmount = sdkmath.NewInt(100000000000000000)

// BallotMaturityBlocks is amount of blocks needed for ballot to mature
// by default is set to 100
BallotMaturityBlocks = 100
)

0 comments on commit 700fb8d

Please sign in to comment.