-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
historical_data_retrieval.go
49 lines (46 loc) · 1.54 KB
/
historical_data_retrieval.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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 := ðpb.ListIndexedAttestationsResponse{}
var err error
for {
res, err = bs.beaconClient.ListIndexedAttestations(ctx, ðpb.ListIndexedAttestationsRequest{
QueryFilter: ðpb.ListIndexedAttestationsRequest_TargetEpoch{
TargetEpoch: 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.SaveIncomingIndexedAttestationsByEpoch(ctx, indexedAtts); err != nil {
return nil, errors.Wrap(err, "could not save indexed attestations")
}
return indexedAtts, nil
}