mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-31 15:31:20 +00:00
Change ListIndexedAttestations to be more slasher friendly (#5930)
* Improve slasher beacon comms * Fixes * Add case for normal errors * remove baz * Merge branch 'master' into improve-slasher-beacon * Merge refs/heads/master into improve-slasher-beacon * Merge refs/heads/master into improve-slasher-beacon * Feedback * Merge branch 'improve-slasher-beacon' of github.com:prysmaticlabs/prysm into improve-slasher-beacon * Merge refs/heads/master into improve-slasher-beacon
This commit is contained in:
parent
5f72d28057
commit
9fc6be8b74
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ptypes "github.com/gogo/protobuf/types"
|
||||
@ -155,11 +156,14 @@ func (bs *Server) ListIndexedAttestations(
|
||||
// We use the retrieved committees for the block root to convert all attestations
|
||||
// into indexed form effectively.
|
||||
mappedAttestations := mapAttestationsByTargetRoot(ctx, attsArray)
|
||||
indexedAtts := make([]*ethpb.IndexedAttestation, numAttestations)
|
||||
attIndex := 0
|
||||
indexedAtts := make([]*ethpb.IndexedAttestation, 0, numAttestations)
|
||||
for targetRoot, atts := range mappedAttestations {
|
||||
attState, err := bs.StateGen.StateByRoot(ctx, targetRoot)
|
||||
if err != nil {
|
||||
if err != nil && strings.Contains(err.Error(), "unknown state summary") {
|
||||
// We shouldn't stop the request if we encounter an attestation we don't have the state for.
|
||||
log.Debugf("Could not get state for attestation target root %#x", targetRoot)
|
||||
continue
|
||||
} else if err != nil {
|
||||
return nil, status.Errorf(
|
||||
codes.Internal,
|
||||
"Could not retrieve state for attestation target root %#x: %v",
|
||||
@ -178,8 +182,7 @@ func (bs *Server) ListIndexedAttestations(
|
||||
)
|
||||
}
|
||||
idxAtt := attestationutil.ConvertToIndexed(ctx, att, committee)
|
||||
indexedAtts[attIndex] = idxAtt
|
||||
attIndex++
|
||||
indexedAtts = append(indexedAtts, idxAtt)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ func (bs *Service) querySyncStatus(ctx context.Context) {
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not fetch sync status")
|
||||
}
|
||||
if !status.Syncing {
|
||||
if status != nil && !status.Syncing {
|
||||
log.Info("Beacon node is fully synced, starting slashing detection")
|
||||
return
|
||||
}
|
||||
|
@ -21,6 +21,12 @@ func (bs *Service) RequestHistoricalAttestations(
|
||||
res := ðpb.ListIndexedAttestationsResponse{}
|
||||
var err error
|
||||
for {
|
||||
if ctx.Err() != nil {
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
if res == nil {
|
||||
res = ðpb.ListIndexedAttestationsResponse{}
|
||||
}
|
||||
res, err = bs.beaconClient.ListIndexedAttestations(ctx, ðpb.ListIndexedAttestationsRequest{
|
||||
QueryFilter: ðpb.ListIndexedAttestationsRequest_Epoch{
|
||||
Epoch: epoch,
|
||||
@ -29,7 +35,8 @@ func (bs *Service) RequestHistoricalAttestations(
|
||||
PageToken: res.NextPageToken,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not request indexed attestations for epoch: %d", epoch)
|
||||
log.WithError(err).Errorf("could not request indexed attestations for epoch: %d", epoch)
|
||||
continue
|
||||
}
|
||||
indexedAtts = append(indexedAtts, res.IndexedAttestations...)
|
||||
log.Infof(
|
||||
|
@ -120,10 +120,12 @@ func (ds *Service) detectHistoricalChainData(ctx context.Context) {
|
||||
// slasher DB up to the current beacon node's head epoch we retrieved via gRPC.
|
||||
// If no data was persisted from previous sessions, we request data starting from
|
||||
// the genesis epoch.
|
||||
var storedEpoch uint64
|
||||
for epoch := latestStoredEpoch; epoch < currentChainHead.HeadEpoch; epoch++ {
|
||||
indexedAtts, err := ds.beaconClient.RequestHistoricalAttestations(ctx, epoch)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("Could not fetch attestations for epoch: %d", epoch)
|
||||
break
|
||||
}
|
||||
log.Debugf(
|
||||
"Running slashing detection on %d attestations in epoch %d...",
|
||||
@ -152,8 +154,9 @@ func (ds *Service) detectHistoricalChainData(ctx context.Context) {
|
||||
if err := ds.slasherDB.SaveChainHead(ctx, latestStoredHead); err != nil {
|
||||
log.WithError(err).Error("Could not persist chain head to disk")
|
||||
}
|
||||
storedEpoch = epoch
|
||||
}
|
||||
log.Infof("Completed slashing detection on historical chain data up to epoch %d", currentChainHead.HeadEpoch)
|
||||
log.Infof("Completed slashing detection on historical chain data up to epoch %d", storedEpoch)
|
||||
}
|
||||
|
||||
func (ds *Service) submitAttesterSlashings(ctx context.Context, slashings []*ethpb.AttesterSlashing) {
|
||||
|
Loading…
Reference in New Issue
Block a user