Add Error Log for Attester (#1759)

* add log

* add test
This commit is contained in:
Nishant Das 2019-03-02 09:57:02 +08:00 committed by GitHub
parent 88765b6d3c
commit 615daa98e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View File

@ -102,6 +102,10 @@ func (v *validator) AttestToBlockHead(ctx context.Context, slot uint64) {
break break
} }
} }
if len(aggregationBitfield) == 0 {
log.Error("Aggregation bitfield is empty so unable to attest to block head")
return
}
aggregationBitfield[indexIntoCommittee/8] |= 1 << (indexIntoCommittee % 8) aggregationBitfield[indexIntoCommittee/8] |= 1 << (indexIntoCommittee % 8)
// Note: calling get_attestation_participants(state, attestation.data, attestation.aggregation_bitfield) // Note: calling get_attestation_participants(state, attestation.data, attestation.aggregation_bitfield)
// should return a list of length equal to 1, containing validator_index. // should return a list of length equal to 1, containing validator_index.

View File

@ -280,3 +280,38 @@ func TestAttestToBlockHead_DoesAttestAfterDelay(t *testing.T) {
delay = 0 delay = 0
validator.AttestToBlockHead(context.Background(), 0) validator.AttestToBlockHead(context.Background(), 0)
} }
func TestAttestToBlockHead_EmptyAggregationBitfield(t *testing.T) {
hook := logTest.NewGlobal()
validator, m, finish := setup(t)
defer finish()
validatorIndex := uint64(5)
committee := []uint64{}
m.validatorClient.EXPECT().ValidatorIndex(
gomock.Any(), // ctx
gomock.AssignableToTypeOf(&pb.ValidatorIndexRequest{}),
).Return(&pb.ValidatorIndexResponse{
Index: uint64(validatorIndex),
}, nil)
m.validatorClient.EXPECT().ValidatorCommitteeAtSlot(
gomock.Any(), // ctx
gomock.AssignableToTypeOf(&pb.CommitteeRequest{}),
).Return(&pb.CommitteeResponse{
Shard: 5,
Committee: committee,
}, nil)
m.attesterClient.EXPECT().AttestationDataAtSlot(
gomock.Any(), // ctx
gomock.AssignableToTypeOf(&pb.AttestationDataRequest{}),
).Return(&pb.AttestationDataResponse{
BeaconBlockRootHash32: []byte("A"),
EpochBoundaryRootHash32: []byte("B"),
JustifiedBlockRootHash32: []byte("C"),
LatestCrosslink: &pbp2p.Crosslink{CrosslinkDataRootHash32: []byte{'D'}},
JustifiedEpoch: 3,
}, nil)
validator.AttestToBlockHead(context.Background(), 30)
testutil.AssertLogsContain(t, hook, "Aggregation bitfield is empty so unable to attest to block head")
}