mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
14b3181e67
* more spanner additions * implement iface * begin implement * wrapped up spanner functions * rem interface * added in necessary comments * comments on enums * begin adding tests * plug in surround vote detection * saved indexed db implementation * finally plugin slashing for historical data * Small fixes * add in all gazelle * save incoming new functions * resolve todo * fix broken test channel item * tests passing when fixing certain arguments and setups * Add comment and change unimplemented * find surround * added in gazelle * gazz * feedback from shay * fixed up naming * Update * Add tests for detectSurroundVotes * Remove logs * Fix slasher test * formatting * Remove unneeded condition * Test indices better * fixing broken build * pass tests * skip tests * imports * Update slasher/detection/attestations/attestations_test.go * Update slasher/beaconclient/historical_data_retrieval_test.go * Address comments * Rename function * Add comment for future optimization * Fix comment Co-authored-by: Ivan Martinez <ivanthegreatdev@gmail.com>
50 lines
1.5 KiB
Go
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 := ð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
|
|
}
|