forked from prysmaticlabs/prysm
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate SubmitAggregateAndProof (prysmaticlabs#4951)
* Remove unused services, mark everything as deprecated, regen pb.go * remove some code from cluster pk manager, gazelle * goimports * remove mocks * Update WORKSPACE, deprecate old method, stub new method * Move implementation to ethereumapis definition * gofmt * Add TODO for prysmaticlabs#4952 * Merge branch 'master' into migrate-submitaggregateandproof * Update validator client to use new submit aggregate and proof method * Merge branch 'migrate-submitaggregateandproof' of github.com:prysmaticlabs/prysm into migrate-submitaggregateandproof * gaz * rename * rename * Merge refs/heads/master into migrate-submitaggregateandproof * Merge refs/heads/master into migrate-submitaggregateandproof * Merge refs/heads/master into migrate-submitaggregateandproof * Merge refs/heads/master into migrate-submitaggregateandproof * Merge refs/heads/master into migrate-submitaggregateandproof * fix tests * Merge branch 'migrate-submitaggregateandproof' of github.com:prysmaticlabs/prysm into migrate-submitaggregateandproof
- Loading branch information
1 parent
daa2637
commit 398cd64
Showing
16 changed files
with
886 additions
and
519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,14 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["server.go"], | ||
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/rpc/aggregator", | ||
visibility = ["//beacon-chain:__subpackages__"], | ||
deps = [ | ||
"//beacon-chain/blockchain:go_default_library", | ||
"//beacon-chain/core/helpers:go_default_library", | ||
"//beacon-chain/db:go_default_library", | ||
"//beacon-chain/operations/attestations:go_default_library", | ||
"//beacon-chain/p2p:go_default_library", | ||
"//beacon-chain/sync:go_default_library", | ||
"//beacon-chain/rpc/validator:go_default_library", | ||
"//proto/beacon/rpc/v1:go_default_library", | ||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", | ||
"@com_github_sirupsen_logrus//:go_default_library", | ||
"@io_opencensus_go//trace:go_default_library", | ||
"@org_golang_google_grpc//codes:go_default_library", | ||
"@org_golang_google_grpc//status:go_default_library", | ||
], | ||
) | ||
|
||
go_test( | ||
name = "go_default_test", | ||
srcs = ["server_test.go"], | ||
embed = [":go_default_library"], | ||
deps = [ | ||
"//beacon-chain/blockchain/testing:go_default_library", | ||
"//beacon-chain/core/helpers:go_default_library", | ||
"//beacon-chain/db/testing:go_default_library", | ||
"//beacon-chain/operations/attestations:go_default_library", | ||
"//beacon-chain/p2p/testing:go_default_library", | ||
"//beacon-chain/state:go_default_library", | ||
"//beacon-chain/sync/initial-sync/testing:go_default_library", | ||
"//proto/beacon/p2p/v1:go_default_library", | ||
"//proto/beacon/rpc/v1:go_default_library", | ||
"//shared/attestationutil:go_default_library", | ||
"//shared/bls:go_default_library", | ||
"//shared/params:go_default_library", | ||
"//shared/testutil:go_default_library", | ||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", | ||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library", | ||
"@com_github_prysmaticlabs_go_ssz//:go_default_library", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package validator | ||
|
||
import ( | ||
"context" | ||
|
||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" | ||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" | ||
"github.com/sirupsen/logrus" | ||
"go.opencensus.io/trace" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
// SubmitAggregateAndProof is called by a validator when its assigned to be an aggregator. | ||
// The beacon node will broadcast aggregated attestation and proof on the aggregator's behavior. | ||
func (as *Server) SubmitAggregateAndProof(ctx context.Context, req *ethpb.AggregationRequest) (*ethpb.AggregationResponse, error) { | ||
ctx, span := trace.StartSpan(ctx, "AggregatorServer.SubmitAggregation") | ||
defer span.End() | ||
span.AddAttributes(trace.Int64Attribute("slot", int64(req.Slot))) | ||
|
||
if as.SyncChecker.Syncing() { | ||
return nil, status.Errorf(codes.Unavailable, "Syncing to latest head, not ready to respond") | ||
} | ||
|
||
validatorIndex, exists, err := as.BeaconDB.ValidatorIndex(ctx, req.PublicKey) | ||
if err != nil { | ||
return nil, status.Errorf(codes.Internal, "Could not get validator index from DB: %v", err) | ||
} | ||
if !exists { | ||
return nil, status.Error(codes.Internal, "Could not locate validator index in DB") | ||
} | ||
|
||
epoch := helpers.SlotToEpoch(req.Slot) | ||
activeValidatorIndices, err := as.HeadFetcher.HeadValidatorsIndices(epoch) | ||
if err != nil { | ||
return nil, status.Errorf(codes.Internal, "Could not get validators: %v", err) | ||
} | ||
seed, err := as.HeadFetcher.HeadSeed(epoch) | ||
if err != nil { | ||
return nil, status.Errorf(codes.Internal, "Could not get seed: %v", err) | ||
} | ||
committee, err := helpers.BeaconCommittee(activeValidatorIndices, seed, req.Slot, req.CommitteeIndex) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Check if the validator is an aggregator | ||
isAggregator, err := helpers.IsAggregator(uint64(len(committee)), req.SlotSignature) | ||
if err != nil { | ||
return nil, status.Errorf(codes.Internal, "Could not get aggregator status: %v", err) | ||
} | ||
if !isAggregator { | ||
return nil, status.Errorf(codes.InvalidArgument, "Validator is not an aggregator") | ||
} | ||
|
||
// Retrieve the unaggregated attestation from pool. | ||
aggregatedAtts := as.AttPool.AggregatedAttestationsBySlotIndex(req.Slot, req.CommitteeIndex) | ||
|
||
for _, aggregatedAtt := range aggregatedAtts { | ||
if ctx.Err() != nil { | ||
return nil, ctx.Err() | ||
} | ||
if helpers.IsAggregated(aggregatedAtt) { | ||
if err := as.P2P.Broadcast(ctx, ðpb.AggregateAttestationAndProof{ | ||
AggregatorIndex: validatorIndex, | ||
SelectionProof: req.SlotSignature, | ||
Aggregate: aggregatedAtt, | ||
}); err != nil { | ||
return nil, status.Errorf(codes.Internal, "Could not broadcast aggregated attestation: %v", err) | ||
} | ||
|
||
log.WithFields(logrus.Fields{ | ||
"slot": req.Slot, | ||
"committeeIndex": req.CommitteeIndex, | ||
"validatorIndex": validatorIndex, | ||
"aggregatedCount": aggregatedAtt.AggregationBits.Count(), | ||
}).Debug("Broadcasting aggregated attestation and proof") | ||
} | ||
} | ||
|
||
return ðpb.AggregationResponse{}, nil | ||
} |
Oops, something went wrong.