Skip to content

Commit

Permalink
chore(lint): apply to dogfood
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 committed Feb 28, 2024
1 parent 3d78db7 commit 3a5d824
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 39 deletions.
3 changes: 2 additions & 1 deletion x/dogfood/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ 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"

"github.com/ExocoreNetwork/exocore/x/dogfood/types"
)

// 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,
Expand Down
2 changes: 1 addition & 1 deletion x/dogfood/keeper/impl_epochs_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
19 changes: 11 additions & 8 deletions x/dogfood/keeper/impl_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}

Expand All @@ -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
}

Expand All @@ -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")
}

Expand Down Expand Up @@ -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{}
}

Expand Down
6 changes: 3 additions & 3 deletions x/dogfood/keeper/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 27 additions & 22 deletions x/dogfood/keeper/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,41 @@ 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)
} else {
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)
}
Expand Down
9 changes: 6 additions & 3 deletions x/dogfood/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/dogfood/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3a5d824

Please sign in to comment.