-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added upgrade handler for ics infraction params
- Loading branch information
1 parent
6159a47
commit a38bd3d
Showing
5 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package v22 | ||
|
||
import ( | ||
"github.com/cosmos/gaia/v21/app/upgrades" | ||
) | ||
|
||
const ( | ||
// UpgradeName defines the on-chain upgrade name. | ||
UpgradeName = "v22" | ||
) | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
CreateUpgradeHandler: CreateUpgradeHandler, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package v22 | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"cosmossdk.io/math" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
providerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/provider/keeper" | ||
providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
|
||
"github.com/cosmos/gaia/v21/app/keepers" | ||
) | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
keepers *keepers.AppKeepers, | ||
) upgradetypes.UpgradeHandler { | ||
return func(c context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | ||
ctx := sdk.UnwrapSDKContext(c) | ||
ctx.Logger().Info("Starting module migrations...") | ||
|
||
vm, err := mm.RunMigrations(ctx, configurator, vm) | ||
if err != nil { | ||
return vm, err | ||
} | ||
|
||
if err := SetConsumerInfractionParams(ctx, keepers.ProviderKeeper); err != nil { | ||
return vm, err | ||
} | ||
|
||
ctx.Logger().Info("Upgrade v22 complete") | ||
return vm, nil | ||
} | ||
} | ||
|
||
func SetConsumerInfractionParams(ctx sdk.Context, pk providerkeeper.Keeper) error { | ||
infractionParameters := DefaultInfractionParams() | ||
|
||
activeConsumerIds := pk.GetAllActiveConsumerIds(ctx) | ||
Check failure on line 44 in app/upgrades/v22/upgrades.go GitHub Actions / Analyze
|
||
for _, consumerId := range activeConsumerIds { | ||
Check failure on line 45 in app/upgrades/v22/upgrades.go GitHub Actions / Analyze
|
||
if err := pk.SetInfractionParameters(ctx, consumerId, infractionParameters); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func DefaultInfractionParams() providertypes.InfractionParameters { | ||
return providertypes.InfractionParameters{ | ||
DoubleSign: &providertypes.SlashJailParameters{ | ||
JailDuration: time.Duration(1<<63 - 1), // the largest value a time.Duration can hold 9223372036854775807 (approximately 292 years) | ||
SlashFraction: math.LegacyNewDecWithPrec(5, 2), // 0.05 | ||
}, | ||
Downtime: &providertypes.SlashJailParameters{ | ||
JailDuration: 600 * time.Second, | ||
SlashFraction: math.LegacyNewDec(0), // no slashing for downtime on the consumer | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package v22_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
v22 "github.com/cosmos/gaia/v21/app/upgrades/v22" | ||
testutil "github.com/cosmos/interchain-security/v6/testutil/keeper" | ||
providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" | ||
) | ||
|
||
func TestSetDefaultConsumerInfractionParams(t *testing.T) { | ||
t.Helper() | ||
inMemParams := testutil.NewInMemKeeperParams(t) | ||
pk, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, inMemParams) | ||
defer ctrl.Finish() | ||
|
||
// Add consumer chains | ||
initConsumerID := pk.FetchAndIncrementConsumerId(ctx) | ||
pk.SetConsumerChainId(ctx, initConsumerID, "init-1") | ||
pk.SetConsumerPhase(ctx, initConsumerID, providertypes.CONSUMER_PHASE_INITIALIZED) | ||
launchedConsumerID := pk.FetchAndIncrementConsumerId(ctx) | ||
pk.SetConsumerChainId(ctx, launchedConsumerID, "launched-1") | ||
pk.SetConsumerPhase(ctx, launchedConsumerID, providertypes.CONSUMER_PHASE_LAUNCHED) | ||
stoppedConsumerID := pk.FetchAndIncrementConsumerId(ctx) | ||
pk.SetConsumerChainId(ctx, stoppedConsumerID, "stopped-1") | ||
pk.SetConsumerPhase(ctx, stoppedConsumerID, providertypes.CONSUMER_PHASE_STOPPED) | ||
|
||
activeConsumerIds := pk.GetAllActiveConsumerIds(ctx) | ||
Check failure on line 30 in app/upgrades/v22/upgrades_test.go GitHub Actions / Analyze
|
||
require.Equal(t, 2, len(activeConsumerIds)) | ||
|
||
for _, consumerId := range activeConsumerIds { | ||
Check failure on line 33 in app/upgrades/v22/upgrades_test.go GitHub Actions / Analyze
|
||
_, err := pk.GetInfractionParameters(ctx, consumerId) | ||
require.Error(t, err) | ||
} | ||
|
||
err := v22.SetConsumerInfractionParams(ctx, pk) | ||
require.NoError(t, err) | ||
|
||
defaultInfractionParams := v22.DefaultInfractionParams() | ||
for _, consumerId := range activeConsumerIds { | ||
Check failure on line 42 in app/upgrades/v22/upgrades_test.go GitHub Actions / Analyze
|
||
infractionParams, err := pk.GetInfractionParameters(ctx, consumerId) | ||
require.NoError(t, err) | ||
require.Equal(t, defaultInfractionParams, infractionParams) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters