prysm-pulse/slasher/beaconclient/historical_data_retrieval.go
Ivan Martinez bdb80f4639
Change ListAttestations to get attestations from blocks (#5145)
* Start fixing api to get from blocks

* Fix listatts tests

* Fix slasher

* Improve blocks

* Change att grouping

* Use faster att concat

* Try to fix e2e

* Change back time

* tiny e2e fix

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2020-03-23 16:22:37 -04:00

50 lines
1.5 KiB
Go

package beaconclient
import (
"context"
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
"go.opencensus.io/trace"
)
// 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 := &ethpb.ListIndexedAttestationsResponse{}
var err error
for {
res, err = bs.beaconClient.ListIndexedAttestations(ctx, &ethpb.ListIndexedAttestationsRequest{
QueryFilter: &ethpb.ListIndexedAttestationsRequest_Epoch{
Epoch: epoch,
},
PageSize: int32(params.BeaconConfig().DefaultPageSize),
PageToken: res.NextPageToken,
})
if err != nil {
return nil, errors.Wrapf(err, "could not request indexed attestations for epoch: %d", epoch)
}
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
}
}
if err := bs.slasherDB.SaveIndexedAttestations(ctx, indexedAtts); err != nil {
return nil, errors.Wrap(err, "could not save indexed attestations")
}
return indexedAtts, nil
}