diff --git a/simapp/app.go b/simapp/app.go index 325fde488c85..fea36d1132cc 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -24,6 +24,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/crisis" distr "github.com/cosmos/cosmos-sdk/x/distribution" "github.com/cosmos/cosmos-sdk/x/evidence" + evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/gov" @@ -139,7 +141,7 @@ type SimApp struct { UpgradeKeeper upgradekeeper.Keeper ParamsKeeper paramskeeper.Keeper IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly - EvidenceKeeper evidence.Keeper + EvidenceKeeper evidencekeeper.Keeper TransferKeeper ibctransferkeeper.Keeper // make scoped keepers public for test purposes @@ -170,7 +172,7 @@ func NewSimApp( auth.StoreKey, bank.StoreKey, stakingtypes.StoreKey, minttypes.StoreKey, distr.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, - evidence.StoreKey, ibctransfertypes.StoreKey, capability.StoreKey, + evidencetypes.StoreKey, ibctransfertypes.StoreKey, capability.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capability.MemStoreKey) @@ -269,10 +271,10 @@ func NewSimApp( app.IBCKeeper.SetRouter(ibcRouter) // create evidence keeper with router - evidenceKeeper := evidence.NewKeeper( - appCodec, keys[evidence.StoreKey], &app.StakingKeeper, app.SlashingKeeper, + evidenceKeeper := evidencekeeper.NewKeeper( + appCodec, keys[evidencetypes.StoreKey], &app.StakingKeeper, app.SlashingKeeper, ) - evidenceRouter := evidence.NewRouter(). + evidenceRouter := evidencetypes.NewRouter(). AddRoute(ibcclient.RouterKey, ibcclient.HandlerClientMisbehaviour(app.IBCKeeper.ClientKeeper)) evidenceKeeper.SetRouter(evidenceRouter) @@ -304,7 +306,7 @@ func NewSimApp( // NOTE: staking module is required if HistoricalEntries param > 0 app.mm.SetOrderBeginBlockers( upgradetypes.ModuleName, minttypes.ModuleName, distr.ModuleName, slashingtypes.ModuleName, - evidence.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, + evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, ) app.mm.SetOrderEndBlockers(crisis.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName) @@ -316,7 +318,7 @@ func NewSimApp( app.mm.SetOrderInitGenesis( capability.ModuleName, auth.ModuleName, distr.ModuleName, stakingtypes.ModuleName, bank.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisis.ModuleName, - ibchost.ModuleName, genutiltypes.ModuleName, evidence.ModuleName, ibctransfertypes.ModuleName, + ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, ibctransfertypes.ModuleName, ) app.mm.RegisterInvariants(&app.CrisisKeeper) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index e6254c0a44e3..50465b3b6101 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -21,7 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/capability" distr "github.com/cosmos/cosmos-sdk/x/distribution" - "github.com/cosmos/cosmos-sdk/x/evidence" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types" ibchost "github.com/cosmos/cosmos-sdk/x/ibc/24-host" @@ -160,7 +160,7 @@ func TestAppImportExport(t *testing.T) { {app.keys[bank.StoreKey], newApp.keys[bank.StoreKey], [][]byte{bank.BalancesPrefix}}, {app.keys[paramtypes.StoreKey], newApp.keys[paramtypes.StoreKey], [][]byte{}}, {app.keys[govtypes.StoreKey], newApp.keys[govtypes.StoreKey], [][]byte{}}, - {app.keys[evidence.StoreKey], newApp.keys[evidence.StoreKey], [][]byte{}}, + {app.keys[evidencetypes.StoreKey], newApp.keys[evidencetypes.StoreKey], [][]byte{}}, {app.keys[capability.StoreKey], newApp.keys[capability.StoreKey], [][]byte{}}, {app.keys[ibchost.StoreKey], newApp.keys[ibchost.StoreKey], [][]byte{}}, {app.keys[ibctransfertypes.StoreKey], newApp.keys[ibctransfertypes.StoreKey], [][]byte{}}, diff --git a/x/evidence/abci.go b/x/evidence/abci.go index 2e42efa3d079..bc1422cef3be 100644 --- a/x/evidence/abci.go +++ b/x/evidence/abci.go @@ -7,16 +7,19 @@ import ( abci "github.com/tendermint/tendermint/abci/types" tmtypes "github.com/tendermint/tendermint/types" + + "github.com/cosmos/cosmos-sdk/x/evidence/keeper" + "github.com/cosmos/cosmos-sdk/x/evidence/types" ) // BeginBlocker iterates through and handles any newly discovered evidence of // misbehavior submitted by Tendermint. Currently, only equivocation is handled. -func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k Keeper) { +func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) { for _, tmEvidence := range req.ByzantineValidators { switch tmEvidence.Type { case tmtypes.ABCIEvidenceTypeDuplicateVote: - evidence := ConvertDuplicateVoteEvidence(tmEvidence) - k.HandleDoubleSign(ctx, evidence.(*Equivocation)) + evidence := types.ConvertDuplicateVoteEvidence(tmEvidence) + k.HandleDoubleSign(ctx, evidence.(*types.Equivocation)) default: k.Logger(ctx).Error(fmt.Sprintf("ignored unknown evidence type: %s", tmEvidence.Type)) diff --git a/x/evidence/alias.go b/x/evidence/alias.go deleted file mode 100644 index 3505652caeec..000000000000 --- a/x/evidence/alias.go +++ /dev/null @@ -1,50 +0,0 @@ -package evidence - -import ( - "github.com/cosmos/cosmos-sdk/x/evidence/keeper" - "github.com/cosmos/cosmos-sdk/x/evidence/types" -) - -const ( - ModuleName = types.ModuleName - StoreKey = types.StoreKey - RouterKey = types.RouterKey - QuerierRoute = types.QuerierRoute - QueryEvidence = types.QueryEvidence - QueryAllEvidence = types.QueryAllEvidence - TypeMsgSubmitEvidence = types.TypeMsgSubmitEvidence - EventTypeSubmitEvidence = types.EventTypeSubmitEvidence - AttributeValueCategory = types.AttributeValueCategory - AttributeKeyEvidenceHash = types.AttributeKeyEvidenceHash -) - -var ( - NewKeeper = keeper.NewKeeper - NewQuerier = keeper.NewQuerier - - NewMsgSubmitEvidence = types.NewMsgSubmitEvidence - NewRouter = types.NewRouter - NewQueryEvidenceParams = types.NewQueryEvidenceParams - NewQueryAllEvidenceParams = types.NewQueryAllEvidenceParams - RegisterCodec = types.RegisterCodec - RegisterInterfaces = types.RegisterInterfaces - ModuleCdc = types.ModuleCdc - NewGenesisState = types.NewGenesisState - DefaultGenesisState = types.DefaultGenesisState - ConvertDuplicateVoteEvidence = types.ConvertDuplicateVoteEvidence - DoubleSignJailEndTime = types.DoubleSignJailEndTime - ErrNoEvidenceHandlerExists = types.ErrNoEvidenceHandlerExists - ErrInvalidEvidence = types.ErrInvalidEvidence - ErrNoEvidenceExists = types.ErrNoEvidenceExists - ErrEvidenceExists = types.ErrEvidenceExists -) - -type ( - Keeper = keeper.Keeper - - GenesisState = types.GenesisState - MsgSubmitEvidence = types.MsgSubmitEvidence - Handler = types.Handler - Router = types.Router - Equivocation = types.Equivocation -) diff --git a/x/evidence/genesis.go b/x/evidence/genesis.go index b06c7ce96783..4f8ca4852bc7 100644 --- a/x/evidence/genesis.go +++ b/x/evidence/genesis.go @@ -4,13 +4,15 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/evidence/keeper" + "github.com/cosmos/cosmos-sdk/x/evidence/types" ) // InitGenesis initializes the evidence module's state from a provided genesis // state. -func InitGenesis(ctx sdk.Context, k Keeper, gs GenesisState) { +func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) { if err := gs.Validate(); err != nil { - panic(fmt.Sprintf("failed to validate %s genesis state: %s", ModuleName, err)) + panic(fmt.Sprintf("failed to validate %s genesis state: %s", types.ModuleName, err)) } for _, e := range gs.Evidence { @@ -23,8 +25,8 @@ func InitGenesis(ctx sdk.Context, k Keeper, gs GenesisState) { } // ExportGenesis returns the evidence module's exported genesis. -func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState { - return GenesisState{ +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState { + return types.GenesisState{ Evidence: k.GetAllEvidence(ctx), } } diff --git a/x/evidence/genesis_test.go b/x/evidence/genesis_test.go index 32f60a55a4d2..381321224072 100644 --- a/x/evidence/genesis_test.go +++ b/x/evidence/genesis_test.go @@ -12,6 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/evidence" "github.com/cosmos/cosmos-sdk/x/evidence/exported" + "github.com/cosmos/cosmos-sdk/x/evidence/keeper" "github.com/cosmos/cosmos-sdk/x/evidence/types" ) @@ -19,7 +20,7 @@ type GenesisTestSuite struct { suite.Suite ctx sdk.Context - keeper evidence.Keeper + keeper keeper.Keeper } func (suite *GenesisTestSuite) SetupTest() { @@ -44,7 +45,7 @@ func (suite *GenesisTestSuite) TestInitGenesis_Valid() { } suite.NotPanics(func() { - evidence.InitGenesis(suite.ctx, suite.keeper, evidence.NewGenesisState(testEvidence)) + evidence.InitGenesis(suite.ctx, suite.keeper, types.NewGenesisState(testEvidence)) }) for _, e := range testEvidence { @@ -66,7 +67,7 @@ func (suite *GenesisTestSuite) TestInitGenesis_Invalid() { } suite.Panics(func() { - evidence.InitGenesis(suite.ctx, suite.keeper, evidence.NewGenesisState(testEvidence)) + evidence.InitGenesis(suite.ctx, suite.keeper, types.NewGenesisState(testEvidence)) }) suite.Empty(suite.keeper.GetAllEvidence(suite.ctx)) diff --git a/x/evidence/handler.go b/x/evidence/handler.go index 711aff5f8abb..60c59158ede9 100644 --- a/x/evidence/handler.go +++ b/x/evidence/handler.go @@ -4,9 +4,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/evidence/exported" + "github.com/cosmos/cosmos-sdk/x/evidence/keeper" + "github.com/cosmos/cosmos-sdk/x/evidence/types" ) -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()) @@ -16,12 +18,12 @@ func NewHandler(k Keeper) sdk.Handler { 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) } } } -func handleMsgSubmitEvidence(ctx sdk.Context, k Keeper, msg exported.MsgSubmitEvidence) (*sdk.Result, error) { +func handleMsgSubmitEvidence(ctx sdk.Context, k keeper.Keeper, msg exported.MsgSubmitEvidence) (*sdk.Result, error) { evidence := msg.GetEvidence() if err := k.SubmitEvidence(ctx, evidence); err != nil { return nil, err @@ -30,7 +32,7 @@ func handleMsgSubmitEvidence(ctx sdk.Context, k Keeper, msg exported.MsgSubmitEv ctx.EventManager().EmitEvent( sdk.NewEvent( sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory), + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), sdk.NewAttribute(sdk.AttributeKeySender, msg.GetSubmitter().String()), ), ) diff --git a/x/evidence/handler_test.go b/x/evidence/handler_test.go index bae546d0c436..1318b8027b01 100644 --- a/x/evidence/handler_test.go +++ b/x/evidence/handler_test.go @@ -14,6 +14,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/evidence" "github.com/cosmos/cosmos-sdk/x/evidence/exported" + "github.com/cosmos/cosmos-sdk/x/evidence/keeper" "github.com/cosmos/cosmos-sdk/x/evidence/types" ) @@ -25,7 +26,7 @@ type HandlerTestSuite struct { } func testMsgSubmitEvidence(r *require.Assertions, e exported.Evidence, s sdk.AccAddress) exported.MsgSubmitEvidence { - msg, err := evidence.NewMsgSubmitEvidence(s, e) + msg, err := types.NewMsgSubmitEvidence(s, e) r.NoError(err) return msg } @@ -53,10 +54,10 @@ func (suite *HandlerTestSuite) SetupTest() { app := simapp.Setup(checkTx) // recreate keeper in order to use custom testing types - evidenceKeeper := evidence.NewKeeper( - app.AppCodec(), app.GetKey(evidence.StoreKey), app.StakingKeeper, app.SlashingKeeper, + evidenceKeeper := keeper.NewKeeper( + app.AppCodec(), app.GetKey(types.StoreKey), app.StakingKeeper, app.SlashingKeeper, ) - router := evidence.NewRouter() + router := types.NewRouter() router = router.AddRoute(types.RouteEquivocation, testEquivocationHandler(*evidenceKeeper)) evidenceKeeper.SetRouter(router) diff --git a/x/evidence/keeper/keeper_test.go b/x/evidence/keeper/keeper_test.go index 11606401052b..411b5d38d24f 100644 --- a/x/evidence/keeper/keeper_test.go +++ b/x/evidence/keeper/keeper_test.go @@ -10,7 +10,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" - "github.com/cosmos/cosmos-sdk/x/evidence" "github.com/cosmos/cosmos-sdk/x/evidence/exported" "github.com/cosmos/cosmos-sdk/x/evidence/keeper" "github.com/cosmos/cosmos-sdk/x/evidence/types" @@ -81,10 +80,10 @@ func (suite *KeeperTestSuite) SetupTest() { app := simapp.Setup(checkTx) // recreate keeper in order to use custom testing types - evidenceKeeper := evidence.NewKeeper( - app.AppCodec(), app.GetKey(evidence.StoreKey), app.StakingKeeper, app.SlashingKeeper, + evidenceKeeper := keeper.NewKeeper( + app.AppCodec(), app.GetKey(types.StoreKey), app.StakingKeeper, app.SlashingKeeper, ) - router := evidence.NewRouter() + router := types.NewRouter() router = router.AddRoute(types.RouteEquivocation, testEquivocationHandler(*evidenceKeeper)) evidenceKeeper.SetRouter(router) diff --git a/x/evidence/module.go b/x/evidence/module.go index bef19f5d44a3..342991b02609 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -14,14 +14,16 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" eviclient "github.com/cosmos/cosmos-sdk/x/evidence/client" "github.com/cosmos/cosmos-sdk/x/evidence/client/cli" "github.com/cosmos/cosmos-sdk/x/evidence/client/rest" + "github.com/cosmos/cosmos-sdk/x/evidence/keeper" "github.com/cosmos/cosmos-sdk/x/evidence/simulation" + "github.com/cosmos/cosmos-sdk/x/evidence/types" ) var ( @@ -49,24 +51,24 @@ func NewAppModuleBasic(evidenceHandlers ...eviclient.EvidenceHandler) AppModuleB // Name returns the evidence module's name. func (AppModuleBasic) Name() string { - return ModuleName + return types.ModuleName } // RegisterCodec registers the evidence module's types to the provided codec. func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { - RegisterCodec(cdc) + types.RegisterCodec(cdc) } // DefaultGenesis returns the evidence module's default genesis state. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { - return cdc.MustMarshalJSON(DefaultGenesisState()) + return cdc.MustMarshalJSON(types.DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the evidence module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { - var gs GenesisState + var gs types.GenesisState if err := cdc.UnmarshalJSON(bz, &gs); err != nil { - return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err) + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } return gs.Validate() @@ -96,11 +98,11 @@ func (a AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { // GetTxCmd returns the evidence module's root query command. func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command { - return cli.GetQueryCmd(StoreKey, clientCtx.Codec) + return cli.GetQueryCmd(types.StoreKey, clientCtx.Codec) } -func (AppModuleBasic) RegisterInterfaceTypes(registry types.InterfaceRegistry) { - RegisterInterfaces(registry) +func (AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) } // ---------------------------------------------------------------------------- @@ -111,10 +113,10 @@ func (AppModuleBasic) RegisterInterfaceTypes(registry types.InterfaceRegistry) { type AppModule struct { AppModuleBasic - keeper Keeper + keeper keeper.Keeper } -func NewAppModule(keeper Keeper) AppModule { +func NewAppModule(keeper keeper.Keeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, keeper: keeper, @@ -128,17 +130,17 @@ func (am AppModule) Name() string { // Route returns the evidence module's message routing key. func (am AppModule) Route() sdk.Route { - return sdk.NewRoute(RouterKey, NewHandler(am.keeper)) + return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper)) } // QuerierRoute returns the evidence module's query routing key. func (AppModule) QuerierRoute() string { - return QuerierRoute + return types.QuerierRoute } // NewQuerierHandler returns the evidence module's Querier. func (am AppModule) NewQuerierHandler() sdk.Querier { - return NewQuerier(am.keeper) + return keeper.NewQuerier(am.keeper) } func (am AppModule) RegisterQueryService(grpc.Server) {} @@ -149,10 +151,10 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {} // InitGenesis performs the evidence module's genesis initialization It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, bz json.RawMessage) []abci.ValidatorUpdate { - var gs GenesisState + var gs types.GenesisState err := cdc.UnmarshalJSON(bz, &gs) if err != nil { - panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", ModuleName, err)) + panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", types.ModuleName, err)) } InitGenesis(ctx, am.keeper, gs) @@ -197,7 +199,7 @@ func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { // RegisterStoreDecoder registers a decoder for evidence module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { - sdr[StoreKey] = simulation.NewDecodeStore(am.keeper) + sdr[types.StoreKey] = simulation.NewDecodeStore(am.keeper) } // WeightedOperations returns the all the gov module operations with their respective weights. diff --git a/x/ibc/02-client/handler.go b/x/ibc/02-client/handler.go index 70441e56e6c1..0a7cefcd5fa8 100644 --- a/x/ibc/02-client/handler.go +++ b/x/ibc/02-client/handler.go @@ -5,8 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/evidence" evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" @@ -82,7 +82,7 @@ func HandleMsgUpdateClient(ctx sdk.Context, k Keeper, msg exported.MsgUpdateClie // HandlerClientMisbehaviour defines the Evidence module handler for submitting a // light client misbehaviour. -func HandlerClientMisbehaviour(k Keeper) evidence.Handler { +func HandlerClientMisbehaviour(k Keeper) evidencetypes.Handler { return func(ctx sdk.Context, evidence evidenceexported.Evidence) error { misbehaviour, ok := evidence.(exported.Misbehaviour) if !ok {