Skip to content

Commit

Permalink
rename ValidateBasic to Validate (IBC packets)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoke committed Nov 30, 2023
1 parent 4b26974 commit 5488484
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/integration/slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (suite *CCVTestSuite) TestOnRecvSlashPacketErrors() {
_, _ = providerKeeper.OnRecvSlashPacket(ctx, packet, ccv.SlashPacketData{})
})

// Check ValidateBasic for SlashPacket data
// Check Validate for SlashPacket data
validAddress := ed25519.GenPrivKey().PubKey().Address()
slashPacketData := ccv.NewSlashPacketData(
abci.Validator{
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/consumer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// processed by ApplyCCValidatorChanges) s.t. more recent val power changes overwrite older ones.
func (k Keeper) OnRecvVSCPacket(ctx sdk.Context, packet channeltypes.Packet, newChanges ccv.ValidatorSetChangePacketData) error {
// validate packet data upon receiving
if err := newChanges.ValidateBasic(); err != nil {
if err := newChanges.Validate(); err != nil {
return errorsmod.Wrapf(err, "error validating VSCPacket data")
}

Expand Down
4 changes: 2 additions & 2 deletions x/ccv/provider/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (k Keeper) OnRecvVSCMaturedPacket(
}

// validate packet data upon receiving
if err := data.ValidateBasic(); err != nil {
if err := data.Validate(); err != nil {
return errorsmod.Wrapf(err, "error validating VSCMaturedPacket data")
}

Expand Down Expand Up @@ -285,7 +285,7 @@ func (k Keeper) OnRecvSlashPacket(
}

// validate packet data upon receiving
if err := data.ValidateBasic(); err != nil {
if err := data.Validate(); err != nil {
return nil, errorsmod.Wrapf(err, "error validating SlashPacket data")
}

Expand Down
16 changes: 8 additions & 8 deletions x/ccv/types/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func NewValidatorSetChangePacketData(valUpdates []abci.ValidatorUpdate, valUpdat
}
}

// ValidateBasic is used for validating the CCV packet data.
func (vsc ValidatorSetChangePacketData) ValidateBasic() error {
// Validate is used for validating the CCV packet data.
func (vsc ValidatorSetChangePacketData) Validate() error {
// Note that vsc.ValidatorUpdates can be empty in the case of unbonding
// operations w/o changes in the voting power of the validators in the validator set
if vsc.ValidatorUpdates == nil {
Expand Down Expand Up @@ -53,8 +53,8 @@ func NewVSCMaturedPacketData(valUpdateID uint64) *VSCMaturedPacketData {
}
}

// ValidateBasic is used for validating the VSCMatured packet data.
func (mat VSCMaturedPacketData) ValidateBasic() error {
// Validate is used for validating the VSCMatured packet data.
func (mat VSCMaturedPacketData) Validate() error {
// ValsetUpdateId is strictly positive
if mat.ValsetUpdateId == 0 {
return errorsmod.Wrap(ErrInvalidPacketData, "vscId cannot be equal to zero")
Expand Down Expand Up @@ -87,7 +87,7 @@ func NewSlashPacketDataV1(validator abci.Validator, valUpdateId uint64, infracti
}
}

func (vdt SlashPacketData) ValidateBasic() error {
func (vdt SlashPacketData) Validate() error {
// vdt.Validator.Address must be a consensus address
if err := sdk.VerifyAddressFormat(vdt.Validator.Address); err != nil {
return errorsmod.Wrap(ErrInvalidPacketData, fmt.Sprintf("invalid validator: %s", err.Error()))
Expand All @@ -109,22 +109,22 @@ func (vdt SlashPacketData) ToV1() *SlashPacketDataV1 {
return NewSlashPacketDataV1(vdt.Validator, vdt.ValsetUpdateId, vdt.Infraction)
}

func (cp ConsumerPacketData) ValidateBasic() (err error) {
func (cp ConsumerPacketData) Validate() (err error) {
switch cp.Type {
case VscMaturedPacket:
// validate VSCMaturedPacket
vscMaturedPacket := cp.GetVscMaturedPacketData()
if vscMaturedPacket == nil {
return fmt.Errorf("invalid consumer packet data: VscMaturePacketData data cannot be empty")
}
err = vscMaturedPacket.ValidateBasic()
err = vscMaturedPacket.Validate()
case SlashPacket:
// validate SlashPacket
slashPacket := cp.GetSlashPacketData()
if slashPacket == nil {
return fmt.Errorf("invalid consumer packet data: SlashPacketData data cannot be empty")
}
err = slashPacket.ValidateBasic()
err = slashPacket.Validate()
default:
err = fmt.Errorf("invalid consumer packet type: %q", cp.Type)
}
Expand Down
6 changes: 3 additions & 3 deletions x/ccv/types/wire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ func TestPacketDataValidateBasic(t *testing.T) {
}

for _, c := range cases {
err := c.packetData.ValidateBasic()
err := c.packetData.Validate()
if c.expError {
require.Error(t, err, "%s invalid but passed ValidateBasic", c.name)
require.Error(t, err, "%s invalid but passed Validate", c.name)
} else {
require.NoError(t, err, "%s valid but ValidateBasic returned error: %w", c.name, err)
require.NoError(t, err, "%s valid but Validate returned error: %w", c.name, err)
}
}
}
Expand Down

0 comments on commit 5488484

Please sign in to comment.