Skip to content

Commit

Permalink
took into account comment
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed Jun 5, 2024
1 parent e0775d9 commit 1c62d65
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
18 changes: 13 additions & 5 deletions x/ccv/provider/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ func (cccp *ConsumerAdditionProposal) ProposalType() string {
}

// ValidatePSSFeatures returns an error if the `topN` and `validatorsPowerCap` parameters are no in the correct ranges
func ValidatePSSFeatures(topN uint32, validatorsPowerCap uint32, error *errorsmod.Error) error {
func ValidatePSSFeatures(topN uint32, validatorsPowerCap uint32) error {
// Top N corresponds to the top N% of validators that have to validate the consumer chain and can only be 0 (for an
// Opt In chain) or in the range [50, 100] (for a Top N chain).
if topN != 0 && (topN < 50 || topN > 100) {
return errorsmod.Wrap(error, "Top N can either be 0 or in the range [50, 100]")
return fmt.Errorf("Top N can either be 0 or in the range [50, 100]")
}

if validatorsPowerCap != 0 && validatorsPowerCap > 100 {
return errorsmod.Wrap(error, "validators' power cap must be in the range [0, 100]")
return fmt.Errorf("validators' power cap has to be in the range [1, 100]")
}

return nil
Expand Down Expand Up @@ -163,7 +163,11 @@ func (cccp *ConsumerAdditionProposal) ValidateBasic() error {
return errorsmod.Wrap(ErrInvalidConsumerAdditionProposal, "unbonding period cannot be zero")
}

return ValidatePSSFeatures(cccp.Top_N, cccp.ValidatorsPowerCap, ErrInvalidConsumerAdditionProposal)
err := ValidatePSSFeatures(cccp.Top_N, cccp.ValidatorsPowerCap)
if err != nil {
return errorsmod.Wrapf(ErrInvalidConsumerAdditionProposal, "invalid PSS features: %s", err.Error())
}
return nil
}

// String returns the string representation of the ConsumerAdditionProposal.
Expand Down Expand Up @@ -269,7 +273,11 @@ func (cccp *ConsumerModificationProposal) ValidateBasic() error {
return errorsmod.Wrap(ErrInvalidConsumerModificationProposal, "consumer chain id must not be blank")
}

return ValidatePSSFeatures(cccp.Top_N, cccp.ValidatorsPowerCap, ErrInvalidConsumerModificationProposal)
err := ValidatePSSFeatures(cccp.Top_N, cccp.ValidatorsPowerCap)
if err != nil {
return errorsmod.Wrapf(ErrInvalidConsumerModificationProposal, "invalid PSS features: %s", err.Error())
}
return nil
}

// NewEquivocationProposal creates a new equivocation proposal.
Expand Down
20 changes: 10 additions & 10 deletions x/ccv/provider/types/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,15 +576,15 @@ func TestConsumerModificationProposalValidateBasic(t *testing.T) {
}

func TestValidatePSSFeatures(t *testing.T) {
require.NoError(t, types.ValidatePSSFeatures(0, 0, types.ErrInvalidConsumerRemovalProp))
require.NoError(t, types.ValidatePSSFeatures(50, 0, types.ErrInvalidConsumerRemovalProp))
require.NoError(t, types.ValidatePSSFeatures(100, 0, types.ErrInvalidConsumerRemovalProp))
require.NoError(t, types.ValidatePSSFeatures(0, 10, types.ErrInvalidConsumerRemovalProp))
require.NoError(t, types.ValidatePSSFeatures(0, 100, types.ErrInvalidConsumerRemovalProp))
require.NoError(t, types.ValidatePSSFeatures(50, 100, types.ErrInvalidConsumerRemovalProp))
require.NoError(t, types.ValidatePSSFeatures(0, 0))
require.NoError(t, types.ValidatePSSFeatures(50, 0))
require.NoError(t, types.ValidatePSSFeatures(100, 0))
require.NoError(t, types.ValidatePSSFeatures(0, 10))
require.NoError(t, types.ValidatePSSFeatures(0, 100))
require.NoError(t, types.ValidatePSSFeatures(50, 100))

require.Error(t, types.ValidatePSSFeatures(10, 0, types.ErrInvalidConsumerRemovalProp))
require.Error(t, types.ValidatePSSFeatures(49, 0, types.ErrInvalidConsumerRemovalProp))
require.Error(t, types.ValidatePSSFeatures(101, 0, types.ErrInvalidConsumerRemovalProp))
require.Error(t, types.ValidatePSSFeatures(50, 101, types.ErrInvalidConsumerRemovalProp))
require.Error(t, types.ValidatePSSFeatures(10, 0))
require.Error(t, types.ValidatePSSFeatures(49, 0))
require.Error(t, types.ValidatePSSFeatures(101, 0))
require.Error(t, types.ValidatePSSFeatures(50, 101))
}

0 comments on commit 1c62d65

Please sign in to comment.