Skip to content

Commit

Permalink
Ensure aggregateAndProofSig returns when err'ing (#7182)
Browse files Browse the repository at this point in the history
* Return if sign fails
  • Loading branch information
terencechain authored Sep 6, 2020
1 parent 9219dc7 commit 245c187
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions validator/client/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (v *validator) SubmitAggregateAndProof(ctx context.Context, slot uint64, pu
sig, err := v.aggregateAndProofSig(ctx, pubKey, res.AggregateAndProof)
if err != nil {
log.Errorf("Could not sign aggregate and proof: %v", err)
return
}
_, err = v.validatorClient.SubmitSignedAggregateSelectionProof(ctx, &ethpb.SignedAggregateSubmitRequest{
SignedAggregateAndProof: &ethpb.SignedAggregateAttestationAndProof{
Expand Down
44 changes: 44 additions & 0 deletions validator/client/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"errors"
"testing"

"github.com/golang/mock/gomock"
Expand All @@ -27,6 +28,49 @@ func TestSubmitAggregateAndProof_GetDutiesRequestFailure(t *testing.T) {
require.LogsContain(t, hook, "Could not fetch validator assignment")
}

func TestSubmitAggregateAndProof_SignFails(t *testing.T) {
validator, m, finish := setup(t)
defer finish()
validator.duties = &ethpb.DutiesResponse{
Duties: []*ethpb.DutiesResponse_Duty{
{
PublicKey: validatorKey.PublicKey.Marshal(),
},
},
}

m.validatorClient.EXPECT().DomainData(
gomock.Any(), // ctx
gomock.Any(), // epoch
).Return(&ethpb.DomainResponse{SignatureDomain: make([]byte, 32)}, nil /*err*/)

m.validatorClient.EXPECT().SubmitAggregateSelectionProof(
gomock.Any(), // ctx
gomock.AssignableToTypeOf(&ethpb.AggregateSelectionRequest{}),
).Return(&ethpb.AggregateSelectionResponse{
AggregateAndProof: &ethpb.AggregateAttestationAndProof{
AggregatorIndex: 0,
Aggregate: &ethpb.Attestation{
Data: &ethpb.AttestationData{
BeaconBlockRoot: make([]byte, 32),
Target: &ethpb.Checkpoint{Root: make([]byte, 32)},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
},
Signature: make([]byte, 96),
AggregationBits: make([]byte, 1),
},
SelectionProof: make([]byte, 96),
},
}, nil)

m.validatorClient.EXPECT().DomainData(
gomock.Any(), // ctx
gomock.Any(), // epoch
).Return(&ethpb.DomainResponse{SignatureDomain: nil}, errors.New("bad domain root"))

validator.SubmitAggregateAndProof(context.Background(), 0, validatorPubKey)
}

func TestSubmitAggregateAndProof_Ok(t *testing.T) {
validator, m, finish := setup(t)
defer finish()
Expand Down

0 comments on commit 245c187

Please sign in to comment.