2020-02-19 22:26:14 +00:00
|
|
|
package beaconclient
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
2020-02-23 22:30:52 +00:00
|
|
|
"go.opencensus.io/trace"
|
2020-02-19 22:26:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// RequestHistoricalAttestations requests all indexed attestations for a
|
|
|
|
// given epoch from a beacon node via gRPC.
|
|
|
|
func (bs *Service) RequestHistoricalAttestations(
|
|
|
|
ctx context.Context,
|
|
|
|
epoch uint64,
|
|
|
|
) ([]*ethpb.IndexedAttestation, error) {
|
|
|
|
ctx, span := trace.StartSpan(ctx, "beaconclient.RequestHistoricalAttestations")
|
|
|
|
defer span.End()
|
|
|
|
indexedAtts := make([]*ethpb.IndexedAttestation, 0)
|
|
|
|
res := ðpb.ListIndexedAttestationsResponse{}
|
|
|
|
var err error
|
|
|
|
for {
|
|
|
|
res, err = bs.beaconClient.ListIndexedAttestations(ctx, ðpb.ListIndexedAttestationsRequest{
|
2020-03-23 20:22:37 +00:00
|
|
|
QueryFilter: ðpb.ListIndexedAttestationsRequest_Epoch{
|
|
|
|
Epoch: epoch,
|
2020-02-19 22:26:14 +00:00
|
|
|
},
|
|
|
|
PageSize: int32(params.BeaconConfig().DefaultPageSize),
|
|
|
|
PageToken: res.NextPageToken,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2020-02-27 17:22:39 +00:00
|
|
|
return nil, errors.Wrapf(err, "could not request indexed attestations for epoch: %d", epoch)
|
2020-02-19 22:26:14 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2020-03-03 18:08:21 +00:00
|
|
|
if err := bs.slasherDB.SaveIndexedAttestations(ctx, indexedAtts); err != nil {
|
2020-02-27 17:22:39 +00:00
|
|
|
return nil, errors.Wrap(err, "could not save indexed attestations")
|
|
|
|
}
|
2020-02-19 22:26:14 +00:00
|
|
|
return indexedAtts, nil
|
|
|
|
}
|