Skip to content

Commit

Permalink
nit: validate MsgAssignConsumerKey
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoke committed Nov 30, 2023
1 parent b5cebfa commit 5a4b6d8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion x/ccv/provider/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var (
ErrUnknownConsumerChainId = errorsmod.Register(ModuleName, 3, "no consumer chain with this chain id")
ErrUnknownConsumerChannelId = errorsmod.Register(ModuleName, 4, "no consumer chain with this channel id")
ErrInvalidConsumerConsensusPubKey = errorsmod.Register(ModuleName, 5, "empty consumer consensus public key")
ErrBlankConsumerChainID = errorsmod.Register(ModuleName, 6, "consumer chain id must not be blank")
ErrInvalidConsumerChainID = errorsmod.Register(ModuleName, 6, "invalid consumer chain id")
ErrConsumerKeyNotFound = errorsmod.Register(ModuleName, 7, "consumer key not found")
ErrNoValidatorConsumerAddress = errorsmod.Register(ModuleName, 8, "error getting validator consumer address")
ErrNoValidatorProviderAddress = errorsmod.Register(ModuleName, 9, "error getting validator provider address")
Expand Down
5 changes: 2 additions & 3 deletions x/ccv/provider/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ func (msg MsgAssignConsumerKey) GetSignBytes() []byte {
// ValidateBasic implements the sdk.Msg interface.
func (msg MsgAssignConsumerKey) ValidateBasic() error {
if strings.TrimSpace(msg.ChainId) == "" {
return ErrBlankConsumerChainID
return errorsmod.Wrapf(ErrInvalidConsumerChainID, "chainId cannot be blank")
}
// It is possible to assign keys for consumer chains that are not yet approved.
// This can only be done by a signing validator, but it is still sensible
// to limit the chainID size to prevent abuse.

if 128 < len(msg.ChainId) {
return ErrBlankConsumerChainID
return errorsmod.Wrapf(ErrInvalidConsumerChainID, "chainId cannot exceed 128 length")
}
_, err := sdk.ValAddressFromBech32(msg.ProviderAddr)
if err != nil {
Expand Down

0 comments on commit 5a4b6d8

Please sign in to comment.