From df68b1512ca6ffc722c884eef3779c2b1440c834 Mon Sep 17 00:00:00 2001 From: dauTT <30392990+dauTT@users.noreply.github.com> Date: Fri, 12 Jun 2020 16:25:12 +0200 Subject: [PATCH] x/slashing: remove alias.go usage (#6417) Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> --- simapp/app.go | 16 ++--- simapp/export.go | 4 +- simapp/sim_test.go | 12 ++-- x/slashing/abci.go | 3 +- x/slashing/alias.go | 87 --------------------------- x/slashing/app_test.go | 8 +-- x/slashing/client/testutil/helpers.go | 10 +-- x/slashing/genesis.go | 5 +- x/slashing/handler.go | 9 +-- x/slashing/handler_test.go | 40 ++++++------ x/slashing/module.go | 29 ++++----- 11 files changed, 71 insertions(+), 152 deletions(-) delete mode 100644 x/slashing/alias.go diff --git a/simapp/app.go b/simapp/app.go index c224c69bc..6c3d3f75d 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -37,6 +37,8 @@ import ( paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" "github.com/cosmos/cosmos-sdk/x/slashing" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/upgrade" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" @@ -118,7 +120,7 @@ type SimApp struct { BankKeeper bank.Keeper CapabilityKeeper *capability.Keeper StakingKeeper staking.Keeper - SlashingKeeper slashing.Keeper + SlashingKeeper slashingkeeper.Keeper MintKeeper mint.Keeper DistrKeeper distr.Keeper GovKeeper gov.Keeper @@ -155,7 +157,7 @@ func NewSimApp( keys := sdk.NewKVStoreKeys( auth.StoreKey, bank.StoreKey, staking.StoreKey, - mint.StoreKey, distr.StoreKey, slashing.StoreKey, + mint.StoreKey, distr.StoreKey, slashingtypes.StoreKey, gov.StoreKey, paramstypes.StoreKey, ibc.StoreKey, upgradetypes.StoreKey, evidence.StoreKey, transfer.StoreKey, capability.StoreKey, ) @@ -180,7 +182,7 @@ func NewSimApp( app.subspaces[staking.ModuleName] = app.ParamsKeeper.Subspace(staking.DefaultParamspace) app.subspaces[mint.ModuleName] = app.ParamsKeeper.Subspace(mint.DefaultParamspace) app.subspaces[distr.ModuleName] = app.ParamsKeeper.Subspace(distr.DefaultParamspace) - app.subspaces[slashing.ModuleName] = app.ParamsKeeper.Subspace(slashing.DefaultParamspace) + app.subspaces[slashingtypes.ModuleName] = app.ParamsKeeper.Subspace(slashingtypes.DefaultParamspace) app.subspaces[gov.ModuleName] = app.ParamsKeeper.Subspace(gov.DefaultParamspace).WithKeyTable(gov.ParamKeyTable()) app.subspaces[crisis.ModuleName] = app.ParamsKeeper.Subspace(crisis.DefaultParamspace) @@ -210,8 +212,8 @@ func NewSimApp( appCodec, keys[distr.StoreKey], app.subspaces[distr.ModuleName], app.AccountKeeper, app.BankKeeper, &stakingKeeper, auth.FeeCollectorName, app.ModuleAccountAddrs(), ) - app.SlashingKeeper = slashing.NewKeeper( - appCodec, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], + app.SlashingKeeper = slashingkeeper.NewKeeper( + appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.subspaces[slashingtypes.ModuleName], ) app.CrisisKeeper = crisis.NewKeeper( app.subspaces[crisis.ModuleName], invCheckPeriod, app.BankKeeper, auth.FeeCollectorName, @@ -290,7 +292,7 @@ func NewSimApp( // CanWithdrawInvariant invariant. // NOTE: staking module is required if HistoricalEntries param > 0 app.mm.SetOrderBeginBlockers( - upgradetypes.ModuleName, mint.ModuleName, distr.ModuleName, slashing.ModuleName, + upgradetypes.ModuleName, mint.ModuleName, distr.ModuleName, slashingtypes.ModuleName, evidence.ModuleName, staking.ModuleName, ibc.ModuleName, ) app.mm.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, staking.ModuleName) @@ -302,7 +304,7 @@ func NewSimApp( // can do so safely. app.mm.SetOrderInitGenesis( capability.ModuleName, auth.ModuleName, distr.ModuleName, staking.ModuleName, bank.ModuleName, - slashing.ModuleName, gov.ModuleName, mint.ModuleName, crisis.ModuleName, + slashingtypes.ModuleName, gov.ModuleName, mint.ModuleName, crisis.ModuleName, ibc.ModuleName, genutil.ModuleName, evidence.ModuleName, transfer.ModuleName, ) diff --git a/simapp/export.go b/simapp/export.go index 84e442faf..78a46a966 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/staking/exported" ) @@ -157,7 +157,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []str // reset start height on signing infos app.SlashingKeeper.IterateValidatorSigningInfos( ctx, - func(addr sdk.ConsAddress, info slashing.ValidatorSigningInfo) (stop bool) { + func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) { info.StartHeight = 0 app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info) return false diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 2de2ed3fa..183a7fb32 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -28,8 +28,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/mint" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/cosmos/cosmos-sdk/x/slashing" - "github.com/cosmos/cosmos-sdk/x/staking" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) // Get flags every time the simulator is run @@ -149,12 +149,12 @@ func TestAppImportExport(t *testing.T) { storeKeysPrefixes := []StoreKeysPrefixes{ {app.keys[auth.StoreKey], newApp.keys[auth.StoreKey], [][]byte{}}, - {app.keys[staking.StoreKey], newApp.keys[staking.StoreKey], + {app.keys[stakingtypes.StoreKey], newApp.keys[stakingtypes.StoreKey], [][]byte{ - staking.UnbondingQueueKey, staking.RedelegationQueueKey, staking.ValidatorQueueKey, - staking.HistoricalInfoKey, + stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey, + stakingtypes.HistoricalInfoKey, }}, // ordering may change but it doesn't matter - {app.keys[slashing.StoreKey], newApp.keys[slashing.StoreKey], [][]byte{}}, + {app.keys[slashingtypes.StoreKey], newApp.keys[slashingtypes.StoreKey], [][]byte{}}, {app.keys[mint.StoreKey], newApp.keys[mint.StoreKey], [][]byte{}}, {app.keys[distr.StoreKey], newApp.keys[distr.StoreKey], [][]byte{}}, {app.keys[bank.StoreKey], newApp.keys[bank.StoreKey], [][]byte{bank.BalancesPrefix}}, diff --git a/x/slashing/abci.go b/x/slashing/abci.go index c6caeec9b..94b8d1e59 100644 --- a/x/slashing/abci.go +++ b/x/slashing/abci.go @@ -4,11 +4,12 @@ import ( abci "github.com/tendermint/tendermint/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/slashing/keeper" ) // BeginBlocker check for infraction evidence or downtime of validators // on every begin block -func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k Keeper) { +func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) { // Iterate over all the validators which *should* have signed this block // store whether or not they have actually signed it and slash/unbond any // which have missed too many blocks in a row (downtime slashing) diff --git a/x/slashing/alias.go b/x/slashing/alias.go deleted file mode 100644 index 921668d85..000000000 --- a/x/slashing/alias.go +++ /dev/null @@ -1,87 +0,0 @@ -package slashing - -import ( - "github.com/cosmos/cosmos-sdk/x/slashing/keeper" - "github.com/cosmos/cosmos-sdk/x/slashing/types" -) - -const ( - ModuleName = types.ModuleName - StoreKey = types.StoreKey - RouterKey = types.RouterKey - QuerierRoute = types.QuerierRoute - DefaultParamspace = types.DefaultParamspace - DefaultSignedBlocksWindow = types.DefaultSignedBlocksWindow - DefaultDowntimeJailDuration = types.DefaultDowntimeJailDuration - QueryParameters = types.QueryParameters - QuerySigningInfo = types.QuerySigningInfo - QuerySigningInfos = types.QuerySigningInfos - - EventTypeSlash = types.EventTypeSlash - EventTypeLiveness = types.EventTypeLiveness - AttributeKeyAddress = types.AttributeKeyAddress - AttributeKeyHeight = types.AttributeKeyHeight - AttributeKeyPower = types.AttributeKeyPower - AttributeKeyReason = types.AttributeKeyReason - AttributeKeyJailed = types.AttributeKeyJailed - AttributeKeyMissedBlocks = types.AttributeKeyMissedBlocks - AttributeValueDoubleSign = types.AttributeValueDoubleSign - AttributeValueMissingSignature = types.AttributeValueMissingSignature - AttributeValueCategory = types.AttributeValueCategory -) - -var ( - // functions aliases - NewKeeper = keeper.NewKeeper - NewQuerier = keeper.NewQuerier - RegisterCodec = types.RegisterCodec - ErrNoValidatorForAddress = types.ErrNoValidatorForAddress - ErrBadValidatorAddr = types.ErrBadValidatorAddr - ErrValidatorJailed = types.ErrValidatorJailed - ErrValidatorNotJailed = types.ErrValidatorNotJailed - ErrMissingSelfDelegation = types.ErrMissingSelfDelegation - ErrSelfDelegationTooLowToUnjail = types.ErrSelfDelegationTooLowToUnjail - ErrNoSigningInfoFound = types.ErrNoSigningInfoFound - NewGenesisState = types.NewGenesisState - NewMissedBlock = types.NewMissedBlock - DefaultGenesisState = types.DefaultGenesisState - ValidateGenesis = types.ValidateGenesis - ValidatorSigningInfoKey = types.ValidatorSigningInfoKey - ValidatorSigningInfoAddress = types.ValidatorSigningInfoAddress - ValidatorMissedBlockBitArrayPrefixKey = types.ValidatorMissedBlockBitArrayPrefixKey - ValidatorMissedBlockBitArrayKey = types.ValidatorMissedBlockBitArrayKey - AddrPubkeyRelationKey = types.AddrPubkeyRelationKey - NewMsgUnjail = types.NewMsgUnjail - ParamKeyTable = types.ParamKeyTable - NewParams = types.NewParams - DefaultParams = types.DefaultParams - NewQuerySigningInfoParams = types.NewQuerySigningInfoParams - NewQuerySigningInfosParams = types.NewQuerySigningInfosParams - NewValidatorSigningInfo = types.NewValidatorSigningInfo - - // variable aliases - ModuleCdc = types.ModuleCdc - ValidatorSigningInfoKeyPrefix = types.ValidatorSigningInfoKeyPrefix - ValidatorMissedBlockBitArrayKeyPrefix = types.ValidatorMissedBlockBitArrayKeyPrefix - AddrPubkeyRelationKeyPrefix = types.AddrPubkeyRelationKeyPrefix - DefaultMinSignedPerWindow = types.DefaultMinSignedPerWindow - DefaultSlashFractionDoubleSign = types.DefaultSlashFractionDoubleSign - DefaultSlashFractionDowntime = types.DefaultSlashFractionDowntime - KeySignedBlocksWindow = types.KeySignedBlocksWindow - KeyMinSignedPerWindow = types.KeyMinSignedPerWindow - KeyDowntimeJailDuration = types.KeyDowntimeJailDuration - KeySlashFractionDoubleSign = types.KeySlashFractionDoubleSign - KeySlashFractionDowntime = types.KeySlashFractionDowntime -) - -type ( - Hooks = keeper.Hooks - Keeper = keeper.Keeper - GenesisState = types.GenesisState - MissedBlock = types.MissedBlock - MsgUnjail = types.MsgUnjail - Params = types.Params - QuerySigningInfoParams = types.QuerySigningInfoParams - QuerySigningInfosParams = types.QuerySigningInfosParams - ValidatorSigningInfo = types.ValidatorSigningInfo -) diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index f8cdb3e17..cc1f3ba17 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -13,7 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank" - "github.com/cosmos/cosmos-sdk/x/slashing" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -29,7 +29,7 @@ func checkValidator(t *testing.T, app *simapp.SimApp, _ sdk.AccAddress, expFound return validator } -func checkValidatorSigningInfo(t *testing.T, app *simapp.SimApp, addr sdk.ConsAddress, expFound bool) slashing.ValidatorSigningInfo { +func checkValidatorSigningInfo(t *testing.T, app *simapp.SimApp, addr sdk.ConsAddress, expFound bool) types.ValidatorSigningInfo { ctxCheck := app.BaseApp.NewContext(true, abci.Header{}) signingInfo, found := app.SlashingKeeper.GetValidatorSigningInfo(ctxCheck, addr) require.Equal(t, expFound, found) @@ -75,7 +75,7 @@ func TestSlashingMsgs(t *testing.T) { require.Equal(t, sdk.ValAddress(addr1), validator.OperatorAddress) require.Equal(t, sdk.Bonded, validator.Status) require.True(sdk.IntEq(t, bondTokens, validator.BondedTokens())) - unjailMsg := &slashing.MsgUnjail{ValidatorAddr: sdk.ValAddress(validator.GetConsPubKey().Address())} + unjailMsg := &types.MsgUnjail{ValidatorAddr: sdk.ValAddress(validator.GetConsPubKey().Address())} checkValidatorSigningInfo(t, app, sdk.ConsAddress(addr1), true) @@ -84,5 +84,5 @@ func TestSlashingMsgs(t *testing.T) { _, res, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{unjailMsg}, []uint64{0}, []uint64{1}, false, false, priv1) require.Error(t, err) require.Nil(t, res) - require.True(t, errors.Is(slashing.ErrValidatorNotJailed, err)) + require.True(t, errors.Is(types.ErrValidatorNotJailed, err)) } diff --git a/x/slashing/client/testutil/helpers.go b/x/slashing/client/testutil/helpers.go index 48ce2401a..ca58ad511 100644 --- a/x/slashing/client/testutil/helpers.go +++ b/x/slashing/client/testutil/helpers.go @@ -7,28 +7,28 @@ import ( "github.com/cosmos/cosmos-sdk/tests" "github.com/cosmos/cosmos-sdk/tests/cli" - "github.com/cosmos/cosmos-sdk/x/slashing" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // QuerySigningInfo returns the signing info for a validator -func QuerySigningInfo(f *cli.Fixtures, val string) slashing.ValidatorSigningInfo { +func QuerySigningInfo(f *cli.Fixtures, val string) types.ValidatorSigningInfo { cmd := fmt.Sprintf("%s query slashing signing-info %s %s", f.SimcliBinary, val, f.Flags()) res, errStr := tests.ExecuteT(f.T, cmd, "") require.Empty(f.T, errStr) - var sinfo slashing.ValidatorSigningInfo + var sinfo types.ValidatorSigningInfo err := f.Cdc.UnmarshalJSON([]byte(res), &sinfo) require.NoError(f.T, err) return sinfo } // QuerySlashingParams returns query slashing params -func QuerySlashingParams(f *cli.Fixtures) slashing.Params { +func QuerySlashingParams(f *cli.Fixtures) types.Params { cmd := fmt.Sprintf("%s query slashing params %s", f.SimcliBinary, f.Flags()) res, errStr := tests.ExecuteT(f.T, cmd, "") require.Empty(f.T, errStr) - var params slashing.Params + var params types.Params err := f.Cdc.UnmarshalJSON([]byte(res), ¶ms) require.NoError(f.T, err) return params diff --git a/x/slashing/genesis.go b/x/slashing/genesis.go index a5d2eb0f1..df866800c 100644 --- a/x/slashing/genesis.go +++ b/x/slashing/genesis.go @@ -2,13 +2,14 @@ package slashing import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/slashing/keeper" "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking/exported" ) // InitGenesis initialize default parameters // and the keeper's address to pubkey map -func InitGenesis(ctx sdk.Context, keeper Keeper, stakingKeeper types.StakingKeeper, data types.GenesisState) { +func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, stakingKeeper types.StakingKeeper, data types.GenesisState) { stakingKeeper.IterateValidators(ctx, func(index int64, validator exported.ValidatorI) bool { keeper.AddPubkey(ctx, validator.GetConsPubKey()) @@ -40,7 +41,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, stakingKeeper types.StakingKeep // ExportGenesis writes the current store values // to a genesis file, which can be imported again // with InitGenesis -func ExportGenesis(ctx sdk.Context, keeper Keeper) (data types.GenesisState) { +func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) (data types.GenesisState) { params := keeper.GetParams(ctx) signingInfos := make(map[string]types.ValidatorSigningInfo) missedBlocks := make(map[string][]types.MissedBlock) diff --git a/x/slashing/handler.go b/x/slashing/handler.go index c4a5b9f12..328a3db61 100644 --- a/x/slashing/handler.go +++ b/x/slashing/handler.go @@ -3,27 +3,28 @@ package slashing import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/slashing/keeper" "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // NewHandler creates an sdk.Handler for all the slashing type messages -func NewHandler(k Keeper) sdk.Handler { +func NewHandler(k keeper.Keeper) sdk.Handler { return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) switch msg := msg.(type) { - case *MsgUnjail: + case *types.MsgUnjail: return handleMsgUnjail(ctx, msg, k) default: - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg) + return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) } } } // Validators must submit a transaction to unjail itself after // having been jailed (and thus unbonded) for downtime -func handleMsgUnjail(ctx sdk.Context, msg *MsgUnjail, k Keeper) (*sdk.Result, error) { +func handleMsgUnjail(ctx sdk.Context, msg *types.MsgUnjail, k keeper.Keeper) (*sdk.Result, error) { err := k.Unjail(ctx, msg.ValidatorAddr) if err != nil { return nil, err diff --git a/x/slashing/handler_test.go b/x/slashing/handler_test.go index 0759dfdf9..2d03ff62f 100644 --- a/x/slashing/handler_test.go +++ b/x/slashing/handler_test.go @@ -12,7 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing" - slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + "github.com/cosmos/cosmos-sdk/x/slashing/keeper" "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -29,7 +29,7 @@ func TestCannotUnjailUnlessJailed(t *testing.T) { amt := sdk.TokensFromConsensusPower(100) addr, val := sdk.ValAddress(pks[0].Address()), pks[0] - msg := slashingkeeper.NewTestMsgCreateValidator(addr, val, amt) + msg := keeper.NewTestMsgCreateValidator(addr, val, amt) res, err := staking.NewHandler(app.StakingKeeper)(ctx, msg) require.NoError(t, err) require.NotNil(t, res) @@ -38,15 +38,15 @@ func TestCannotUnjailUnlessJailed(t *testing.T) { require.Equal( t, app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(addr)), - sdk.Coins{sdk.NewCoin(app.StakingKeeper.GetParams(ctx).BondDenom, slashingkeeper.InitTokens.Sub(amt))}, + sdk.Coins{sdk.NewCoin(app.StakingKeeper.GetParams(ctx).BondDenom, keeper.InitTokens.Sub(amt))}, ) require.Equal(t, amt, app.StakingKeeper.Validator(ctx, addr).GetBondedTokens()) // assert non-jailed validator can't be unjailed - res, err = slh(ctx, slashing.NewMsgUnjail(addr)) + res, err = slh(ctx, types.NewMsgUnjail(addr)) require.Error(t, err) require.Nil(t, res) - require.True(t, errors.Is(slashing.ErrValidatorNotJailed, err)) + require.True(t, errors.Is(types.ErrValidatorNotJailed, err)) } func TestCannotUnjailUnlessMeetMinSelfDelegation(t *testing.T) { @@ -59,7 +59,7 @@ func TestCannotUnjailUnlessMeetMinSelfDelegation(t *testing.T) { slh := slashing.NewHandler(app.SlashingKeeper) amtInt := int64(100) addr, val, amt := sdk.ValAddress(pks[0].Address()), pks[0], sdk.TokensFromConsensusPower(amtInt) - msg := slashingkeeper.NewTestMsgCreateValidator(addr, val, amt) + msg := keeper.NewTestMsgCreateValidator(addr, val, amt) msg.MinSelfDelegation = amt res, err := staking.NewHandler(app.StakingKeeper)(ctx, msg) @@ -70,7 +70,7 @@ func TestCannotUnjailUnlessMeetMinSelfDelegation(t *testing.T) { require.Equal( t, app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(addr)), - sdk.Coins{sdk.NewCoin(app.StakingKeeper.GetParams(ctx).BondDenom, slashingkeeper.InitTokens.Sub(amt))}, + sdk.Coins{sdk.NewCoin(app.StakingKeeper.GetParams(ctx).BondDenom, keeper.InitTokens.Sub(amt))}, ) unbondAmt := sdk.NewCoin(app.StakingKeeper.GetParams(ctx).BondDenom, sdk.OneInt()) @@ -82,10 +82,10 @@ func TestCannotUnjailUnlessMeetMinSelfDelegation(t *testing.T) { require.True(t, app.StakingKeeper.Validator(ctx, addr).IsJailed()) // assert non-jailed validator can't be unjailed - res, err = slh(ctx, slashing.NewMsgUnjail(addr)) + res, err = slh(ctx, types.NewMsgUnjail(addr)) require.Error(t, err) require.Nil(t, res) - require.True(t, errors.Is(slashing.ErrSelfDelegationTooLowToUnjail, err)) + require.True(t, errors.Is(types.ErrSelfDelegationTooLowToUnjail, err)) } func TestJailedValidatorDelegations(t *testing.T) { @@ -95,7 +95,7 @@ func TestJailedValidatorDelegations(t *testing.T) { pks := simapp.CreateTestPubKeys(3) simapp.AddTestAddrsFromPubKeys(app, ctx, pks, sdk.TokensFromConsensusPower(20)) - app.SlashingKeeper.SetParams(ctx, slashingkeeper.TestParams()) + app.SlashingKeeper.SetParams(ctx, keeper.TestParams()) stakingParams := app.StakingKeeper.GetParams(ctx) app.StakingKeeper.SetParams(ctx, stakingParams) @@ -105,7 +105,7 @@ func TestJailedValidatorDelegations(t *testing.T) { valPubKey := pks[1] valAddr, consAddr := sdk.ValAddress(pks[1].Address()), sdk.ConsAddress(pks[0].Address()) - msgCreateVal := slashingkeeper.NewTestMsgCreateValidator(valAddr, valPubKey, bondAmount) + msgCreateVal := keeper.NewTestMsgCreateValidator(valAddr, valPubKey, bondAmount) res, err := staking.NewHandler(app.StakingKeeper)(ctx, msgCreateVal) require.NoError(t, err) require.NotNil(t, res) @@ -114,12 +114,12 @@ func TestJailedValidatorDelegations(t *testing.T) { staking.EndBlocker(ctx, app.StakingKeeper) // set dummy signing info - newInfo := slashing.NewValidatorSigningInfo(consAddr, 0, 0, time.Unix(0, 0), false, 0) + newInfo := types.NewValidatorSigningInfo(consAddr, 0, 0, time.Unix(0, 0), false, 0) app.SlashingKeeper.SetValidatorSigningInfo(ctx, consAddr, newInfo) // delegate tokens to the validator delAddr := sdk.AccAddress(pks[2].Address()) - msgDelegate := slashingkeeper.NewTestMsgDelegate(delAddr, valAddr, bondAmount) + msgDelegate := keeper.NewTestMsgDelegate(delAddr, valAddr, bondAmount) res, err = staking.NewHandler(app.StakingKeeper)(ctx, msgDelegate) require.NoError(t, err) require.NotNil(t, res) @@ -141,24 +141,24 @@ func TestJailedValidatorDelegations(t *testing.T) { require.True(t, validator.IsJailed()) // verify the validator cannot unjail itself - res, err = slashing.NewHandler(app.SlashingKeeper)(ctx, slashing.NewMsgUnjail(valAddr)) + res, err = slashing.NewHandler(app.SlashingKeeper)(ctx, types.NewMsgUnjail(valAddr)) require.Error(t, err) require.Nil(t, res) // self-delegate to validator - msgSelfDelegate := slashingkeeper.NewTestMsgDelegate(sdk.AccAddress(valAddr), valAddr, bondAmount) + msgSelfDelegate := keeper.NewTestMsgDelegate(sdk.AccAddress(valAddr), valAddr, bondAmount) res, err = staking.NewHandler(app.StakingKeeper)(ctx, msgSelfDelegate) require.NoError(t, err) require.NotNil(t, res) // verify the validator can now unjail itself - res, err = slashing.NewHandler(app.SlashingKeeper)(ctx, slashing.NewMsgUnjail(valAddr)) + res, err = slashing.NewHandler(app.SlashingKeeper)(ctx, types.NewMsgUnjail(valAddr)) require.NoError(t, err) require.NotNil(t, res) } func TestInvalidMsg(t *testing.T) { - k := slashing.Keeper{} + k := keeper.Keeper{} h := slashing.NewHandler(k) res, err := h(sdk.NewContext(nil, abci.Header{}, false, nil), sdk.NewTestMsg()) @@ -176,7 +176,7 @@ func TestHandleAbsentValidator(t *testing.T) { pks := simapp.CreateTestPubKeys(1) simapp.AddTestAddrsFromPubKeys(app, ctx, pks, sdk.TokensFromConsensusPower(200)) - app.SlashingKeeper.SetParams(ctx, slashingkeeper.TestParams()) + app.SlashingKeeper.SetParams(ctx, keeper.TestParams()) power := int64(100) amt := sdk.TokensFromConsensusPower(power) @@ -184,7 +184,7 @@ func TestHandleAbsentValidator(t *testing.T) { sh := staking.NewHandler(app.StakingKeeper) slh := slashing.NewHandler(app.SlashingKeeper) - res, err := sh(ctx, slashingkeeper.NewTestMsgCreateValidator(addr, val, amt)) + res, err := sh(ctx, keeper.NewTestMsgCreateValidator(addr, val, amt)) require.NoError(t, err) require.NotNil(t, res) @@ -192,7 +192,7 @@ func TestHandleAbsentValidator(t *testing.T) { require.Equal( t, app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(addr)), - sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.GetParams(ctx).BondDenom, slashingkeeper.InitTokens.Sub(amt))), + sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.GetParams(ctx).BondDenom, keeper.InitTokens.Sub(amt))), ) require.Equal(t, amt, app.StakingKeeper.Validator(ctx, addr).GetBondedTokens()) diff --git a/x/slashing/module.go b/x/slashing/module.go index c588a971c..66563f6da 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -19,6 +19,7 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/slashing/client/cli" "github.com/cosmos/cosmos-sdk/x/slashing/client/rest" + "github.com/cosmos/cosmos-sdk/x/slashing/keeper" "github.com/cosmos/cosmos-sdk/x/slashing/simulation" "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" @@ -44,23 +45,23 @@ func (AppModuleBasic) Name() string { // RegisterCodec registers the slashing module's types for the given codec. func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { - RegisterCodec(cdc) + types.RegisterCodec(cdc) } // DefaultGenesis returns default genesis state as raw bytes for the slashing // module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { - return cdc.MustMarshalJSON(DefaultGenesisState()) + return cdc.MustMarshalJSON(types.DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the slashing module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { - var data GenesisState + var data types.GenesisState if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } - return ValidateGenesis(data) + return types.ValidateGenesis(data) } // RegisterRESTRoutes registers the REST routes for the slashing module. @@ -75,7 +76,7 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { // GetQueryCmd returns no root query command for the slashing module. func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command { - return cli.GetQueryCmd(StoreKey, clientCtx.Codec) + return cli.GetQueryCmd(types.StoreKey, clientCtx.Codec) } //____________________________________________________________________________ @@ -84,14 +85,14 @@ func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command { type AppModule struct { AppModuleBasic - keeper Keeper + keeper keeper.Keeper accountKeeper types.AccountKeeper bankKeeper types.BankKeeper stakingKeeper stakingkeeper.Keeper } // NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Marshaler, keeper Keeper, ak types.AccountKeeper, bk types.BankKeeper, sk stakingkeeper.Keeper) AppModule { +func NewAppModule(cdc codec.Marshaler, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper, sk stakingkeeper.Keeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc}, keeper: keeper, @@ -103,7 +104,7 @@ func NewAppModule(cdc codec.Marshaler, keeper Keeper, ak types.AccountKeeper, bk // Name returns the slashing module's name. func (AppModule) Name() string { - return ModuleName + return types.ModuleName } // RegisterInvariants registers the slashing module invariants. @@ -111,17 +112,17 @@ func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} // Route returns the message routing key for the slashing module. func (am AppModule) Route() sdk.Route { - return sdk.NewRoute(RouterKey, NewHandler(am.keeper)) + return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper)) } // QuerierRoute returns the slashing module's querier route name. func (AppModule) QuerierRoute() string { - return QuerierRoute + return types.QuerierRoute } // NewQuerierHandler returns the slashing module sdk.Querier. func (am AppModule) NewQuerierHandler() sdk.Querier { - return NewQuerier(am.keeper) + return keeper.NewQuerier(am.keeper) } func (am AppModule) RegisterQueryService(grpc.Server) {} @@ -129,8 +130,8 @@ func (am AppModule) RegisterQueryService(grpc.Server) {} // InitGenesis performs genesis initialization for the slashing module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState GenesisState - ModuleCdc.MustUnmarshalJSON(data, &genesisState) + var genesisState types.GenesisState + types.ModuleCdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.keeper, am.stakingKeeper, genesisState) return []abci.ValidatorUpdate{} } @@ -174,7 +175,7 @@ func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { // RegisterStoreDecoder registers a decoder for slashing module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { - sdr[StoreKey] = simulation.NewDecodeStore(am.cdc) + sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) } // WeightedOperations returns the all the slashing module operations with their respective weights.