Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ssv/committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (c *Committee) StartDuty(duty types.Duty) error {
switch d := duty.(type) {
case *types.CommitteeDuty:
if d == nil {
return types.NewError(types.UnknownDutyRoleDataErrorCode, "nil committee duty")
return types.NewError(types.InvalidCommitteeDutyErrorCode, "nil committee duty")
}
slot = phase0.Slot(d.Slot)
runnerMap = &c.CommitteeRunners
Expand Down
2 changes: 2 additions & 0 deletions ssv/committee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,6 @@ func TestCommitteeStartDutyRejectsNilCommitteeDuty(t *testing.T) {
var duty *types.CommitteeDuty
err := committee.StartDuty(duty)
require.EqualError(t, err, "nil committee duty")
require.ErrorIs(t, err, &types.Error{})
require.Equal(t, types.InvalidCommitteeDutyErrorCode, err.(*types.Error).Code)
}
6 changes: 3 additions & 3 deletions types/beacon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,17 @@ func (cd *CommitteeDuty) RunnerRole() RunnerRole {
// - Each duty must pass ValidatorDuty.Validate()
func (cd *CommitteeDuty) Validate() error {
if cd == nil {
return NewError(UnknownDutyRoleDataErrorCode, "nil committee duty")
return NewError(InvalidCommitteeDutyErrorCode, "nil committee duty")
}
if len(cd.ValidatorDuties) == 0 {
return NewError(NoBeaconDutiesErrorCode, "no beacon duties")
}
for _, vd := range cd.ValidatorDuties {
if vd == nil {
return NewError(UnknownDutyRoleDataErrorCode, "nil validator duty")
return NewError(InvalidCommitteeDutyErrorCode, "nil validator duty")
}
if vd.Slot != cd.Slot {
return NewError(UnknownDutyRoleDataErrorCode, "mismatched slot in validator duty")
return NewError(InvalidCommitteeDutyErrorCode, "mismatched slot in validator duty")
}
if vd.Type != BNRoleAttester && vd.Type != BNRoleSyncCommittee {
return NewError(WrongBeaconRoleTypeErrorCode, "invalid beacon role in validator duty")
Expand Down
1 change: 1 addition & 0 deletions types/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const (
InvalidCommitteeMemberErrorCode
InvalidValidatorDutyErrorCode
BeaconVoteNilCheckpointErrorCode
InvalidCommitteeDutyErrorCode
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth calling out in the PR body that consumers matching the raw code UnknownDutyRoleDataErrorCode for nil/malformed CommitteeDuty inputs need to migrate to InvalidCommitteeDutyErrorCode. This is the spec repo, so a migration note reduces friction for ssv-node maintainers picking up the change.

)

type Error struct {
Expand Down
43 changes: 43 additions & 0 deletions types/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,46 @@ func TestBeaconVoteValidate(t *testing.T) {
require.Equal(t, AttestationSourceNotLessThanTargetErrorCode, err.(*Error).Code)
})
}

func TestCommitteeDutyValidate(t *testing.T) {
t.Run("nil committee duty", func(t *testing.T) {
var duty *CommitteeDuty
err := duty.Validate()
require.Error(t, err)
require.ErrorIs(t, err, &Error{})
require.Equal(t, InvalidCommitteeDutyErrorCode, err.(*Error).Code)
})

t.Run("nil validator duty", func(t *testing.T) {
err := (&CommitteeDuty{
Slot: 1,
ValidatorDuties: []*ValidatorDuty{
nil,
},
}).Validate()
require.Error(t, err)
require.ErrorIs(t, err, &Error{})
require.Equal(t, InvalidCommitteeDutyErrorCode, err.(*Error).Code)
})

t.Run("mismatched validator duty slot", func(t *testing.T) {
var pubKey phase0.BLSPubKey
pubKey[0] = 1

err := (&CommitteeDuty{
Slot: 1,
ValidatorDuties: []*ValidatorDuty{
{
Type: BNRoleAttester,
PubKey: pubKey,
Slot: 2,
CommitteeLength: 1,
ValidatorCommitteeIndex: 0,
},
},
}).Validate()
require.Error(t, err)
require.ErrorIs(t, err, &Error{})
require.Equal(t, InvalidCommitteeDutyErrorCode, err.(*Error).Code)
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth adding a subcase for ValidatorDuties: [] so the NoBeaconDutiesErrorCode path is covered too. This new test is now the canonical suite for CommitteeDuty.Validate(), so leaving the empty-slice branch untested is an obvious gap.

}
Loading