prysm-pulse/slasher/beaconclient/historical_data_retrieval.go
Victor Farazdagi a8e501b3cf
ETH2 Types: Epoch (#8373)
* update deps

* update deps

* update protos/*

* update deps

* reset protos

* update protos

* update shared/params/config

* update protos

* update /shared

* update shared/slotutil and shared/testutil

* update beacon-chain/core/helpers

* updates beacon-chain/state

* update beacon-chain/forkchoice

* update beacon-chain/blockchain

* update beacon-chain/cache

* update beacon-chain/core

* update beacon-chain/db

* update beacon-chain/node

* update beacon-chain/p2p

* update beacon-chain/rpc

* update beacon-chain/sync

* go mod tidy

* make sure that beacon-chain build suceeds

* go fmt

* update e2e tests

* update slasher

* remove redundant alias

* update validator

* gazelle

* fix build errors in unit tests

* go fmt

* update deps

* update fuzz/BUILD.bazel

* fix unit tests

* more unit test fixes

* fix blockchain UTs

* more unit test fixes
2021-02-09 10:05:22 +00:00

54 lines
1.5 KiB
Go

package beaconclient
import (
"context"
"github.com/prysmaticlabs/eth2-types"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/cmd"
"go.opencensus.io/trace"
)
// RequestHistoricalAttestations requests all indexed attestations for a
// given epoch from a beacon node via gRPC.
func (s *Service) RequestHistoricalAttestations(
ctx context.Context,
epoch types.Epoch,
) ([]*ethpb.IndexedAttestation, error) {
ctx, span := trace.StartSpan(ctx, "beaconclient.RequestHistoricalAttestations")
defer span.End()
indexedAtts := make([]*ethpb.IndexedAttestation, 0)
res := &ethpb.ListIndexedAttestationsResponse{}
var err error
for {
if ctx.Err() != nil {
return nil, ctx.Err()
}
if res == nil {
res = &ethpb.ListIndexedAttestationsResponse{}
}
res, err = s.beaconClient.ListIndexedAttestations(ctx, &ethpb.ListIndexedAttestationsRequest{
QueryFilter: &ethpb.ListIndexedAttestationsRequest_Epoch{
Epoch: epoch,
},
PageSize: int32(cmd.Get().MaxRPCPageSize),
PageToken: res.NextPageToken,
})
if err != nil {
log.WithError(err).Errorf("could not request indexed attestations for epoch: %d", epoch)
break
}
indexedAtts = append(indexedAtts, res.IndexedAttestations...)
log.Infof(
"Retrieved %d/%d indexed attestations for epoch %d",
len(indexedAtts),
res.TotalSize,
epoch,
)
if res.NextPageToken == "" || res.TotalSize == 0 || len(indexedAtts) == int(res.TotalSize) {
break
}
}
return indexedAtts, nil
}