mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 05:38:55 +00:00
38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
package helpers
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"github.com/prysmaticlabs/prysm/api/grpc"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/sync"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// ValidateSync checks whether the node is currently syncing and returns an error if it is.
|
|
// It also appends syncing info to gRPC headers.
|
|
func ValidateSync(ctx context.Context, syncChecker sync.Checker, headFetcher blockchain.HeadFetcher, timeFetcher blockchain.TimeFetcher) error {
|
|
if !syncChecker.Syncing() {
|
|
return nil
|
|
}
|
|
headSlot := headFetcher.HeadSlot()
|
|
syncDetailsContainer := &SyncDetailsContainer{
|
|
SyncDetails: &SyncDetails{
|
|
HeadSlot: strconv.FormatUint(uint64(headSlot), 10),
|
|
SyncDistance: strconv.FormatUint(uint64(timeFetcher.CurrentSlot()-headSlot), 10),
|
|
IsSyncing: true,
|
|
},
|
|
}
|
|
err := grpc.AppendCustomErrorHeader(ctx, syncDetailsContainer)
|
|
if err != nil {
|
|
return status.Errorf(
|
|
codes.InvalidArgument,
|
|
"Syncing to latest head, not ready to respond. Could not prepare sync details: %v",
|
|
err,
|
|
)
|
|
}
|
|
return status.Error(codes.Unavailable, "Syncing to latest head, not ready to respond")
|
|
}
|