-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86fc22c
commit f1e7c6a
Showing
4 changed files
with
92 additions
and
1 deletion.
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
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,39 @@ | ||
package v9 | ||
|
||
import ( | ||
"time" | ||
|
||
"cosmossdk.io/math" | ||
storetypes "cosmossdk.io/store/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
providerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/provider/keeper" | ||
providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" | ||
) | ||
|
||
func MigrateConsumerInfractionParams(ctx sdk.Context, store storetypes.KVStore, pk providerkeeper.Keeper) error { | ||
infractionParameters := defaultInfractionParams() | ||
|
||
activeConsumerIds := pk.GetAllActiveConsumerIds(ctx) | ||
for _, consumerId := range activeConsumerIds { | ||
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,35 @@ | ||
package v9 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
testutil "github.com/cosmos/interchain-security/v6/testutil/keeper" | ||
) | ||
|
||
func TestSetDefaultConsumerInfractionParams(t *testing.T) { | ||
t.Helper() | ||
inMemParams := testutil.NewInMemKeeperParams(t) | ||
k, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, inMemParams) | ||
defer ctrl.Finish() | ||
|
||
store := ctx.KVStore(inMemParams.StoreKey) | ||
|
||
activeConsumerIds := k.GetAllActiveConsumerIds(ctx) | ||
|
||
for _, consumerId := range activeConsumerIds { | ||
_, err := k.GetInfractionParameters(ctx, consumerId) | ||
require.Error(t, err) | ||
} | ||
|
||
err := MigrateConsumerInfractionParams(ctx, store, k) | ||
require.NoError(t, err) | ||
|
||
defaultInfractionParams := defaultInfractionParams() | ||
for _, consumerId := range activeConsumerIds { | ||
infractionParams, err := k.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