Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Validator Index in GetDuties Response, Update EthereumAPIs #4567

Merged
merged 8 commits into from Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion WORKSPACE
Expand Up @@ -1255,7 +1255,7 @@ go_repository(

go_repository(
name = "com_github_prysmaticlabs_ethereumapis",
commit = "87118fb893cc6f32b25793d819790fd3bcce3221",
commit = "8a785e129627db2be96339a35fb2317b200160b1",
importpath = "github.com/prysmaticlabs/ethereumapis",
patch_args = ["-p1"],
patches = [
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/rpc/validator/assignments.go
Expand Up @@ -58,6 +58,7 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth
if ok {
assignment.Committee = ca.Committee
assignment.Status = ethpb.ValidatorStatus_ACTIVE
assignment.ValidatorIndex = idx
assignment.PublicKey = pubKey
assignment.AttesterSlot = ca.AttesterSlot
assignment.ProposerSlot = proposerIndexToSlot[idx]
Expand Down
105 changes: 44 additions & 61 deletions beacon-chain/rpc/validator/assignments_test.go
Expand Up @@ -5,11 +5,11 @@ import (
"encoding/binary"
"fmt"
"strings"
"sync"
"testing"

ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"

terencechain marked this conversation as resolved.
Show resolved Hide resolved
mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
blk "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
Expand Down Expand Up @@ -105,22 +105,14 @@ func TestGetDuties_OK(t *testing.T) {
t.Fatalf("Could not get signing root %v", err)
}

var wg sync.WaitGroup
numOfValidators := int(depChainStart)
errs := make(chan error, numOfValidators)
pubKeys := make([][]byte, len(deposits))
indices := make([]uint64, len(deposits))
for i := 0; i < len(deposits); i++ {
wg.Add(1)
go func(index int) {
errs <- db.SaveValidatorIndex(ctx, deposits[index].Data.PublicKey, uint64(index))
wg.Done()
}(i)
}
wg.Wait()
close(errs)
for err := range errs {
if err != nil {
t.Fatalf("Could not save validator index: %v", err)
}
pubKeys[i] = deposits[i].Data.PublicKey
indices[i] = uint64(i)
}
if err := db.SaveValidatorIndices(ctx, pubKeys, indices); err != nil {
t.Fatal(err)
}

vs := &Server{
Expand Down Expand Up @@ -157,6 +149,21 @@ func TestGetDuties_OK(t *testing.T) {
t.Errorf("Assigned slot %d can't be higher than %d",
res.Duties[0].AttesterSlot, state.Slot+params.BeaconConfig().SlotsPerEpoch)
}

// We request for duties for all validators.
req = &ethpb.DutiesRequest{
PublicKeys: pubKeys,
Epoch: 0,
}
res, err = vs.GetDuties(context.Background(), req)
if err != nil {
t.Fatalf("Could not call epoch committee assignment %v", err)
}
for i := 0; i < len(res.Duties); i++ {
if res.Duties[i].ValidatorIndex != uint64(i) {
t.Errorf("Wanted %d, received %d", i, res.Duties[i].ValidatorIndex)
}
}
}

func TestGetDuties_CurrentEpoch_ShouldNotFail(t *testing.T) {
Expand All @@ -182,22 +189,14 @@ func TestGetDuties_CurrentEpoch_ShouldNotFail(t *testing.T) {
t.Fatalf("Could not get signing root %v", err)
}

var wg sync.WaitGroup
numOfValidators := int(depChainStart)
errs := make(chan error, numOfValidators)
pubKeys := make([][]byte, len(deposits))
indices := make([]uint64, len(deposits))
for i := 0; i < len(deposits); i++ {
wg.Add(1)
go func(index int) {
errs <- db.SaveValidatorIndex(ctx, deposits[index].Data.PublicKey, uint64(index))
wg.Done()
}(i)
}
wg.Wait()
close(errs)
for err := range errs {
if err != nil {
t.Fatalf("Could not save validator index: %v", err)
}
pubKeys[i] = deposits[i].Data.PublicKey
indices[i] = uint64(i)
}
if err := db.SaveValidatorIndices(ctx, pubKeys, indices); err != nil {
t.Fatal(err)
}

vs := &Server{
Expand Down Expand Up @@ -241,22 +240,14 @@ func TestGetDuties_MultipleKeys_OK(t *testing.T) {
t.Fatalf("Could not get signing root %v", err)
}

var wg sync.WaitGroup
numOfValidators := int(depChainStart)
errs := make(chan error, numOfValidators)
for i := 0; i < numOfValidators; i++ {
wg.Add(1)
go func(index int) {
errs <- db.SaveValidatorIndex(ctx, deposits[index].Data.PublicKey, uint64(index))
wg.Done()
}(i)
pubKeys := make([][]byte, len(deposits))
indices := make([]uint64, len(deposits))
for i := 0; i < len(deposits); i++ {
pubKeys[i] = deposits[i].Data.PublicKey
indices[i] = uint64(i)
}
wg.Wait()
close(errs)
for err := range errs {
if err != nil {
t.Fatalf("Could not save validator index: %v", err)
}
if err := db.SaveValidatorIndices(ctx, pubKeys, indices); err != nil {
t.Fatal(err)
}

vs := &Server{
Expand Down Expand Up @@ -320,22 +311,14 @@ func BenchmarkCommitteeAssignment(b *testing.B) {
b.Fatalf("Could not get signing root %v", err)
}

var wg sync.WaitGroup
numOfValidators := int(depChainStart)
errs := make(chan error, numOfValidators)
for i := 0; i < numOfValidators; i++ {
wg.Add(1)
go func(index int) {
errs <- db.SaveValidatorIndex(ctx, deposits[index].Data.PublicKey, uint64(index))
wg.Done()
}(i)
pubKeys := make([][]byte, len(deposits))
indices := make([]uint64, len(deposits))
for i := 0; i < len(deposits); i++ {
pubKeys[i] = deposits[i].Data.PublicKey
indices[i] = uint64(i)
}
wg.Wait()
close(errs)
for err := range errs {
if err != nil {
b.Fatalf("Could not save validator index: %v", err)
}
if err := db.SaveValidatorIndices(ctx, pubKeys, indices); err != nil {
b.Fatal(err)
}

vs := &Server{
Expand Down