Skip to content

Commit

Permalink
cleanup duties naming (#13451)
Browse files Browse the repository at this point in the history
* updating some naming to reflect changes to duties

* fixing unit tests

* fixing more tests
  • Loading branch information
james-prysm authored Jan 22, 2024
1 parent 5a2453a commit 4afb379
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go_library(
name = "go_default_library",
srcs = [
"aggregator.go",
"assignments.go",
"duties.go",
"attester.go",
"blocks.go",
"construct_generic_block.go",
Expand Down Expand Up @@ -178,7 +178,7 @@ go_test(
timeout = "moderate",
srcs = [
"aggregator_test.go",
"assignments_test.go",
"duties_test.go",
"attester_test.go",
"blocks_test.go",
"construct_generic_block_test.go",
Expand Down
6 changes: 3 additions & 3 deletions validator/client/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
func TestSubmitAggregateAndProof_GetDutiesRequestFailure(t *testing.T) {
hook := logTest.NewGlobal()
validator, _, validatorKey, finish := setup(t)
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{}}
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{}}
defer finish()

var pubKey [fieldparams.BLSPubkeyLength]byte
Expand All @@ -39,7 +39,7 @@ func TestSubmitAggregateAndProof_SignFails(t *testing.T) {
var pubKey [fieldparams.BLSPubkeyLength]byte
copy(pubKey[:], validatorKey.PublicKey().Marshal())
validator.duties = &ethpb.DutiesResponse{
Duties: []*ethpb.DutiesResponse_Duty{
CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
},
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestSubmitAggregateAndProof_Ok(t *testing.T) {
var pubKey [fieldparams.BLSPubkeyLength]byte
copy(pubKey[:], validatorKey.PublicKey().Marshal())
validator.duties = &ethpb.DutiesResponse{
Duties: []*ethpb.DutiesResponse_Duty{
CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
},
Expand Down
2 changes: 1 addition & 1 deletion validator/client/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (v *validator) duty(pubKey [fieldparams.BLSPubkeyLength]byte) (*ethpb.Dutie
return nil, errors.New("no duties for validators")
}

for _, duty := range v.duties.Duties {
for _, duty := range v.duties.CurrentEpochDuties {
if bytes.Equal(pubKey[:], duty.PublicKey) {
return duty, nil
}
Expand Down
18 changes: 9 additions & 9 deletions validator/client/attest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
func TestRequestAttestation_ValidatorDutiesRequestFailure(t *testing.T) {
hook := logTest.NewGlobal()
validator, _, validatorKey, finish := setup(t)
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{}}
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{}}
defer finish()

var pubKey [fieldparams.BLSPubkeyLength]byte
Expand All @@ -47,7 +47,7 @@ func TestAttestToBlockHead_SubmitAttestation_EmptyCommittee(t *testing.T) {
defer finish()
var pubKey [fieldparams.BLSPubkeyLength]byte
copy(pubKey[:], validatorKey.PublicKey().Marshal())
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
CommitteeIndex: 0,
Expand All @@ -63,7 +63,7 @@ func TestAttestToBlockHead_SubmitAttestation_RequestFailure(t *testing.T) {

validator, m, validatorKey, finish := setup(t)
defer finish()
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
CommitteeIndex: 5,
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestAttestToBlockHead_AttestsCorrectly(t *testing.T) {
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
var pubKey [fieldparams.BLSPubkeyLength]byte
copy(pubKey[:], validatorKey.PublicKey().Marshal())
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
CommitteeIndex: 5,
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestAttestToBlockHead_BlocksDoubleAtt(t *testing.T) {
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
var pubKey [fieldparams.BLSPubkeyLength]byte
copy(pubKey[:], validatorKey.PublicKey().Marshal())
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
CommitteeIndex: 5,
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestAttestToBlockHead_BlocksSurroundAtt(t *testing.T) {
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
var pubKey [fieldparams.BLSPubkeyLength]byte
copy(pubKey[:], validatorKey.PublicKey().Marshal())
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
CommitteeIndex: 5,
Expand Down Expand Up @@ -278,7 +278,7 @@ func TestAttestToBlockHead_BlocksSurroundedAtt(t *testing.T) {
var pubKey [fieldparams.BLSPubkeyLength]byte
copy(pubKey[:], validatorKey.PublicKey().Marshal())
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
CommitteeIndex: 5,
Expand Down Expand Up @@ -365,7 +365,7 @@ func TestAttestToBlockHead_DoesAttestAfterDelay(t *testing.T) {
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
var pubKey [fieldparams.BLSPubkeyLength]byte
copy(pubKey[:], validatorKey.PublicKey().Marshal())
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
CommitteeIndex: 5,
Expand Down Expand Up @@ -404,7 +404,7 @@ func TestAttestToBlockHead_CorrectBitfieldLength(t *testing.T) {
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
var pubKey [fieldparams.BLSPubkeyLength]byte
copy(pubKey[:], validatorKey.PublicKey().Marshal())
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
CommitteeIndex: 5,
Expand Down
22 changes: 11 additions & 11 deletions validator/client/sync_committee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
func TestSubmitSyncCommitteeMessage_ValidatorDutiesRequestFailure(t *testing.T) {
hook := logTest.NewGlobal()
validator, m, validatorKey, finish := setup(t)
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{}}
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{}}
defer finish()

m.validatorClient.EXPECT().GetSyncMessageBlockRoot(
Expand All @@ -44,7 +44,7 @@ func TestSubmitSyncCommitteeMessage_BadDomainData(t *testing.T) {
hook := logTest.NewGlobal()
validatorIndex := primitives.ValidatorIndex(7)
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
Committee: committee,
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestSubmitSyncCommitteeMessage_CouldNotSubmit(t *testing.T) {
hook := logTest.NewGlobal()
validatorIndex := primitives.ValidatorIndex(7)
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
Committee: committee,
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestSubmitSyncCommitteeMessage_OK(t *testing.T) {
hook := logTest.NewGlobal()
validatorIndex := primitives.ValidatorIndex(7)
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
Committee: committee,
Expand Down Expand Up @@ -161,7 +161,7 @@ func TestSubmitSyncCommitteeMessage_OK(t *testing.T) {
func TestSubmitSignedContributionAndProof_ValidatorDutiesRequestFailure(t *testing.T) {
hook := logTest.NewGlobal()
validator, _, validatorKey, finish := setup(t)
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{}}
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{}}
defer finish()

var pubKey [fieldparams.BLSPubkeyLength]byte
Expand All @@ -175,7 +175,7 @@ func TestSubmitSignedContributionAndProof_GetSyncSubcommitteeIndexFailure(t *tes
validator, m, validatorKey, finish := setup(t)
validatorIndex := primitives.ValidatorIndex(7)
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
Committee: committee,
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestSubmitSignedContributionAndProof_NothingToDo(t *testing.T) {
validator, m, validatorKey, finish := setup(t)
validatorIndex := primitives.ValidatorIndex(7)
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
Committee: committee,
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestSubmitSignedContributionAndProof_BadDomain(t *testing.T) {
validator, m, validatorKey, finish := setup(t)
validatorIndex := primitives.ValidatorIndex(7)
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
Committee: committee,
Expand Down Expand Up @@ -273,7 +273,7 @@ func TestSubmitSignedContributionAndProof_CouldNotGetContribution(t *testing.T)
validator, m, validatorKey, finish := setupWithKey(t, validatorKey)
validatorIndex := primitives.ValidatorIndex(7)
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
Committee: committee,
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestSubmitSignedContributionAndProof_CouldNotSubmitContribution(t *testing.
validator, m, validatorKey, finish := setupWithKey(t, validatorKey)
validatorIndex := primitives.ValidatorIndex(7)
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
Committee: committee,
Expand Down Expand Up @@ -401,7 +401,7 @@ func TestSubmitSignedContributionAndProof_Ok(t *testing.T) {
validator, m, validatorKey, finish := setupWithKey(t, validatorKey)
validatorIndex := primitives.ValidatorIndex(7)
committee := []primitives.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
validator.duties = &ethpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{
validator.duties = &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey().Marshal(),
Committee: committee,
Expand Down
2 changes: 1 addition & 1 deletion validator/client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ func (v *validator) RolesAt(ctx context.Context, slot primitives.Slot) (map[[fie
v.dutiesLock.RLock()
defer v.dutiesLock.RUnlock()
rolesAt := make(map[[fieldparams.BLSPubkeyLength]byte][]iface.ValidatorRole)
for validator, duty := range v.duties.Duties {
for validator, duty := range v.duties.CurrentEpochDuties {
var roles []iface.ValidatorRole

if duty == nil {
Expand Down
24 changes: 12 additions & 12 deletions validator/client/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func TestUpdateDuties_DoesNothingWhenNotEpochStart_AlreadyExistingAssignments(t
v := validator{
validatorClient: client,
duties: &ethpb.DutiesResponse{
Duties: []*ethpb.DutiesResponse_Duty{
CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
Committee: []primitives.ValidatorIndex{},
AttesterSlot: 10,
Expand All @@ -482,7 +482,7 @@ func TestUpdateDuties_ReturnsError(t *testing.T) {
validatorClient: client,
keyManager: newMockKeymanager(t, randKeypair(t)),
duties: &ethpb.DutiesResponse{
Duties: []*ethpb.DutiesResponse_Duty{
CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
CommitteeIndex: 1,
},
Expand All @@ -508,7 +508,7 @@ func TestUpdateDuties_OK(t *testing.T) {

slot := params.BeaconConfig().SlotsPerEpoch
resp := &ethpb.DutiesResponse{
Duties: []*ethpb.DutiesResponse_Duty{
CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
AttesterSlot: params.BeaconConfig().SlotsPerEpoch,
ValidatorIndex: 200,
Expand Down Expand Up @@ -544,10 +544,10 @@ func TestUpdateDuties_OK(t *testing.T) {

util.WaitTimeout(&wg, 2*time.Second)

assert.Equal(t, params.BeaconConfig().SlotsPerEpoch+1, v.duties.Duties[0].ProposerSlots[0], "Unexpected validator assignments")
assert.Equal(t, params.BeaconConfig().SlotsPerEpoch, v.duties.Duties[0].AttesterSlot, "Unexpected validator assignments")
assert.Equal(t, resp.Duties[0].CommitteeIndex, v.duties.Duties[0].CommitteeIndex, "Unexpected validator assignments")
assert.Equal(t, resp.Duties[0].ValidatorIndex, v.duties.Duties[0].ValidatorIndex, "Unexpected validator assignments")
assert.Equal(t, params.BeaconConfig().SlotsPerEpoch+1, v.duties.CurrentEpochDuties[0].ProposerSlots[0], "Unexpected validator assignments")
assert.Equal(t, params.BeaconConfig().SlotsPerEpoch, v.duties.CurrentEpochDuties[0].AttesterSlot, "Unexpected validator assignments")
assert.Equal(t, resp.CurrentEpochDuties[0].CommitteeIndex, v.duties.CurrentEpochDuties[0].CommitteeIndex, "Unexpected validator assignments")
assert.Equal(t, resp.CurrentEpochDuties[0].ValidatorIndex, v.duties.CurrentEpochDuties[0].ValidatorIndex, "Unexpected validator assignments")
}

func TestUpdateDuties_OK_FilterBlacklistedPublicKeys(t *testing.T) {
Expand All @@ -570,7 +570,7 @@ func TestUpdateDuties_OK_FilterBlacklistedPublicKeys(t *testing.T) {
}

resp := &ethpb.DutiesResponse{
Duties: []*ethpb.DutiesResponse_Duty{},
CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{},
}
client.EXPECT().GetDuties(
gomock.Any(),
Expand Down Expand Up @@ -644,7 +644,7 @@ func TestRolesAt_OK(t *testing.T) {
defer finish()

v.duties = &ethpb.DutiesResponse{
Duties: []*ethpb.DutiesResponse_Duty{
CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
CommitteeIndex: 1,
AttesterSlot: 1,
Expand Down Expand Up @@ -684,7 +684,7 @@ func TestRolesAt_OK(t *testing.T) {

// Test sync committee role at epoch boundary.
v.duties = &ethpb.DutiesResponse{
Duties: []*ethpb.DutiesResponse_Duty{
CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
CommitteeIndex: 1,
AttesterSlot: 1,
Expand Down Expand Up @@ -720,7 +720,7 @@ func TestRolesAt_DoesNotAssignProposer_Slot0(t *testing.T) {
defer finish()

v.duties = &ethpb.DutiesResponse{
Duties: []*ethpb.DutiesResponse_Duty{
CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
CommitteeIndex: 1,
AttesterSlot: 0,
Expand Down Expand Up @@ -847,7 +847,7 @@ func TestCheckAndLogValidatorStatus_OK(t *testing.T) {
v := validator{
validatorClient: client,
duties: &ethpb.DutiesResponse{
Duties: []*ethpb.DutiesResponse_Duty{
CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
{
CommitteeIndex: 1,
},
Expand Down

0 comments on commit 4afb379

Please sign in to comment.