diff --git a/x/dogfood/client/cli/query.go b/x/dogfood/client/cli/query.go index a4dfc065d..a1f193d8d 100644 --- a/x/dogfood/client/cli/query.go +++ b/x/dogfood/client/cli/query.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + // "github.com/cosmos/cosmos-sdk/client/flags" // sdk "github.com/cosmos/cosmos-sdk/types" @@ -15,7 +16,7 @@ import ( ) // GetQueryCmd returns the cli query commands for this module -func GetQueryCmd(queryRoute string) *cobra.Command { +func GetQueryCmd(string) *cobra.Command { // Group dogfood queries under a subcommand cmd := &cobra.Command{ Use: types.ModuleName, diff --git a/x/dogfood/keeper/impl_epochs_hooks.go b/x/dogfood/keeper/impl_epochs_hooks.go index af7cc5267..c17314a89 100644 --- a/x/dogfood/keeper/impl_epochs_hooks.go +++ b/x/dogfood/keeper/impl_epochs_hooks.go @@ -54,7 +54,7 @@ func (wrapper EpochsHooksWrapper) AfterEpochEnd( // BeforeEpochStart is called before an epoch starts. func (wrapper EpochsHooksWrapper) BeforeEpochStart( - ctx sdk.Context, identifier string, epoch int64, + sdk.Context, string, int64, ) { // nothing to do } diff --git a/x/dogfood/keeper/impl_sdk.go b/x/dogfood/keeper/impl_sdk.go index 547f526e7..a019bff2a 100644 --- a/x/dogfood/keeper/impl_sdk.go +++ b/x/dogfood/keeper/impl_sdk.go @@ -12,14 +12,16 @@ import ( ) // interface guards -var _ slashingtypes.StakingKeeper = Keeper{} -var _ evidencetypes.StakingKeeper = Keeper{} -var _ genutiltypes.StakingKeeper = Keeper{} -var _ clienttypes.StakingKeeper = Keeper{} // implemented in `validators.go` +var ( + _ slashingtypes.StakingKeeper = Keeper{} + _ evidencetypes.StakingKeeper = Keeper{} + _ genutiltypes.StakingKeeper = Keeper{} + _ clienttypes.StakingKeeper = Keeper{} // implemented in `validators.go` +) // GetParams is an implementation of the staking interface expected by the SDK's evidence // module. The module does not use it, but it is part of the interface. -func (k Keeper) GetParams(ctx sdk.Context) stakingtypes.Params { +func (k Keeper) GetParams(sdk.Context) stakingtypes.Params { return stakingtypes.Params{} } @@ -30,7 +32,8 @@ func (k Keeper) GetParams(ctx sdk.Context) stakingtypes.Params { // matches that of each validator. Ideally, this invariant should be implemented // by the delegation and/or deposit module(s) instead. func (k Keeper) IterateValidators(sdk.Context, - func(index int64, validator stakingtypes.ValidatorI) (stop bool)) { + func(index int64, validator stakingtypes.ValidatorI) (stop bool), +) { // no op } @@ -42,7 +45,7 @@ func (k Keeper) IterateValidators(sdk.Context, // depending upon the finalized design. We don't need to implement this function here because // we are not calling the AfterValidatorCreated hook in our module, so this will never be // reached. -func (k Keeper) Validator(ctx sdk.Context, addr sdk.ValAddress) stakingtypes.ValidatorI { +func (k Keeper) Validator(sdk.Context, sdk.ValAddress) stakingtypes.ValidatorI { panic("unimplemented on this keeper") } @@ -143,7 +146,7 @@ func (k Keeper) MaxValidators(ctx sdk.Context) uint32 { // GetAllValidators is an implementation of the staking interface expected by the SDK's // slashing module. It is not called within the slashing module, but is part of the interface. -func (k Keeper) GetAllValidators(ctx sdk.Context) (validators []stakingtypes.Validator) { +func (k Keeper) GetAllValidators(sdk.Context) (validators []stakingtypes.Validator) { return []stakingtypes.Validator{} } diff --git a/x/dogfood/keeper/queue.go b/x/dogfood/keeper/queue.go index 591962d5f..07cedfb32 100644 --- a/x/dogfood/keeper/queue.go +++ b/x/dogfood/keeper/queue.go @@ -25,10 +25,10 @@ func (k Keeper) QueueOperation( if operation.PubKey.Equal(key) { if operation.OperationType == operationType { return types.QueueResultExists - } else { - indexToDelete = i - break } + // reverse operation exists, remove it + indexToDelete = i + break } } ret := types.QueueResultSuccess diff --git a/x/dogfood/keeper/validators.go b/x/dogfood/keeper/validators.go index c41b7ba22..bdfc529d6 100644 --- a/x/dogfood/keeper/validators.go +++ b/x/dogfood/keeper/validators.go @@ -48,7 +48,8 @@ func (k Keeper) ApplyValidatorChanges( addr := pubkey.Address() val, found := k.GetValidator(ctx, addr) - if found { + switch found { + case true: // update or delete an existing validator if change.Power < 1 { k.DeleteValidator(ctx, addr) @@ -56,28 +57,32 @@ func (k Keeper) ApplyValidatorChanges( val.Power = change.Power k.SetValidator(ctx, val) } - } else if change.Power > 0 { - // create a new validator - the address is just derived from the public key and has - // no correlation with the operator address on Exocore - ocVal, err := types.NewExocoreValidator(addr, change.Power, pubkey) - if err != nil { - // An error here would indicate that the validator updates - // received are invalid. - panic(err) - } - - k.SetValidator(ctx, ocVal) - err = k.Hooks().AfterValidatorBonded(ctx, sdk.ConsAddress(addr), nil) - if err != nil { - // AfterValidatorBonded is hooked by the Slashing module and should not return - // an error. If any other module were to hook it, they should also not. - panic(err) + case false: + if change.Power > 0 { + // create a new validator - the address is just derived from the public key and + // has + // no correlation with the operator address on Exocore + ocVal, err := types.NewExocoreValidator(addr, change.Power, pubkey) + if err != nil { + // An error here would indicate that the validator updates + // received are invalid. + panic(err) + } + + k.SetValidator(ctx, ocVal) + err = k.Hooks().AfterValidatorBonded(ctx, sdk.ConsAddress(addr), nil) + if err != nil { + // AfterValidatorBonded is hooked by the Slashing module and should not + // return + // an error. If any other module were to hook it, they should also not. + panic(err) + } + } else { + // edge case: we received an update for 0 power + // but the validator is already deleted. Do not forward + // to tendermint. + continue } - } else { - // edge case: we received an update for 0 power - // but the validator is already deleted. Do not forward - // to tendermint. - continue } ret = append(ret, change) } diff --git a/x/dogfood/module.go b/x/dogfood/module.go index 50d02a5d0..44483fd37 100644 --- a/x/dogfood/module.go +++ b/x/dogfood/module.go @@ -56,7 +56,7 @@ func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { types.RegisterInterfaces(reg) } -// DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. +// DefaultGenesis returns a default GenesisState for the module, marshaled to json.RawMessage. // The default GenesisState need to be defined by the module developer and is primarily used for // testing func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { @@ -66,7 +66,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { // ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form func (AppModuleBasic) ValidateGenesis( cdc codec.JSONCodec, - config client.TxEncodingConfig, + _ client.TxEncodingConfig, bz json.RawMessage, ) error { var genState types.GenesisState @@ -81,7 +81,10 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes( clientCtx client.Context, mux *runtime.ServeMux, ) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + // this panic is safe to do because it means an error in setting up the module. + panic(err) + } } // GetTxCmd returns the root Tx command for the module. The subcommands of this root command are diff --git a/x/dogfood/types/codec.go b/x/dogfood/types/codec.go index b70e2a444..3fb01c133 100644 --- a/x/dogfood/types/codec.go +++ b/x/dogfood/types/codec.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" ) -func RegisterCodec(cdc *codec.LegacyAmino) { +func RegisterCodec(*codec.LegacyAmino) { } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {