mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
Remove redundant assignments request in validator attesting routine (#2166)
* remove redunant assignments request in validator attesting routine * fix test
This commit is contained in:
parent
83130358a9
commit
9abefc386d
@ -45,25 +45,15 @@ func (v *validator) AttestToBlockHead(ctx context.Context, slot uint64) {
|
||||
log.Errorf("Could not fetch validator index: %v", err)
|
||||
return
|
||||
}
|
||||
req := &pb.CommitteeAssignmentsRequest{
|
||||
EpochStart: slot,
|
||||
PublicKey: [][]byte{pubKey},
|
||||
}
|
||||
resp, err := v.validatorClient.CommitteeAssignment(ctx, req)
|
||||
if err != nil {
|
||||
log.Errorf("Could not fetch crosslink committees at slot %d: %v",
|
||||
slot-params.BeaconConfig().GenesisSlot, err)
|
||||
return
|
||||
}
|
||||
// Set the attestation data's shard as the shard associated with the validator's
|
||||
// committee as retrieved by CrosslinkCommitteesAtSlot.
|
||||
attData.Shard = resp.Assignment[0].Shard
|
||||
attData.Shard = v.assignment.Assignment[0].Shard
|
||||
|
||||
// Fetch other necessary information from the beacon node in order to attest
|
||||
// including the justified epoch, epoch boundary information, and more.
|
||||
infoReq := &pb.AttestationDataRequest{
|
||||
Slot: slot,
|
||||
Shard: resp.Assignment[0].Shard,
|
||||
Shard: v.assignment.Assignment[0].Shard,
|
||||
}
|
||||
infoRes, err := v.attesterClient.AttestationDataAtSlot(ctx, infoReq)
|
||||
if err != nil {
|
||||
@ -97,12 +87,12 @@ func (v *validator) AttestToBlockHead(ctx context.Context, slot uint64) {
|
||||
|
||||
// We set the custody bitfield to an slice of zero values as a stub for phase 0
|
||||
// of length len(committee)+7 // 8.
|
||||
attestation.CustodyBitfield = make([]byte, (len(resp.Assignment[0].Committee)+7)/8)
|
||||
attestation.CustodyBitfield = make([]byte, (len(v.assignment.Assignment[0].Committee)+7)/8)
|
||||
|
||||
// Find the index in committee to be used for
|
||||
// the aggregation bitfield
|
||||
var indexInCommittee int
|
||||
for i, vIndex := range resp.Assignment[0].Committee {
|
||||
for i, vIndex := range v.assignment.Assignment[0].Committee {
|
||||
if vIndex == validatorIndexRes.Index {
|
||||
indexInCommittee = i
|
||||
break
|
||||
|
@ -31,41 +31,20 @@ func TestAttestToBlockHead_ValidatorIndexRequestFailure(t *testing.T) {
|
||||
testutil.AssertLogsContain(t, hook, "Could not fetch validator index")
|
||||
}
|
||||
|
||||
func TestAttestToBlockHead_ValidatorCommitteeAtSlotFailure(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
|
||||
validator, m, finish := setup(t)
|
||||
defer finish()
|
||||
m.validatorClient.EXPECT().ValidatorIndex(
|
||||
gomock.Any(), // ctx
|
||||
gomock.AssignableToTypeOf(&pb.ValidatorIndexRequest{}),
|
||||
).Return(&pb.ValidatorIndexResponse{Index: 5}, nil)
|
||||
m.validatorClient.EXPECT().CommitteeAssignment(
|
||||
gomock.Any(), // ctx
|
||||
gomock.Any(),
|
||||
).Return(nil, errors.New("something went wrong"))
|
||||
|
||||
validator.AttestToBlockHead(context.Background(), 30+params.BeaconConfig().GenesisSlot)
|
||||
testutil.AssertLogsContain(t, hook, "Could not fetch crosslink committees at slot 30")
|
||||
}
|
||||
|
||||
func TestAttestToBlockHead_AttestationDataAtSlotFailure(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
|
||||
validator, m, finish := setup(t)
|
||||
defer finish()
|
||||
validator.assignment = &pb.CommitteeAssignmentResponse{Assignment: []*pb.CommitteeAssignmentResponse_CommitteeAssignment{
|
||||
{
|
||||
Shard: 5,
|
||||
},
|
||||
}}
|
||||
m.validatorClient.EXPECT().ValidatorIndex(
|
||||
gomock.Any(), // ctx
|
||||
gomock.AssignableToTypeOf(&pb.ValidatorIndexRequest{}),
|
||||
).Return(&pb.ValidatorIndexResponse{Index: 5}, nil)
|
||||
m.validatorClient.EXPECT().CommitteeAssignment(
|
||||
gomock.Any(), // ctx
|
||||
gomock.AssignableToTypeOf(&pb.CommitteeAssignmentsRequest{}),
|
||||
).Return(&pb.CommitteeAssignmentResponse{Assignment: []*pb.CommitteeAssignmentResponse_CommitteeAssignment{
|
||||
{
|
||||
Shard: 5,
|
||||
},
|
||||
}}, nil)
|
||||
m.attesterClient.EXPECT().AttestationDataAtSlot(
|
||||
gomock.Any(), // ctx
|
||||
gomock.AssignableToTypeOf(&pb.AttestationDataRequest{}),
|
||||
@ -80,20 +59,17 @@ func TestAttestToBlockHead_AttestHeadRequestFailure(t *testing.T) {
|
||||
|
||||
validator, m, finish := setup(t)
|
||||
defer finish()
|
||||
validator.assignment = &pb.CommitteeAssignmentResponse{Assignment: []*pb.CommitteeAssignmentResponse_CommitteeAssignment{
|
||||
{
|
||||
Shard: 5,
|
||||
Committee: make([]uint64, 111),
|
||||
}}}
|
||||
m.validatorClient.EXPECT().ValidatorIndex(
|
||||
gomock.Any(), // ctx
|
||||
gomock.AssignableToTypeOf(&pb.ValidatorIndexRequest{}),
|
||||
).Return(&pb.ValidatorIndexResponse{
|
||||
Index: 0,
|
||||
}, nil)
|
||||
m.validatorClient.EXPECT().CommitteeAssignment(
|
||||
gomock.Any(), // ctx
|
||||
gomock.AssignableToTypeOf(&pb.CommitteeAssignmentsRequest{}),
|
||||
).Return(&pb.CommitteeAssignmentResponse{Assignment: []*pb.CommitteeAssignmentResponse_CommitteeAssignment{
|
||||
{
|
||||
Shard: 5,
|
||||
Committee: make([]uint64, 111),
|
||||
}}}, nil)
|
||||
m.attesterClient.EXPECT().AttestationDataAtSlot(
|
||||
gomock.Any(), // ctx
|
||||
gomock.AssignableToTypeOf(&pb.AttestationDataRequest{}),
|
||||
@ -120,20 +96,17 @@ func TestAttestToBlockHead_AttestsCorrectly(t *testing.T) {
|
||||
defer finish()
|
||||
validatorIndex := uint64(7)
|
||||
committee := []uint64{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
|
||||
validator.assignment = &pb.CommitteeAssignmentResponse{Assignment: []*pb.CommitteeAssignmentResponse_CommitteeAssignment{
|
||||
{
|
||||
Shard: 5,
|
||||
Committee: committee,
|
||||
}}}
|
||||
m.validatorClient.EXPECT().ValidatorIndex(
|
||||
gomock.Any(), // ctx
|
||||
gomock.AssignableToTypeOf(&pb.ValidatorIndexRequest{}),
|
||||
).Return(&pb.ValidatorIndexResponse{
|
||||
Index: uint64(validatorIndex),
|
||||
}, nil)
|
||||
m.validatorClient.EXPECT().CommitteeAssignment(
|
||||
gomock.Any(), // ctx
|
||||
gomock.AssignableToTypeOf(&pb.CommitteeAssignmentsRequest{}),
|
||||
).Return(&pb.CommitteeAssignmentResponse{Assignment: []*pb.CommitteeAssignmentResponse_CommitteeAssignment{
|
||||
{
|
||||
Shard: 5,
|
||||
Committee: committee,
|
||||
}}}, nil)
|
||||
m.attesterClient.EXPECT().AttestationDataAtSlot(
|
||||
gomock.Any(), // ctx
|
||||
gomock.AssignableToTypeOf(&pb.AttestationDataRequest{}),
|
||||
@ -215,22 +188,17 @@ func TestAttestToBlockHead_DoesAttestAfterDelay(t *testing.T) {
|
||||
defer finish()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(3)
|
||||
wg.Add(2)
|
||||
defer wg.Wait()
|
||||
|
||||
validator.genesisTime = uint64(time.Now().Unix())
|
||||
validatorIndex := uint64(5)
|
||||
committee := []uint64{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
|
||||
m.validatorClient.EXPECT().CommitteeAssignment(
|
||||
gomock.Any(), // ctx
|
||||
gomock.AssignableToTypeOf(&pb.CommitteeAssignmentsRequest{}),
|
||||
).Return(&pb.CommitteeAssignmentResponse{Assignment: []*pb.CommitteeAssignmentResponse_CommitteeAssignment{
|
||||
validator.assignment = &pb.CommitteeAssignmentResponse{Assignment: []*pb.CommitteeAssignmentResponse_CommitteeAssignment{
|
||||
{
|
||||
Shard: 5,
|
||||
Committee: committee,
|
||||
}}}, nil).Do(func(arg0, arg1 interface{}) {
|
||||
wg.Done()
|
||||
})
|
||||
}}}
|
||||
|
||||
m.attesterClient.EXPECT().AttestationDataAtSlot(
|
||||
gomock.Any(), // ctx
|
||||
|
Loading…
Reference in New Issue
Block a user