Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/slashing: remove alias.go usage #6417

Merged
merged 3 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
Expand All @@ -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)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
)

Expand Down
4 changes: 2 additions & 2 deletions simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}},
Expand Down
3 changes: 2 additions & 1 deletion x/slashing/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
87 changes: 0 additions & 87 deletions x/slashing/alias.go

This file was deleted.

8 changes: 4 additions & 4 deletions x/slashing/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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))
}
10 changes: 5 additions & 5 deletions x/slashing/client/testutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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), &params)
require.NoError(f.T, err)
return params
Expand Down
5 changes: 3 additions & 2 deletions x/slashing/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions x/slashing/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading